77 types :
88 - completed
99jobs :
10- build :
10+ deploy :
1111 runs-on : ubuntu-latest
12- if : >
13- ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
12+ if : github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
1413 steps :
1514 - name : " 🔍 Read PR number"
1615 id : readctx
17- # we need to find the PR number that corresponds to the branch, which we do by
18- # searching the GH API
16+ # We need to find the PR number that corresponds to the branch, which we do by searching the GH API
1917 # The workflow_run event includes a list of pull requests, but it doesn't get populated for
2018 # forked PRs: https://docs.github.com/en/rest/reference/checks#create-a-check-run
2119 run : |
2220 head_branch='${{github.event.workflow_run.head_repository.owner.login}}:${{github.event.workflow_run.head_branch}}'
23- echo "head branch: $head_branch"
21+ echo "Head branch: $head_branch"
2422 pulls_uri="https://api.github.com/repos/${{ github.repository }}/pulls?head=$(jq -Rr '@uri' <<<$head_branch)"
2523 pr_number=$(curl -s -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' "$pulls_uri" |
2624 jq -r '.[] | .number')
2725 echo "PR number: $pr_number"
2826 echo "::set-output name=prnumber::$pr_number"
2927
30- # There's a 'download artifact' action but it hasn't been updated for the
28+ - name : Create Deployment
29+ uses : bobheadxi/deployments@v1
30+ id : deployment
31+ with :
32+ step : start
33+ token : ${{ secrets.GITHUB_TOKEN }}
34+ env : Netlify
35+ ref : ${{ github.event.workflow_run.head_sha }}
36+ desc : |
37+ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware.
38+ Exercise caution. Use test accounts.
39+
40+ # There's a 'download artifact' action, but it hasn't been updated for the
3141 # workflow_run action (https://github.com/actions/download-artifact/issues/60)
3242 # so instead we get this mess:
3343 - name : ' Download artifact'
34443545 with :
3646 script : |
37- var artifacts = await github.actions.listWorkflowRunArtifacts({
38- owner: context.repo.owner,
39- repo: context.repo.repo,
40- run_id: ${{github.event.workflow_run.id }},
47+ const artifacts = await github.actions.listWorkflowRunArtifacts({
48+ owner: context.repo.owner,
49+ repo: context.repo.repo,
50+ run_id: ${{ github.event.workflow_run.id }},
4151 });
42- var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
43- return artifact.name == "previewbuild"
52+ const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
53+ return artifact.name == "previewbuild"
4454 })[0];
45- var download = await github.actions.downloadArtifact({
46- owner: context.repo.owner,
47- repo: context.repo.repo,
48- artifact_id: matchArtifact.id,
49- archive_format: 'zip',
55+ const download = await github.actions.downloadArtifact({
56+ owner: context.repo.owner,
57+ repo: context.repo.repo,
58+ artifact_id: matchArtifact.id,
59+ archive_format: 'zip',
5060 });
51- var fs = require('fs');
61+ const fs = require('fs');
5262 fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data));
5363
5464 - name : Extract Artifacts
@@ -69,12 +79,16 @@ jobs:
6979 NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
7080 timeout-minutes : 1
7181
72- - name : Edit PR Description
73- uses : Beakyn/gha-comment-pull-request@2167a7aee24f9e61ce76a23039f322e49a990409
74- env :
75- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
82+ - name : Update deployment status
83+ uses : bobheadxi/deployments@v1
84+ if : always()
7685 with :
77- pull-request-number : ${{ steps.readctx.outputs.prnumber }}
78- description-message : |
79- Preview: ${{ steps.netlify.outputs.deploy-url }}
80- ⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts.
86+ step : finish
87+ token : ${{ secrets.GITHUB_TOKEN }}
88+ status : ${{ job.status }}
89+ env : ${{ steps.deployment.outputs.env }}
90+ deployment_id : ${{ steps.deployment.outputs.deployment_id }}
91+ env_url : ${{ steps.netlify.outputs.deploy-url }}
92+ desc : |
93+ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware.
94+ Exercise caution. Use test accounts.
0 commit comments