From 55c56dd839599ef184fc102c931b81354d214a6c Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Thu, 7 May 2026 19:19:05 +1000 Subject: [PATCH 1/4] Alternative preview "release" workflow --- .github/workflows/preview-release.yml | 33 +++++ .github/workflows/release-pr.yml | 183 -------------------------- scripts/release-pr.ts | 2 +- 3 files changed, 34 insertions(+), 184 deletions(-) create mode 100644 .github/workflows/preview-release.yml delete mode 100644 .github/workflows/release-pr.yml diff --git a/.github/workflows/preview-release.yml b/.github/workflows/preview-release.yml new file mode 100644 index 00000000..7c688fdd --- /dev/null +++ b/.github/workflows/preview-release.yml @@ -0,0 +1,33 @@ +name: Release Branch + +on: + workflow_dispatch: + +permissions: {} + +jobs: + release: + timeout-minutes: 20 + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - uses: ./.github/actions/ci-setup + + - run: yarn changeset version --snapshot branch-${{ github.ref_name }} + 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 + env: + GITHUB_REF_NAME: ${{ github.ref_name }} diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml deleted file mode 100644 index 35f2f5d1..00000000 --- a/.github/workflows/release-pr.yml +++ /dev/null @@ -1,183 +0,0 @@ -name: Release PR - -on: - issue_comment: - types: [created] - -permissions: {} - -jobs: - release_check: - if: github.repository == 'changesets/action' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/release-pr') - runs-on: ubuntu-latest - permissions: - contents: read - issues: write - pull-requests: read - 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: parse_command - run: | - if [[ "$COMMENT_BODY" =~ ^/release-pr[[:space:]]+([0-9a-fA-F]{7,40})[[:space:]]*$ ]] - then - echo "requested_sha=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" - else - echo "Expected '/release-pr ' where is a 7-40 character commit SHA." - exit 1 - fi - env: - COMMENT_BODY: ${{ github.event.comment.body }} - - - 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 }} - - - id: resolve_requested_sha - run: | - requested_sha=$(echo "$REQUESTED_SHA" | tr '[:upper:]' '[:lower:]') - - mapfile -t matches < <( - gh api /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/commits --paginate --jq '.[].sha' | - awk -v sha="$requested_sha" 'index(tolower($0), sha) == 1 { print $0 }' - ) - - if [[ ${#matches[@]} -eq 0 ]] - then - echo "Requested SHA $REQUESTED_SHA is not part of this pull request." - exit 1 - fi - - if [[ ${#matches[@]} -gt 1 ]] - then - echo "Requested SHA $REQUESTED_SHA is ambiguous for this pull request." - exit 1 - fi - - resolved_sha="${matches[0]}" - pr_head_sha=$(gh pr view ${{ github.event.issue.number }} --json headRefOid --jq '.headRefOid') - - if [[ "$resolved_sha" != "$pr_head_sha" ]] - then - echo "Requested SHA $resolved_sha is not the current PR head $pr_head_sha." - exit 1 - fi - - echo "resolved_sha=$resolved_sha" >> "$GITHUB_OUTPUT" - echo "pr_head_sha=$pr_head_sha" >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REQUESTED_SHA: ${{ steps.parse_command.outputs.requested_sha }} - - - id: get_pr_head_repository - run: | - echo "head_repository=$(gh pr view ${{ github.event.issue.number }} --json headRepositoryOwner,headRepository --jq '.headRepositoryOwner.login + "/" + .headRepository.name')" >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - outputs: - in_progress_reaction_id: ${{ steps.report_in_progress.outputs.in_progress_reaction_id }} - requested_sha: ${{ steps.parse_command.outputs.requested_sha }} - resolved_sha: ${{ steps.resolve_requested_sha.outputs.resolved_sha }} - pr_head_sha: ${{ steps.resolve_requested_sha.outputs.pr_head_sha }} - head_repository: ${{ steps.get_pr_head_repository.outputs.head_repository }} - - release: - if: github.repository == 'changesets/action' - timeout-minutes: 20 - runs-on: ubuntu-latest - needs: release_check - permissions: - contents: write - issues: write - pull-requests: write - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - uses: ./.github/actions/ci-setup - - - name: Fetch validated commit from pull request head repository - run: | - git remote add pr-head https://github.com/$HEAD_REPOSITORY.git - git fetch --no-tags pr-head $RESOLVED_SHA - env: - HEAD_REPOSITORY: ${{ needs.release_check.outputs.head_repository }} - RESOLVED_SHA: ${{ needs.release_check.outputs.resolved_sha }} - - - name: Checkout validated commit - run: git checkout --detach $RESOLVED_SHA - env: - RESOLVED_SHA: ${{ needs.release_check.outputs.resolved_sha }} - - - 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 - - - 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 release for \`${{ needs.release_check.outputs.resolved_sha }}\` triggered by [this comment](${{ github.event.comment.url }}) has [succeeded](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). Published commit: [${{ github.repository }}@$(git rev-parse HEAD)](https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD))." - 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') - permissions: - issues: write - pull-requests: write - 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 for \`${{ needs.release_check.outputs.requested_sha }}\` 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 }} diff --git a/scripts/release-pr.ts b/scripts/release-pr.ts index c20aefe8..14df5936 100644 --- a/scripts/release-pr.ts +++ b/scripts/release-pr.ts @@ -4,7 +4,7 @@ import path from "node:path"; import pkgJson from "../package.json" with { type: "json" }; const tag = `v${pkgJson.version}`; -const releaseLine = "pr-release"; +const releaseLine = `built-${process.env.GITHUB_REF_NAME}`; process.chdir(path.join(import.meta.dirname, "..")); From 49ce81563d3786f6e40dc0b99271f28371636683 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Thu, 7 May 2026 19:38:48 +1000 Subject: [PATCH 2/4] output job summary --- .github/workflows/preview-release.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/preview-release.yml b/.github/workflows/preview-release.yml index 7c688fdd..0e2b564e 100644 --- a/.github/workflows/preview-release.yml +++ b/.github/workflows/preview-release.yml @@ -31,3 +31,15 @@ jobs: run: yarn run release:pr env: GITHUB_REF_NAME: ${{ github.ref_name }} + + - name: Summarize preview release + run: | + commit_sha=$(git rev-parse HEAD) + + { + echo "Use this preview build in a GitHub Actions workflow:" + echo "" + echo '```yaml' + echo " - uses: ${GITHUB_REPOSITORY}@${commit_sha}" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" From d9dd7a665f2233ceb3d041112812d9e2cb2541d8 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Thu, 7 May 2026 19:42:00 +1000 Subject: [PATCH 3/4] Show diff for built version --- .github/workflows/preview-release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview-release.yml b/.github/workflows/preview-release.yml index 0e2b564e..c6459a0e 100644 --- a/.github/workflows/preview-release.yml +++ b/.github/workflows/preview-release.yml @@ -37,6 +37,8 @@ jobs: commit_sha=$(git rev-parse HEAD) { + echo "See the diff for this built version: https://github.com/changesets/action/compare/main...${GITHUB_REPOSITORY}:${commit_sha}" + echo "" echo "Use this preview build in a GitHub Actions workflow:" echo "" echo '```yaml' From cedecbb8166b8fc9cefcdd493ae05b97d7b27968 Mon Sep 17 00:00:00 2001 From: Emma Hamilton Date: Thu, 7 May 2026 19:50:34 +1000 Subject: [PATCH 4/4] Fix compare link --- .github/workflows/preview-release.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-release.yml b/.github/workflows/preview-release.yml index c6459a0e..aaa829c3 100644 --- a/.github/workflows/preview-release.yml +++ b/.github/workflows/preview-release.yml @@ -35,9 +35,11 @@ jobs: - name: Summarize preview release run: | commit_sha=$(git rev-parse HEAD) + repository_owner="${{ github.repository_owner }}" + repository_name="${{ github.event.repository.name }}" { - echo "See the diff for this built version: https://github.com/changesets/action/compare/main...${GITHUB_REPOSITORY}:${commit_sha}" + echo "See the diff for this built version: https://github.com/changesets/action/compare/main...${repository_owner}:${repository_name}:${commit_sha}" echo "" echo "Use this preview build in a GitHub Actions workflow:" echo ""