@@ -128,6 +128,7 @@ jobs:
128
128
PR_TITLE : ${{ needs.pr_commented.outputs.PR_TITLE }}
129
129
PR_URL : ${{ needs.pr_commented.outputs.PR_URL }}
130
130
PR_BRANCH : ${{ needs.pr_commented.outputs.PR_BRANCH }}
131
+ PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ needs.pr_commented.outputs.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
131
132
steps :
132
133
- name : Checkout
133
134
uses : actions/checkout@v3
@@ -218,17 +219,57 @@ jobs:
218
219
--namespace "pr${{ env.PR_NUMBER }}" \
219
220
--set url="https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
220
221
222
+ - name : Wait 30 seconds
223
+ run : |
224
+ sleep 30
225
+
226
+ - name : Create first user, template and workspace
227
+ id : setup_deployment
228
+ run : |
229
+ set -euxo pipefail
230
+
231
+ # Create first user
232
+
233
+ # create a masked random password 12 characters long
234
+ password=$(openssl rand -base64 6 | tr -d "=+/" | cut -c1-12)
235
+
236
+ # add mask so that the password is not printed to the logs
237
+ echo "::add-mask::$password"
238
+ echo "password=$password" >> $GITHUB_OUTPUT
239
+
240
+ coder login \
241
+ --first-user-username ${{ env.PR_NUMBER }} \
242
+ --first-user-email ${{ env.PR_NUMBER }}@coder.com \
243
+ --first-user-password $password \
244
+ --first-user-trial \
245
+ --use-token-as-session \
246
+ ${{ env.PR_DEPLOYMENT_ACCESS_URL }}
247
+
248
+ # Create template
249
+ coder templates init --id kubernetes && cd ./kubernetes/ && coder templates create -y --variable namespace=pr${{ env.PR_NUMBER }}
250
+
251
+ # Create workspace
252
+ cat <<EOF > workspace.yaml
253
+ cpu: "2"
254
+ memory: "4"
255
+ home_disk_size: "2"
256
+ EOF
257
+
258
+ coder create --template="kubernetes" pr${{ env.PR_NUMBER }} --rich-parameter-file ./workspace.yaml -y
259
+ coder stop pr${{ env.PR_NUMBER }} -y
260
+
221
261
- name : Send Slack notification
222
262
run : |
223
263
curl -s -o /dev/null -X POST -H 'Content-type: application/json' \
224
264
-d '{
225
265
"pr_number": "'"${{ env.PR_NUMBER }}"'",
226
266
"pr_url": "'"${{ env.PR_URL }}"'",
227
267
"pr_title": "'"${{ env.PR_TITLE }}"'",
228
- "pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
268
+ "pr_access_url": "'"${{ env.PR_DEPLOYMENT_ACCESS_URL }}"'",
269
+ "pr_username": "'"${{ env.PR_NUMBER }}"'",
270
+ "pr_email": "'"${{ env.PR_NUMBER }}@coder.com"'",
271
+ "pr_password": "'"${{ steps.setup_deployment.outputs.password }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
229
272
echo "Slack notification sent"
230
- env :
231
- PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
232
273
233
274
- name : Find Comment
234
275
uses : peter-evans/find-comment@v2
@@ -252,5 +293,3 @@ jobs:
252
293
:rocket: Access the deployment link [here](${{ env.PR_DEPLOYMENT_ACCESS_URL }}).
253
294
:warning: This deployment will be deleted when the PR is closed.
254
295
reactions : rocket
255
- env :
256
- PR_DEPLOYMENT_ACCESS_URL : " https://pr${{ env.PR_NUMBER }}.${{ secrets.PR_DEPLOYMENTS_DOMAIN }}"
0 commit comments