|
| 1 | +name: Prepare release |
| 2 | + |
| 3 | +# Manually-triggered: bumps every version-bearing file and writes the |
| 4 | +# CHANGELOG.md entry (from conventional-commit subjects since the previous |
| 5 | +# tag) on a release/vX.Y.Z branch, then opens a PR against main. main is |
| 6 | +# ruleset-protected, so this cannot push or tag directly — merging the PR is |
| 7 | +# the approval gate. Once merged, .github/workflows/release-publish.yml tags |
| 8 | +# the merge commit and creates the GitHub Release automatically. |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: 'New version, semver without a leading "v" (e.g. 0.3.0)' |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + pull-requests: write |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: release |
| 23 | + cancel-in-progress: false |
| 24 | + |
| 25 | +jobs: |
| 26 | + prepare: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Ensure running from main |
| 30 | + run: | |
| 31 | + if [ "${{ github.ref }}" != "refs/heads/main" ]; then |
| 32 | + echo "::error::Run this workflow from the main branch (got ${{ github.ref }})." |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +
|
| 36 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + fetch-tags: true |
| 40 | + |
| 41 | + - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 42 | + with: |
| 43 | + node-version: '22' |
| 44 | + |
| 45 | + - name: Validate version and compute previous tag |
| 46 | + run: | |
| 47 | + VERSION="${{ inputs.version }}" |
| 48 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 49 | + echo "::error::version must be semver X.Y.Z with no leading 'v' (got '$VERSION')." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + if git rev-parse "v$VERSION" >/dev/null 2>&1; then |
| 53 | + echo "::error::tag v$VERSION already exists." |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + if git ls-remote --exit-code --heads origin "release/v$VERSION" >/dev/null 2>&1; then |
| 57 | + echo "::error::branch release/v$VERSION already exists on origin." |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + PREV_TAG="$(git describe --tags --abbrev=0 2>/dev/null || true)" |
| 61 | + echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 62 | + echo "PREV_TAG=$PREV_TAG" >> "$GITHUB_ENV" |
| 63 | + echo "Preparing v$VERSION (previous tag: ${PREV_TAG:-none})" |
| 64 | +
|
| 65 | + - name: Generate changelog section |
| 66 | + run: | |
| 67 | + node .github/scripts/generate-changelog-entry.mjs "$PREV_TAG" "$VERSION" > /tmp/section.md |
| 68 | + cat /tmp/section.md |
| 69 | +
|
| 70 | + - name: Insert changelog section |
| 71 | + run: | |
| 72 | + node .github/scripts/insert-changelog-entry.mjs CHANGELOG.md /tmp/section.md "$VERSION" "${{ github.repository }}" |
| 73 | +
|
| 74 | + - name: Bump package versions |
| 75 | + run: | |
| 76 | + for dir in . dashboard .github/actions/report; do |
| 77 | + (cd "$dir" && npm version "$VERSION" --no-git-tag-version --allow-same-version) |
| 78 | + done |
| 79 | +
|
| 80 | + - name: Update README action-usage pins |
| 81 | + run: | |
| 82 | + sed -i -E "s#(\.github/actions/report@v)[0-9]+\.[0-9]+\.[0-9]+#\1${VERSION}#g" \ |
| 83 | + README.md .github/actions/report/README.md |
| 84 | +
|
| 85 | + - name: Commit release changes |
| 86 | + run: | |
| 87 | + git config user.name "github-actions[bot]" |
| 88 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 89 | + git checkout -b "release/v$VERSION" |
| 90 | + git add \ |
| 91 | + package.json package-lock.json \ |
| 92 | + dashboard/package.json dashboard/package-lock.json \ |
| 93 | + .github/actions/report/package.json .github/actions/report/package-lock.json \ |
| 94 | + CHANGELOG.md README.md .github/actions/report/README.md |
| 95 | + git commit -m "chore(release): v$VERSION" |
| 96 | + git push origin "release/v$VERSION" |
| 97 | +
|
| 98 | + - name: Open release PR |
| 99 | + env: |
| 100 | + GH_TOKEN: ${{ github.token }} |
| 101 | + run: | |
| 102 | + gh pr create \ |
| 103 | + --base main \ |
| 104 | + --head "release/v$VERSION" \ |
| 105 | + --title "chore(release): v$VERSION" \ |
| 106 | + --body-file /tmp/section.md |
0 commit comments