|
| 1 | +name: Dev version bump |
| 2 | + |
| 3 | +# When a release publishes, open a pull request that moves `dev` past the published |
| 4 | +# version. Without this, `dev` keeps carrying a version that is at or behind a released |
| 5 | +# one, and `tests/release-version-line.test.ts` fails on `dev` and on every pull request |
| 6 | +# opened against it - inherited red a contributor cannot fix from their own diff. |
| 7 | +# |
| 8 | +# That has been repaired by hand four times: 32529c2b2, e4a85d134, 076ad3036, befcac3e1. |
| 9 | +# The second of those ADDED the detector and two more repairs followed it, so more |
| 10 | +# visibility was never the missing piece; a prepared change was. |
| 11 | +# |
| 12 | +# WHAT THIS DOES NOT DO. It does not push to `dev`. It opens a pull request and a human |
| 13 | +# merges it, because ruleset `Protect dev` requires an approving review and code-owner |
| 14 | +# sign-off that a bot cannot supply. Until that merge the red persists. This converts a |
| 15 | +# forgotten chore into a queued, reviewable change - not into an automatic repair. |
| 16 | +# |
| 17 | +# A `release` event resolves this workflow file from the repository DEFAULT branch |
| 18 | +# (`main`), not from `dev` - the same trap documented in cleanup-closed-pr-branches.yml. |
| 19 | +# So merging this file to `dev` installs it but arms nothing; it first fires after an |
| 20 | +# ordinary dev -> main promotion carries it there. |
| 21 | +# |
| 22 | +# There is deliberately no `workflow_dispatch`: a branch-selected manual run executes |
| 23 | +# THAT branch body with `contents: write`. Re-drive a missed run by running |
| 24 | +# `bun scripts/bump-dev-version.ts <released> package.json` locally and opening the pull |
| 25 | +# request normally. |
| 26 | +on: |
| 27 | + release: |
| 28 | + types: [published] |
| 29 | + |
| 30 | +permissions: {} |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: dev-version-bump |
| 34 | + cancel-in-progress: false |
| 35 | + |
| 36 | +jobs: |
| 37 | + open-bump-pr: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + # Push the new codex/dev-version-* branch. Ruleset `Protect dev` covers only |
| 41 | + # refs/heads/dev, so the bump branch is unprotected and this token cannot |
| 42 | + # bypass dev review. It is the ruleset that keeps this job off dev, not the |
| 43 | + # permission name. |
| 44 | + contents: write |
| 45 | + # Open the pull request. |
| 46 | + pull-requests: write |
| 47 | + steps: |
| 48 | + - name: Checkout dev |
| 49 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 |
| 50 | + with: |
| 51 | + ref: dev |
| 52 | + # Tags are load-bearing, not decoration: the freeness gate below is a bun |
| 53 | + # test that reads the local tag set, and release-version-line.test.ts |
| 54 | + # returns EARLY on an empty set. A shallow checkout would make that gate |
| 55 | + # silently vacuous instead of failing loudly. |
| 56 | + fetch-depth: 0 |
| 57 | + # Do NOT set persist-credentials: false here as the read-only workflows do. |
| 58 | + # This job has to push its bump branch. |
| 59 | + |
| 60 | + # The repository-owned composite action, not a hand-pinned setup-bun SHA: it |
| 61 | + # resolves the Bun version from package.json so the runtime SOT stays in one |
| 62 | + # place. An independently pinned action here would drift from every other job. |
| 63 | + - name: Setup project Bun |
| 64 | + uses: ./.github/actions/setup-project-bun |
| 65 | + |
| 66 | + - name: Install dependencies |
| 67 | + run: bun install --frozen-lockfile |
| 68 | + |
| 69 | + - name: Decide the version dev should carry |
| 70 | + id: decide |
| 71 | + env: |
| 72 | + RELEASED_VERSION: ${{ github.event.release.tag_name }} |
| 73 | + run: | |
| 74 | + set -euo pipefail |
| 75 | + bun scripts/bump-dev-version.ts "${RELEASED_VERSION}" package.json |
| 76 | +
|
| 77 | + - name: Prove the chosen version is unused |
| 78 | + if: ${{ steps.decide.outputs.changed == 'true' }} |
| 79 | + # The script decides the candidate from the released version SHAPE, which is all |
| 80 | + # a pure function can see. Whether that candidate is actually FREE is a property |
| 81 | + # of the tag set, so it is settled here by the detector that already owns the |
| 82 | + # question. If this fails, no pull request is opened and the job goes red asking |
| 83 | + # for a human decision - which is the correct outcome, not a fallback. |
| 84 | + run: bun test tests/release-version-line.test.ts |
| 85 | + |
| 86 | + - name: Open the bump pull request |
| 87 | + if: ${{ steps.decide.outputs.changed == 'true' }} |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ github.token }} |
| 90 | + NEXT_VERSION: ${{ steps.decide.outputs.version }} |
| 91 | + RELEASED_VERSION: ${{ github.event.release.tag_name }} |
| 92 | + run: | |
| 93 | + set -euo pipefail |
| 94 | +
|
| 95 | + branch="codex/dev-version-${NEXT_VERSION}" |
| 96 | +
|
| 97 | + # Idempotent: a second publish, a re-run, or a manual repair must not turn a |
| 98 | + # successful release into a red job. |
| 99 | + # |
| 100 | + # Check the PULL REQUEST as well as the branch, not just the branch. A security |
| 101 | + # review caught that: an open bump pull request whose head branch was deleted |
| 102 | + # leaves the branch check passing, so the job would recreate the branch and then |
| 103 | + # fail on `gh pr create` with "already exists" — turning a successful release red |
| 104 | + # for a repair that was already queued. |
| 105 | + open_prs="$(gh pr list --base dev --head "${branch}" --state open --json number --jq 'length')" |
| 106 | + if [ "${open_prs}" != "0" ]; then |
| 107 | + echo "::notice::a bump pull request for ${branch} is already open; nothing to do" |
| 108 | + exit 0 |
| 109 | + fi |
| 110 | +
|
| 111 | + # An existing branch is NOT terminal. If a previous run pushed the branch and then |
| 112 | + # failed at `gh pr create`, exiting here would leave the repair permanently unqueued |
| 113 | + # while every rerun reports success - the exact failure mode a reviewer caught. So |
| 114 | + # reuse the branch and fall through to pull-request creation instead. |
| 115 | + if git ls-remote --exit-code --heads origin "${branch}" >/dev/null 2>&1; then |
| 116 | + echo "::notice::${branch} exists without an open pull request; validating it" |
| 117 | + git fetch origin "${branch}" |
| 118 | +
|
| 119 | + # Fail closed on unexpected content. The branch carries the bot's own one-line |
| 120 | + # bump, so anything else on it means a human or another job is using that name and |
| 121 | + # this job must not push to it or open a pull request from it. |
| 122 | + changed_files="$(git diff --name-only "origin/dev...origin/${branch}")" |
| 123 | + if [ "${changed_files}" != "package.json" ]; then |
| 124 | + echo "::error::${branch} touches unexpected files: ${changed_files:-<none>}" |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | + branch_version="$(git show "origin/${branch}:package.json" | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).version")" |
| 128 | + if [ "${branch_version}" != "${NEXT_VERSION}" ]; then |
| 129 | + echo "::error::${branch} carries ${branch_version}, expected ${NEXT_VERSION}" |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | + git checkout -B "${branch}" "origin/${branch}" |
| 133 | + else |
| 134 | + git config user.name "github-actions[bot]" |
| 135 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 136 | + git checkout -b "${branch}" |
| 137 | + git add package.json |
| 138 | + git commit -m "fix(release): move dev to ${NEXT_VERSION} after ${RELEASED_VERSION}" |
| 139 | + git push origin "${branch}" |
| 140 | + fi |
| 141 | +
|
| 142 | + gh pr create \ |
| 143 | + --base dev \ |
| 144 | + --head "${branch}" \ |
| 145 | + --title "fix(release): move dev to ${NEXT_VERSION} after ${RELEASED_VERSION}" \ |
| 146 | + --body "$(cat <<BODY |
| 147 | + ## Summary |
| 148 | +
|
| 149 | + \`${RELEASED_VERSION}\` published, so \`dev\` would otherwise keep a version at or |
| 150 | + behind a released one and \`tests/release-version-line.test.ts\` would fail on |
| 151 | + \`dev\` and on every pull request opened against it. This moves \`dev\` to |
| 152 | + \`${NEXT_VERSION}\`. |
| 153 | +
|
| 154 | + Opened automatically by \`.github/workflows/dev-version-bump.yml\`. The same |
| 155 | + repair was previously done by hand in 32529c2b2, e4a85d134, 076ad3036, and |
| 156 | + befcac3e1. |
| 157 | +
|
| 158 | + ## Verification |
| 159 | +
|
| 160 | + \`bun test tests/release-version-line.test.ts\` ran against this exact tree |
| 161 | + before the pull request was opened; the workflow refuses to open one if the |
| 162 | + chosen version collides with a published release. |
| 163 | +
|
| 164 | + ## Checklist |
| 165 | +
|
| 166 | + - [x] Scope stays focused and avoids unrelated cleanup. |
| 167 | + - [x] Docs or release notes were updated when needed. |
| 168 | + - [x] Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. |
| 169 | + BODY |
| 170 | + )" |
0 commit comments