|
| 1 | +name: Prepare Release PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - development |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: release-pr-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + prepare-release-pr: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Compute release state |
| 28 | + id: versions |
| 29 | + run: | |
| 30 | + current_version="$(tr -d '\n' < VERSION)" |
| 31 | + next_version="$(python3 tools/release.py next-version)" |
| 32 | + echo "current_version=${current_version}" >> "$GITHUB_OUTPUT" |
| 33 | + echo "next_version=${next_version}" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + - name: Skip when nothing releasable is pending |
| 36 | + if: steps.versions.outputs.current_version == steps.versions.outputs.next_version |
| 37 | + run: | |
| 38 | + echo "No releasable changesets are pending." |
| 39 | + python3 tools/release.py preview --format markdown >> "$GITHUB_STEP_SUMMARY" |
| 40 | +
|
| 41 | + - name: Prepare release branch |
| 42 | + if: steps.versions.outputs.current_version != steps.versions.outputs.next_version |
| 43 | + id: prepare |
| 44 | + run: | |
| 45 | + python3 tools/release.py apply --output .release-version |
| 46 | + release_version="$(tr -d '\n' < .release-version)" |
| 47 | + echo "release_version=${release_version}" >> "$GITHUB_OUTPUT" |
| 48 | +
|
| 49 | + git config user.name "github-actions[bot]" |
| 50 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 51 | + git switch -C release/next |
| 52 | + git add VERSION CHANGELOG.md .changesets |
| 53 | + git commit -m "chore(release): prepare v${release_version}" |
| 54 | + git push --force --set-upstream origin release/next |
| 55 | +
|
| 56 | + - name: Create or update release PR |
| 57 | + if: steps.versions.outputs.current_version != steps.versions.outputs.next_version |
| 58 | + uses: actions/github-script@v7 |
| 59 | + env: |
| 60 | + RELEASE_VERSION: ${{ steps.prepare.outputs.release_version }} |
| 61 | + with: |
| 62 | + script: | |
| 63 | + const owner = context.repo.owner; |
| 64 | + const repo = context.repo.repo; |
| 65 | + const head = `${owner}:release/next`; |
| 66 | + const base = 'development'; |
| 67 | + const title = `chore(release): prepare v${process.env.RELEASE_VERSION}`; |
| 68 | + const marker = '<!-- st-lib-release-pr -->'; |
| 69 | + const body = [ |
| 70 | + marker, |
| 71 | + '', |
| 72 | + 'This PR was prepared automatically from the pending ST-LIB changesets.', |
| 73 | + '', |
| 74 | + `- Version: \`v${process.env.RELEASE_VERSION}\``, |
| 75 | + '- Source of truth: `VERSION`', |
| 76 | + '- Release notes source: `CHANGELOG.md`', |
| 77 | + ].join('\n'); |
| 78 | +
|
| 79 | + const { data: pulls } = await github.rest.pulls.list({ |
| 80 | + owner, |
| 81 | + repo, |
| 82 | + state: 'open', |
| 83 | + head, |
| 84 | + base, |
| 85 | + }); |
| 86 | +
|
| 87 | + if (pulls.length > 0) { |
| 88 | + await github.rest.pulls.update({ |
| 89 | + owner, |
| 90 | + repo, |
| 91 | + pull_number: pulls[0].number, |
| 92 | + title, |
| 93 | + body, |
| 94 | + }); |
| 95 | + } else { |
| 96 | + await github.rest.pulls.create({ |
| 97 | + owner, |
| 98 | + repo, |
| 99 | + title, |
| 100 | + head: 'release/next', |
| 101 | + base, |
| 102 | + body, |
| 103 | + }); |
| 104 | + } |
0 commit comments