|
2 | 2 | # and uploading it to netlify |
3 | 3 | name: Upload Preview Build to Netlify |
4 | 4 | on: |
5 | | - workflow_run: |
6 | | - workflows: ["Element Web - Build and Test"] |
7 | | - types: |
8 | | - - completed |
| 5 | + workflow_run: |
| 6 | + workflows: [ "Element Web - Build and Test" ] |
| 7 | + types: |
| 8 | + - completed |
9 | 9 | jobs: |
10 | | - build: |
11 | | - runs-on: ubuntu-latest |
12 | | - if: > |
13 | | - ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} |
14 | | - steps: |
15 | | - - name: "🔍 Read PR number" |
16 | | - id: readctx |
17 | | - # we need to find the PR number that corresponds to the branch, which we do by |
18 | | - # searching the GH API |
19 | | - # The workflow_run event includes a list of pull requests, but it doesn't get populated for |
20 | | - # forked PRs: https://docs.github.com/en/rest/reference/checks#create-a-check-run |
21 | | - run: | |
22 | | - head_branch='${{github.event.workflow_run.head_repository.owner.login}}:${{github.event.workflow_run.head_branch}}' |
23 | | - echo "head branch: $head_branch" |
24 | | - pulls_uri="https://api.github.com/repos/${{ github.repository }}/pulls?head=$(jq -Rr '@uri' <<<$head_branch)" |
25 | | - pr_number=$(curl -s -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' "$pulls_uri" | |
26 | | - jq -r '.[] | .number') |
27 | | - echo "PR number: $pr_number" |
28 | | - echo "::set-output name=prnumber::$pr_number" |
29 | | - # There's a 'download artifact' action but it hasn't been updated for the |
30 | | - # workflow_run action (https://github.com/actions/download-artifact/issues/60) |
31 | | - # so instead we get this mess: |
32 | | - - name: 'Download artifact' |
33 | | - |
34 | | - with: |
35 | | - script: | |
36 | | - var artifacts = await github.actions.listWorkflowRunArtifacts({ |
37 | | - owner: context.repo.owner, |
38 | | - repo: context.repo.repo, |
39 | | - run_id: ${{github.event.workflow_run.id }}, |
40 | | - }); |
41 | | - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
42 | | - return artifact.name == "previewbuild" |
43 | | - })[0]; |
44 | | - var download = await github.actions.downloadArtifact({ |
45 | | - owner: context.repo.owner, |
46 | | - repo: context.repo.repo, |
47 | | - artifact_id: matchArtifact.id, |
48 | | - archive_format: 'zip', |
49 | | - }); |
50 | | - var fs = require('fs'); |
51 | | - fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data)); |
52 | | - - name: Extract Artifacts |
53 | | - run: unzip -d webapp previewbuild.zip && rm previewbuild.zip |
54 | | - - name: Deploy to Netlify |
55 | | - id: netlify |
56 | | - |
57 | | - with: |
58 | | - publish-dir: webapp |
59 | | - deploy-message: "Deploy from GitHub Actions" |
60 | | - # These don't work because we're in workflow_run |
61 | | - enable-pull-request-comment: false |
62 | | - enable-commit-comment: false |
63 | | - alias: pr${{ steps.readctx.outputs.prnumber }} |
64 | | - env: |
65 | | - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
66 | | - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
67 | | - timeout-minutes: 1 |
68 | | - - name: Edit PR Description |
69 | | - uses: Beakyn/gha-comment-pull-request@2167a7aee24f9e61ce76a23039f322e49a990409 |
70 | | - env: |
71 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
72 | | - with: |
73 | | - pull-request-number: ${{ steps.readctx.outputs.prnumber }} |
74 | | - description-message: | |
75 | | - Preview: ${{ steps.netlify.outputs.deploy-url }} |
76 | | - ⚠️ Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. Exercise caution. Use test accounts. |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: > |
| 13 | + ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} |
| 14 | + steps: |
| 15 | + - name: "🔍 Read PR number" |
| 16 | + id: readctx |
| 17 | + # we need to find the PR number that corresponds to the branch, which we do by |
| 18 | + # searching the GH API |
| 19 | + # The workflow_run event includes a list of pull requests, but it doesn't get populated for |
| 20 | + # forked PRs: https://docs.github.com/en/rest/reference/checks#create-a-check-run |
| 21 | + run: | |
| 22 | + head_branch='${{github.event.workflow_run.head_repository.owner.login}}:${{github.event.workflow_run.head_branch}}' |
| 23 | + echo "head branch: $head_branch" |
| 24 | + pulls_uri="https://api.github.com/repos/${{ github.repository }}/pulls?head=$(jq -Rr '@uri' <<<$head_branch)" |
| 25 | + pr_number=$(curl -s -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' "$pulls_uri" | |
| 26 | + jq -r '.[] | .number') |
| 27 | + echo "PR number: $pr_number" |
| 28 | + echo "::set-output name=prnumber::$pr_number" |
77 | 29 |
|
| 30 | + # There's a 'download artifact' action but it hasn't been updated for the |
| 31 | + # workflow_run action (https://github.com/actions/download-artifact/issues/60) |
| 32 | + # so instead we get this mess: |
| 33 | + - name: 'Download artifact' |
| 34 | + |
| 35 | + with: |
| 36 | + 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 }}, |
| 41 | + }); |
| 42 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 43 | + return artifact.name == "previewbuild" |
| 44 | + })[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', |
| 50 | + }); |
| 51 | + var fs = require('fs'); |
| 52 | + fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data)); |
| 53 | +
|
| 54 | + - name: Extract Artifacts |
| 55 | + run: unzip -d webapp previewbuild.zip && rm previewbuild.zip |
| 56 | + |
| 57 | + - name: Deploy to Netlify |
| 58 | + id: netlify |
| 59 | + |
| 60 | + with: |
| 61 | + publish-dir: webapp |
| 62 | + deploy-message: "Deploy from GitHub Actions" |
| 63 | + # These don't work because we're in workflow_run |
| 64 | + enable-pull-request-comment: false |
| 65 | + enable-commit-comment: false |
| 66 | + alias: pr${{ steps.readctx.outputs.prnumber }} |
| 67 | + env: |
| 68 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 69 | + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 70 | + timeout-minutes: 1 |
| 71 | + |
| 72 | + - name: Edit PR Description |
| 73 | + uses: Beakyn/gha-comment-pull-request@2167a7aee24f9e61ce76a23039f322e49a990409 |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + 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. |
0 commit comments