|
| 1 | +name: Publish a preview build |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: created |
| 6 | + |
| 7 | +jobs: |
| 8 | + is-fork-pull-request: |
| 9 | + name: Determine whether this issue comment was on a pull request from a fork |
| 10 | + if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot publish-preview') }} |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + pull-requests: read |
| 15 | + outputs: |
| 16 | + IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Determine whether this PR is from a fork |
| 20 | + id: is-fork |
| 21 | + run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT" |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + PR_NUMBER: ${{ github.event.issue.number }} |
| 25 | + |
| 26 | + react-to-comment: |
| 27 | + name: React to the comment |
| 28 | + needs: is-fork-pull-request |
| 29 | + # This ensures we don't publish on forks. We can't trust forks with this token. |
| 30 | + if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }} |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + pull-requests: write |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + - name: React to the comment |
| 38 | + run: | |
| 39 | + gh api \ |
| 40 | + --method POST \ |
| 41 | + -H "Accept: application/vnd.github+json" \ |
| 42 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 43 | + "/repos/${REPO}/issues/comments/${COMMENT_ID}/reactions" \ |
| 44 | + -f content='+1' |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + COMMENT_ID: ${{ github.event.comment.id }} |
| 48 | + REPO: ${{ github.repository }} |
| 49 | + |
| 50 | + publish-preview: |
| 51 | + name: Publish build preview |
| 52 | + needs: react-to-comment |
| 53 | + runs-on: ubuntu-latest |
| 54 | + permissions: |
| 55 | + contents: read |
| 56 | + pull-requests: write |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + - name: Check out pull request |
| 60 | + run: gh pr checkout "${PR_NUMBER}" |
| 61 | + env: |
| 62 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + PR_NUMBER: ${{ github.event.issue.number }} |
| 64 | + - name: Checkout and setup environment |
| 65 | + uses: MetaMask/action-checkout-and-setup@v1 |
| 66 | + with: |
| 67 | + is-high-risk-environment: true |
| 68 | + - name: Get commit SHA |
| 69 | + id: commit-sha |
| 70 | + run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
| 71 | + - run: ./scripts/prepare-preview-builds.sh @metamask-previews ${{ steps.commit-sha.outputs.COMMIT_SHA }} |
| 72 | + - run: yarn build |
| 73 | + - name: Publish preview build |
| 74 | + run: yarn npm publish --tag preview |
| 75 | + env: |
| 76 | + YARN_NPM_AUTH_TOKEN: ${{ secrets.PUBLISH_PREVIEW_NPM_TOKEN }} |
| 77 | + - name: Post build preview in comment |
| 78 | + run: ./scripts/generate-preview-build-message.sh | gh pr comment "${PR_NUMBER}" --body-file - |
| 79 | + env: |
| 80 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }} |
| 82 | + PR_NUMBER: ${{ github.event.issue.number }} |
0 commit comments