Prepare Release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Prepare Release | |
| on: | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: prepare-release-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| env: | |
| HUSKY: "0" | |
| jobs: | |
| prepare-release: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Require main branch | |
| run: | | |
| if [ "${{ github.ref_name }}" != "main" ]; then | |
| { | |
| echo "## Prepare release" | |
| echo | |
| echo "This workflow must be run from \`main\`. Selected ref: \`${{ github.ref_name }}\`." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| exit 1 | |
| fi | |
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| with: | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0 | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| with: | |
| node-version-file: .tool-versions | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Validate publishable package metadata | |
| run: node scripts/release/validate-publishable-packages.mjs | |
| - name: Record source commit and prepare branch | |
| id: source | |
| run: | | |
| main_sha="$(git rev-parse HEAD)" | |
| short_main_sha="$(git rev-parse --short=12 HEAD)" | |
| prepare_branch="prepare-release/${short_main_sha}" | |
| { | |
| echo "main_sha=$main_sha" | |
| echo "short_main_sha=$short_main_sha" | |
| echo "prepare_branch=$prepare_branch" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Run changeset version | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: pnpm exec changeset version | |
| - name: Create release commit | |
| id: release_commit | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git switch -c "${{ steps.source.outputs.prepare_branch }}" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No release changes were generated by changeset version." | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| git commit -m "chore: Prepare release" | |
| git push origin HEAD:refs/heads/${{ steps.source.outputs.prepare_branch }} | |
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | |
| - name: Summarize empty release | |
| if: steps.release_commit.outputs.has_changes == 'false' | |
| run: | | |
| { | |
| echo "## Prepare release" | |
| echo | |
| echo "No release changes were generated by \`changeset version\`." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Create release PR | |
| if: steps.release_commit.outputs.has_changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| { | |
| echo "Prepares a release by updating package versions, changelogs, and consumed changeset files." | |
| echo | |
| echo "Source-main-sha: ${{ steps.source.outputs.main_sha }}" | |
| } > release-pr-body.md | |
| pr_url="$(gh pr create \ | |
| --base main \ | |
| --head "${{ steps.source.outputs.prepare_branch }}" \ | |
| --title "chore: Prepare release (${{ steps.source.outputs.short_main_sha }})" \ | |
| --body-file release-pr-body.md)" | |
| pr_number="${pr_url##*/}" | |
| { | |
| echo "## Prepare release" | |
| echo | |
| echo "Created release PR: $pr_url" | |
| echo | |
| echo "To publish this release, run the \`Publish Stable Release\` workflow with:" | |
| echo | |
| echo "\`\`\`text" | |
| echo "release_pr: $pr_number" | |
| echo "\`\`\`" | |
| } >> "$GITHUB_STEP_SUMMARY" |