name: Release PR on: issue_comment: types: [created] jobs: release_check: if: github.repository == 'changesets/action' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/release-pr') runs-on: ubuntu-latest steps: - id: report_in_progress run: | echo "in_progress_reaction_id=$(gh api /repos/${{github.repository}}/issues/comments/${{github.event.comment.id}}/reactions -f content='eyes' --jq '.id')" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - id: check_authorization run: | if [[ $AUTHOR_ASSOCIATION == 'MEMBER' || $AUTHOR_ASSOCIATION == 'OWNER' || $AUTHOR_ASSOCIATION == 'COLLABORATOR' ]] then echo "User is authorized to release" else echo "User is not authorized to release" exit 1 fi env: AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }} outputs: in_progress_reaction_id: ${{ steps.report_in_progress.outputs.in_progress_reaction_id }} release: if: github.repository == 'changesets/action' timeout-minutes: 20 runs-on: ubuntu-latest needs: release_check steps: - uses: actions/checkout@v4 - name: Checkout pull request run: gh pr checkout ${{ github.event.issue.number }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Check if Version Packages PR id: check_version_packages run: | echo "version_packages=$(gh pr view ${{ github.event.issue.number }} --json headRefName --jq '.headRefName|startswith("changeset-release/")')" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Reset Version Packages PR if: steps.check_version_packages.outputs.version_packages == 'true' run: git reset --hard HEAD~1 - name: Use Node.js 20 uses: actions/setup-node@v4 with: node-version: 20.x - name: Install Dependencies run: yarn --frozen-lockfile - run: yarn changeset version --snapshot pr${{ github.event.issue.number }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build run: yarn build - name: Setup Git user run: | git config --global user.name "github-actions[bot]" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - name: Release snapshot version run: yarn run release:pr - run: gh api /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='rocket' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh api -X DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.release_check.outputs.in_progress_reaction_id }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - 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 }})." env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} report-failure-if-needed: needs: [release_check, release] timeout-minutes: 2 runs-on: ubuntu-latest if: failure() && github.repository == 'changesets/action' && (needs.release_check.result == 'failure' || needs.release.result == 'failure') steps: - run: gh api /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='-1' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh api -X DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.release_check.outputs.in_progress_reaction_id }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - 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 }})." env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }}