|
| 1 | +name: Release PR |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release_check: |
| 9 | + if: github.repository == 'changesets/action' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/release-pr') |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - id: report_in_progress |
| 13 | + run: | |
| 14 | + echo "in_progress_reaction_id=$(gh api /repos/${{github.repository}}/issues/comments/${{github.event.comment.id}}/reactions -f content='eyes' --jq '.id')" >> "$GITHUB_OUTPUT" |
| 15 | + env: |
| 16 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 17 | + |
| 18 | + - id: check_authorization |
| 19 | + run: | |
| 20 | + if [[ $AUTHOR_ASSOCIATION == 'MEMBER' || $AUTHOR_ASSOCIATION == 'OWNER' || $AUTHOR_ASSOCIATION == 'COLLABORATOR' ]] |
| 21 | + then |
| 22 | + echo "User is authorized to release" |
| 23 | + else |
| 24 | + echo "User is not authorized to release" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + env: |
| 28 | + AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }} |
| 29 | + |
| 30 | + outputs: |
| 31 | + in_progress_reaction_id: ${{ steps.report_in_progress.outputs.in_progress_reaction_id }} |
| 32 | + |
| 33 | + release: |
| 34 | + if: github.repository == 'changesets/action' |
| 35 | + timeout-minutes: 20 |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: release_check |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + - uses: ./.github/actions/ci-setup |
| 41 | + |
| 42 | + - name: Checkout pull request |
| 43 | + run: gh pr checkout ${{ github.event.issue.number }} |
| 44 | + env: |
| 45 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + |
| 47 | + - name: Check if Version Packages PR |
| 48 | + id: check_version_packages |
| 49 | + run: | |
| 50 | + echo "version_packages=$(gh pr view ${{ github.event.issue.number }} --json headRefName --jq '.headRefName|startswith("changeset-release/")')" >> "$GITHUB_OUTPUT" |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Reset Version Packages PR |
| 55 | + if: steps.check_version_packages.outputs.version_packages == 'true' |
| 56 | + run: git reset --hard HEAD~1 |
| 57 | + |
| 58 | + - run: yarn changeset version --snapshot pr${{ github.event.issue.number }} |
| 59 | + env: |
| 60 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Build |
| 63 | + run: yarn build |
| 64 | + |
| 65 | + - name: Setup Git user |
| 66 | + run: | |
| 67 | + git config --global user.name "github-actions[bot]" |
| 68 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 69 | +
|
| 70 | + - name: Release snapshot version |
| 71 | + run: yarn run release:pr |
| 72 | + |
| 73 | + - run: gh api /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='rocket' |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + - run: gh api -X DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.release_check.outputs.in_progress_reaction_id }} |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + |
| 81 | + - run: gh pr comment ${{ github.event.issue.number }} --body "The [${{ github.repository }}@$(git rev-parse HEAD)](https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)) release triggered by [this comment](${{ github.event.comment.url }}) has [succeeded](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})." |
| 82 | + env: |
| 83 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + |
| 85 | + report-failure-if-needed: |
| 86 | + needs: [release_check, release] |
| 87 | + timeout-minutes: 2 |
| 88 | + runs-on: ubuntu-latest |
| 89 | + if: failure() && github.repository == 'changesets/action' && (needs.release_check.result == 'failure' || needs.release.result == 'failure') |
| 90 | + steps: |
| 91 | + - run: gh api /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='-1' |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + |
| 95 | + - run: gh api -X DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.release_check.outputs.in_progress_reaction_id }} |
| 96 | + env: |
| 97 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - run: gh pr comment ${{ github.event.issue.number }} --body "The release triggered by [this comment](${{ github.event.comment.url }}) has [failed](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})." |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + GH_REPO: ${{ github.repository }} |
0 commit comments