|
| 1 | +name: Upload REPL artefacts |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - Build REPL artefacts |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + upload: |
| 15 | + permissions: |
| 16 | + pull-requests: write # for removing the label and peter-evans/find-comment and peter-evans/create-or-update-comment |
| 17 | + actions: read # for downloading workflow run artifacts |
| 18 | + id-token: write # for AWS OIDC authentication |
| 19 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + name: Upload |
| 22 | + steps: |
| 23 | + - name: Check whether artefacts were produced |
| 24 | + id: check |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + run: | |
| 28 | + # The build job is skipped for untriggered fork PRs, leaving zero artifacts. |
| 29 | + # In that case the workflow_run still completes with 'success', so we guard here. |
| 30 | + ARTIFACT_COUNT=$(gh api /repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts \ |
| 31 | + --jq '.total_count') |
| 32 | + if [[ "$ARTIFACT_COUNT" != "0" ]]; then |
| 33 | + echo "has-artefacts=true" >> "$GITHUB_OUTPUT" |
| 34 | + else |
| 35 | + echo "has-artefacts=false" >> "$GITHUB_OUTPUT" |
| 36 | + fi |
| 37 | + - name: Download artefacts |
| 38 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 39 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 40 | + with: |
| 41 | + run-id: ${{ github.event.workflow_run.id }} |
| 42 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + pattern: repl-artefacts |
| 44 | + path: repl-artefacts |
| 45 | + - name: Resolve PR number and label from trusted API |
| 46 | + id: pr-number |
| 47 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 48 | + env: |
| 49 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + run: | |
| 51 | + HEAD_SHA="${{ github.event.workflow_run.head_sha }}" |
| 52 | + HEAD_REPO="${{ github.event.workflow_run.head_repository.full_name }}" |
| 53 | +
|
| 54 | + # For same-repo PRs the number is available directly in the workflow_run event. |
| 55 | + # For fork PRs we look it up via the API using the head SHA and head repository. |
| 56 | + PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}" |
| 57 | + if [[ -z "$PR_NUMBER" ]]; then |
| 58 | + PR_NUMBER=$(gh api "/repos/${{ github.repository }}/pulls" \ |
| 59 | + --jq ".[] | select(.head.sha == \"$HEAD_SHA\" and .head.repo.full_name == \"$HEAD_REPO\") | .number" \ |
| 60 | + -f state=open) |
| 61 | + fi |
| 62 | +
|
| 63 | + if [[ -z "$PR_NUMBER" || ! "$PR_NUMBER" =~ ^[0-9]+$ ]]; then |
| 64 | + echo "Could not resolve a valid PR number" >&2 |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + echo "pr-number=$PR_NUMBER" >> "$GITHUB_OUTPUT" |
| 68 | +
|
| 69 | + # Check via API whether the label is currently present on the PR |
| 70 | + LABEL=$(gh api "/repos/${{ github.repository }}/issues/$PR_NUMBER/labels" \ |
| 71 | + --jq '.[] | select(.name == "x⁸ ⚙️ build repl artefacts") | .name') |
| 72 | + if [[ -n "$LABEL" ]]; then |
| 73 | + echo "labeled=true" >> "$GITHUB_OUTPUT" |
| 74 | + else |
| 75 | + echo "labeled=false" >> "$GITHUB_OUTPUT" |
| 76 | + fi |
| 77 | + - name: Remove 'x⁸ ⚙️ build repl artefacts' label |
| 78 | + if: ${{ steps.pr-number.outputs.labeled == 'true' }} |
| 79 | + run: gh pr edit ${{ steps.pr-number.outputs.pr-number }} --repo ${{ github.repository }} --remove-label 'x⁸ ⚙️ build repl artefacts' |
| 80 | + env: |
| 81 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + - name: Configure AWS credentials via OIDC |
| 83 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 84 | + uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 |
| 85 | + with: |
| 86 | + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} |
| 87 | + aws-region: ${{ secrets.AWS_REGION }} |
| 88 | + - name: Upload "${{ steps.pr-number.outputs.pr-number }}/rollup.browser.js" to bucket |
| 89 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 90 | + uses: zdurham/s3-upload-github-action@161dfa6991b9d88a97f02f4aeb5dcd26ea7e03cd # master |
| 91 | + with: |
| 92 | + args: --cache-control max-age=300,public |
| 93 | + env: |
| 94 | + FILE: repl-artefacts/rollup.browser.js |
| 95 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 96 | + S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} |
| 97 | + S3_KEY: ${{ steps.pr-number.outputs.pr-number }}/rollup.browser.js |
| 98 | + - name: Upload "${{ steps.pr-number.outputs.pr-number }}/rollup.browser.js.map" to bucket |
| 99 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 100 | + uses: zdurham/s3-upload-github-action@161dfa6991b9d88a97f02f4aeb5dcd26ea7e03cd # master |
| 101 | + with: |
| 102 | + args: --cache-control max-age=300,public |
| 103 | + env: |
| 104 | + FILE: repl-artefacts/rollup.browser.js.map |
| 105 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 106 | + S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} |
| 107 | + S3_KEY: ${{ steps.pr-number.outputs.pr-number }}/rollup.browser.js.map |
| 108 | + - name: Upload "${{ steps.pr-number.outputs.pr-number }}/bindings_wasm_bg.wasm" to bucket |
| 109 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 110 | + uses: zdurham/s3-upload-github-action@161dfa6991b9d88a97f02f4aeb5dcd26ea7e03cd # master |
| 111 | + with: |
| 112 | + args: --cache-control max-age=300,public |
| 113 | + env: |
| 114 | + FILE: repl-artefacts/bindings_wasm_bg.wasm |
| 115 | + AWS_REGION: ${{ secrets.AWS_REGION }} |
| 116 | + S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} |
| 117 | + S3_KEY: ${{ steps.pr-number.outputs.pr-number }}/bindings_wasm_bg.wasm |
| 118 | + - name: Find Comment |
| 119 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 120 | + uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0 |
| 121 | + id: findComment |
| 122 | + with: |
| 123 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 124 | + comment-author: 'github-actions[bot]' |
| 125 | + body-includes: 'Thank you for your contribution!' |
| 126 | + - name: Create or update comment |
| 127 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 128 | + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 |
| 129 | + id: createInitialComment |
| 130 | + with: |
| 131 | + comment-id: ${{ steps.findComment.outputs.comment-id }} |
| 132 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 133 | + edit-mode: replace |
| 134 | + body: | |
| 135 | + ### Thank you for your contribution! ❤️ |
| 136 | +
|
| 137 | + You can try out this pull request locally by installing Rollup via |
| 138 | +
|
| 139 | + ```bash |
| 140 | + npm install ${{ github.event.workflow_run.head_repository.full_name }}#${{ github.event.workflow_run.head_branch }} |
| 141 | + ``` |
| 142 | +
|
| 143 | + Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. |
| 144 | +
|
| 145 | + or load it into the REPL: |
| 146 | + https://rollupjs.org/repl/?pr=${{ steps.pr-number.outputs.pr-number }} |
| 147 | + - name: Find Vercel preview URL |
| 148 | + if: ${{ steps.check.outputs.has-artefacts == 'true' }} |
| 149 | + uses: patrickedqvist/wait-for-vercel-preview@d7982701e6fcd3ae073bff929e408e004404d38d # v1.3.3 |
| 150 | + id: waitForVercel |
| 151 | + env: |
| 152 | + GITHUB_SHA: ${{ github.event.workflow_run.head_sha }} |
| 153 | + with: |
| 154 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 155 | + - name: Update comment with Vercel preview URL |
| 156 | + uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 |
| 157 | + if: ${{ steps.check.outputs.has-artefacts == 'true' && steps.waitForVercel.outputs.url }} |
| 158 | + with: |
| 159 | + comment-id: ${{ steps.createInitialComment.outputs.comment-id }} |
| 160 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 161 | + edit-mode: replace |
| 162 | + body: | |
| 163 | + ### Thank you for your contribution! ❤️ |
| 164 | +
|
| 165 | + You can try out this pull request locally by installing Rollup via |
| 166 | +
|
| 167 | + ```bash |
| 168 | + npm install ${{ github.event.workflow_run.head_repository.full_name }}#${{ github.event.workflow_run.head_branch }} |
| 169 | + ``` |
| 170 | +
|
| 171 | + Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. |
| 172 | +
|
| 173 | + or load it into the REPL: |
| 174 | + ${{ steps.waitForVercel.outputs.url }}/repl/?pr=${{ steps.pr-number.outputs.pr-number }} |
0 commit comments