diff --git a/.github/workflows/release-manual.yml b/.github/workflows/release-manual.yml index 182fd1b852..2abfa8b85d 100644 --- a/.github/workflows/release-manual.yml +++ b/.github/workflows/release-manual.yml @@ -7,6 +7,16 @@ on: description: "Version to publish. Blank = auto next patch over npm latest." required: false default: "" + skip_ci_gate: + description: "EMERGENCY ONLY (owner decision 2026-11-01): tick to skip the 'Full CI green at publish sha' gate — publishes right after the local typecheck+build pre-flight. LEAVE UNTICKED for normal releases; a ticked run ships code CI did not verify at this sha and logs a loud warning." + type: boolean + required: false + default: false + raw_publish: + description: "NUCLEAR OPTION (owner decision 2026-11-01): fetches the dependency packages once (plain lockfile download — NOT CI, runs no code), then does ONLY npm run build and npm publish immediately — no typecheck, no tests, no CI lanes, no push to master, no release PR. It publishes, pushes the git tag, creates the GitHub Release, and opens a version-sync PR so master can converge. Implies the skip_ci_gate bypass; both audit warnings are logged. Untick everything for normal releases." + type: boolean + required: false + default: false concurrency: group: one-click-release @@ -15,6 +25,7 @@ concurrency: jobs: release: runs-on: ubuntu-latest + timeout-minutes: 90 permissions: contents: write pull-requests: write @@ -29,6 +40,11 @@ jobs: node-version: 22 registry-url: https://registry.npmjs.org + - name: Resolve the patch lane (retired 2026-10-25 — stub kept so steps.train references stay inert) + id: train + if: false + run: | + echo "train mode is retired: patch lanes publish by merging their final carry PR INTO the protected lane (release-bugfix.yml); see reference/release.md" - name: Resolve version id: version run: | @@ -51,13 +67,44 @@ jobs: echo "version=$V" >> "$GITHUB_OUTPUT" - name: Drift guard + id: driftguard + env: + TRAIN_NAME: ${{ steps.train.outputs.name }} run: | - MASTER_V="$(node -p "require('./package.json').version")" + TREE_V="$(node -p "require('./package.json').version")" NPM_V="$(npm view billion-context version)" - if [ "$MASTER_V" != "$NPM_V" ]; then - echo "::error::master package.json ($MASTER_V) != npm latest ($NPM_V). Sync master with the last published release before one-click releasing." + if [ -z "$NPM_V" ]; then + echo "::error::cannot read the npm latest version of billion-context" exit 1 fi + WHAT="master" + [ -n "$TRAIN_NAME" ] && WHAT="patch train $TRAIN_NAME" + if [ "$TREE_V" != "$NPM_V" ]; then + # Pending-bump state (#5376): an earlier one-click's fallback bump PR merged into + # master while CI was red — master now sits EXACTLY one patch ahead of npm latest, + # with changelog + manifests already staged there. Publishing THAT version is the + # intended release; re-bumping would invent a phantom empty patch. Allowed only when + # (a) tree == nextPatch(npm latest), (b) the resolved target IS the tree version, and + # (c) that version is not already tagged anywhere upstream. + NEXT_P="$(node -p 'const p = process.argv[1].split("-")[0].split("."); p[2] = String(Number(p[2]) + 1); p.join(".")' "$NPM_V")" + if [ "$TREE_V" = "$NEXT_P" ] \ + && [ "${{ steps.version.outputs.version }}" = "$TREE_V" ] \ + && ! git ls-remote --exit-code --tags origin "v$TREE_V" >/dev/null 2>&1; then + echo "::notice::$WHAT package.json ($TREE_V) is one patch ahead of npm latest ($NPM_V) — pending-bump state; publishing $TREE_V straight from master (no new bump commit)." + echo "pending_bump=true" >> "$GITHUB_OUTPUT" + elif [ "${{ inputs.raw_publish }}" = "true" ]; then + # Emergency channel (owner decision 2026-11-01): raw_publish ships the tree + # AS-IS and never pushes master, so a master/npm version skew must NOT block + # a second back-to-back emergency publish (the sync PR from publish #1 is + # still unmerged — that is the whole point of this button). Drift is logged + # loudly; nothing gates on it. Duplicate-publish protection stays in the + # Raw emergency publish step, which refuses an npm version that already exists. + echo "::warning::EMERGENCY CHANNEL: $WHAT package.json ($TREE_V) != npm latest ($NPM_V) — raw_publish ships the current tree anyway and does not touch master. Drift logged, not blocking; converge master via the version-sync PR after the dust settles." + else + echo "::error::$WHAT package.json ($TREE_V) != npm latest ($NPM_V). A release must be cut from the live release: sync the base before releasing." + exit 1 + fi + fi if [ "${{ steps.version.outputs.version }}" = "$NPM_V" ]; then echo "::error::$NPM_V is already published; pick a newer version" exit 1 @@ -91,6 +138,9 @@ jobs: " "$VER" - name: Bump version + # Skipped in pending-bump state: the tree already carries the target + # version plus changelog/manifests (merged fallback bump commit). + if: ${{ steps.driftguard.outputs.pending_bump != 'true' }} run: | node -e ' const fs = require("fs"); @@ -104,15 +154,30 @@ jobs: console.log(`${f}: replaced ${n} occurrence(s)`); } ' "$(node -p "require('./package.json').version")" "${{ steps.version.outputs.version }}" + # #4449: plugin manifests (.agents/.claude-plugin/plugins/codex) carry + # their version from package.json — sync them into the same release + # commit or marketplace update detection sees a stale version. + # Pre-b87732e2 patch lanes (cut from tags older than #4449) have no + # manifests and no script — `git add` fatals on the absent pathspecs + # and the script itself is MODULE_NOT_FOUND, killing train mode on + # exactly the lanes that need it. Existence-guard both. + if [ -f scripts/sync-codex-plugin-version.mjs ]; then + node scripts/sync-codex-plugin-version.mjs + else + echo "::notice::sync-codex-plugin-version.mjs absent on this ref (pre-#4449 patch lane) — skipping manifest sync" + fi - name: Verify bump diff + if: ${{ steps.driftguard.outputs.pending_bump != 'true' }} run: | - git add package.json package-lock.json + for P in package.json package-lock.json .agents .claude-plugin plugins/codex; do + [ -e "$P" ] && git add "$P" + done CHANGED="$(git diff --cached --name-only)" - EXPECT="package-lock.json - package.json" - if [ "$CHANGED" != "$EXPECT" ]; then - echo "::error::bump touched unexpected files: $CHANGED" + [ -n "$CHANGED" ] || { echo "::error::bump produced no changes"; exit 1; } + BAD="$(printf '%s\n' "$CHANGED" | grep -vE '^(package\.json|package-lock\.json|\.agents/plugins/marketplace\.json|\.claude-plugin/marketplace\.json|\.claude-plugin/plugin\.json|plugins/codex/\.codex-plugin/plugin\.json)$' || true)" + if [ -n "$BAD" ]; then + echo "::error::bump touched unexpected files: $BAD" exit 1 fi @@ -124,20 +189,127 @@ jobs: # below (policy 2026-10-10 unchanged); the Full CI gate blocks publish # until they are all green, so coverage is identical — only the # executor moved from this job to the parallel lane matrix. + # raw_publish bypasses this whole gate: its own step below downloads the + # dependencies (lockfile fetch, no code runs) and builds only, + # then publishes (#5430 nuclear option). + if: ${{ inputs.raw_publish != 'true' }} run: | npm ci npm run typecheck npm run build + - name: Raw emergency publish (build only — NO typecheck, NO tests, NO CI, NO master push) + id: rawpub + # #5430 nuclear option (owner decision 2026-11-01): before `npm publish` this + # path does a one-time dependency download (`npm install`, straight from the + # lockfile — it executes no project code, it is not CI) and `npm run build`, + # and NOTHING else. master is never touched by this path; + # it publishes, pushes the git tag, creates the GitHub Release, and opens a + # version-sync PR so master can converge without re-running this path. Every + # downstream step keys off steps.push.outputs.direct / needs_pr, which stay EMPTY + # because the push step is skipped when raw_publish is ticked — so no dispatch, + # no wait, no release PR, no second publish can fire from this job. + if: inputs.raw_publish == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + set -euo pipefail + VER="${{ steps.version.outputs.version }}" + echo "::warning::raw_publish=true EMERGENCY RAW PUBLISH at ${VER}: deps download + npm run build ONLY — no typecheck, no tests, no CI lanes, no push to master. This log line is the permanent audit record of the bypass." + npm install --no-audit --no-fund + npm run build + if [ -n "$(npm view billion-context@${VER} version 2>/dev/null || true)" ]; then + echo "::error::v${VER} already exists on npm — refusing a raw re-publish" + exit 1 + fi + NPMTAG="latest" + PRERELEASE="false" + case "$VER" in *-*) NPMTAG="dev"; PRERELEASE="true";; esac + npm publish --tag "$NPMTAG" --access public + echo "::warning::RAW PUBLISHED v${VER} to npm (tag ${NPMTAG}) with zero typecheck/test/CI coverage. master is NOT updated yet." + # --- convergence bookkeeping (best effort; a failure here never un-publishes) --- + LAST_TAG="$(git describe --match 'v[0-9]*' --tags --abbrev=0 HEAD~1 2>/dev/null || true)" + if [ -n "$LAST_TAG" ]; then + NOTES="$(git log --no-merges --pretty='- %s' "${LAST_TAG}..HEAD~1")" + else + NOTES="(no prior release tag found)" + fi + git tag "v${VER}" && git push origin "v${VER}" \ + || echo "::warning::git tag push failed — patch-lane derivation (bugfix-v* from latest tag) stays on the previous tag until fixed manually" + RELEASE_PAYLOAD="$(mktemp)" + VER="$VER" PRERELEASE="$PRERELEASE" NOTES="$NOTES" node -e ' + const fs = require("fs"); + fs.writeFileSync(process.argv[1], JSON.stringify({ + tag_name: "v" + process.env.VER, name: "v" + process.env.VER, + prerelease: process.env.PRERELEASE === "true", + body: "\u{1F6A8} **RAW EMERGENCY PUBLISH** (one-click \u0060raw_publish\u0060 checkbox, #5430): published straight from the pre-flight build — no typecheck, no tests, no CI lanes ran, and master was not pushed.\n\n## Changes since previous tag\n" + (process.env.NOTES || "(no changes recorded)"), + }));' "$RELEASE_PAYLOAD" + curl -sS -f -X POST -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \ + -H "Content-Type: application/json" -d @"$RELEASE_PAYLOAD" \ + "https://api.github.com/repos/${{ github.repository }}/releases" >/dev/null \ + || echo "::warning::GitHub Release creation failed (the npm publish itself succeeded)" + SYNC_BRANCH="emergency-sync-v${VER}-$(date +%Y%m%d%H%M%S)" + git push -q origin "HEAD:refs/heads/${SYNC_BRANCH}" + PR_PAYLOAD="$(mktemp)" + VER="$VER" SYNC_BRANCH="$SYNC_BRANCH" NOTES="$NOTES" node -e ' + const fs = require("fs"); + fs.writeFileSync(process.argv[1], JSON.stringify({ + title: "chore: sync package.json to v" + process.env.VER + " after emergency raw publish (#5430)", + head: process.env.SYNC_BRANCH, base: "master", + body: "Emergency raw publish put v" + process.env.VER + " on npm WITHOUT touching master (one-click \u0060raw_publish\u0060 checkbox). This tiny PR converges master (version bump + changelog/manifests only) so the next one-click release passes the drift guard. Merging it runs the normal CI lanes like any other PR and triggers NO second publish: release.yml gates on the \u0060*_release-v*\u0060 branch shape plus a \u0060release vX\u0060 commit subject, and this branch/title matches neither.\n\n## What shipped\n" + (process.env.NOTES || "(no changes recorded)"), + }));' "$PR_PAYLOAD" + RESP_FILE="$(mktemp)" + HTTP_CODE=$(curl -sS -o "$RESP_FILE" -w '%{http_code}' -X POST \ + -H "Authorization: Bearer $GH_TOKEN" -H "Content-Type: application/json" \ + -d @"$PR_PAYLOAD" "https://api.github.com/repos/${{ github.repository }}/pulls") + PR_URL=$(node -e 'try{console.log(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).html_url||"")}catch(e){console.log("")}' "$RESP_FILE") + echo "::notice::Version-sync PR for master convergence opened (HTTP ${HTTP_CODE})${PR_URL:+: ${PR_URL}}" + { + echo "### :rotating_light: RAW EMERGENCY PUBLISH v${VER}" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "- Published to npm (tag ${NPMTAG}) straight from the pre-flight build — no typecheck/tests/CI ran" >> "$GITHUB_STEP_SUMMARY" + echo "- Git tag v${VER} pushed; GitHub Release body carries the raw-publish banner" >> "$GITHUB_STEP_SUMMARY" + [ -n "$PR_URL" ] && echo "- Merge this version-sync PR to converge master: ${PR_URL}" >> "$GITHUB_STEP_SUMMARY" + echo "- Until then the next one-click release ABORTS on the drift guard (master behind npm) — by design" >> "$GITHUB_STEP_SUMMARY" + } + echo "done" + - name: Commit and push to master id: push + # Skipped on the raw_publish path: that step already published and pushed + # the tag; leaving direct/needs_pr empty deactivates every downstream + # dispatch/wait/release-PR/publish step in this job. + if: ${{ inputs.raw_publish != 'true' }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TRAIN_NAME: ${{ steps.train.outputs.name }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" VER="${{ steps.version.outputs.version }}" + if [ "${{ steps.driftguard.outputs.pending_bump }}" = "true" ]; then + # Pending-bump: master already IS the publish content (release version, changelog and + # manifests landed via the merged fallback bump PR). Nothing to commit; every + # direct-gated downstream step (Full CI dispatch/gate, tag, publish) applies as-is. + echo "pending-bump: master already carries v$VER — publishing the current master head, no release commit needed." + echo "direct=true" >> "$GITHUB_OUTPUT" + exit 0 + fi git commit -q -m "release v$VER" + if [ -n "$TRAIN_NAME" ]; then + # Train mode: the release commit lands ON THE TRAIN; publishing is + # the carve-out channel (release-bugfix on ship-PR merge), never a + # direct master push. + if ! git push -q origin "HEAD:$TRAIN_NAME"; then + echo "::error::push to train $TRAIN_NAME failed — nothing published, aborting." + exit 1 + fi + echo "train ship commit pushed to $TRAIN_NAME" + echo "needs_pr=true" >> "$GITHUB_OUTPUT" + echo "pr_branch=$TRAIN_NAME" >> "$GITHUB_OUTPUT" + exit 0 + fi if git push -q origin HEAD:master; then echo "pushed release commit to master" echo "direct=true" >> "$GITHUB_OUTPUT" @@ -168,23 +340,33 @@ jobs: # blocks publish until all lanes are green. The script first refuses # to dispatch if master's head is no longer the release commit # (#3539) and cancels stale in-flight runs from this attempt. - if: steps.push.outputs.direct == 'true' + # CI_FULL_DISPATCH: the direct path had the same CORE-default gap the + # fallback path fixed (#3539) — without it ci.yml lands only the CORE + # matrix at the release sha, and a windows+node-24-only regression + # can publish before any CI leg sees it. + if: ${{ steps.push.outputs.direct == 'true' && !inputs.skip_ci_gate }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_RUN_STARTED_AT: ${{ github.run_started_at }} + CI_FULL_DISPATCH: "1" run: | GITHUB_SHA="$(git rev-parse HEAD)" GITHUB_REF_NAME="master" export GITHUB_SHA GITHUB_REF_NAME node scripts/release-ci-gate.mjs --dispatch + - name: Acknowledge CI-gate bypass (emergency checkbox) + if: ${{ inputs.skip_ci_gate && (steps.push.outputs.direct == 'true' || steps.push.outputs.needs_pr == 'true') }} + run: | + echo "::warning::skip_ci_gate=true: publishing WITHOUT waiting for the full CI lanes at this sha. Only the pre-flight typecheck+build ran. This log line is the permanent audit record of the bypass." + - name: Full CI gate (all lanes green at the release commit) # Hard precondition for publish: every required lane green at the # publish sha. Any red lane or timeout ⇒ release fails, nothing is # published. The dispatch step above already refused to fire when # master's head was not this commit (#3539); a later push does not # invalidate runs already landed at it. - if: steps.push.outputs.direct == 'true' + if: ${{ steps.push.outputs.direct == 'true' && !inputs.skip_ci_gate }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_RUN_STARTED_AT: ${{ github.run_started_at }} @@ -196,7 +378,9 @@ jobs: node scripts/release-ci-gate.mjs --wait - name: Dispatch full CI on fallback branch - if: steps.push.outputs.needs_pr == 'true' + # #5430 emergency path: with skip_ci_gate ticked nothing is dispatched or + # awaited — the owner explicitly traded full-lane verification for speed. + if: steps.push.outputs.needs_pr == 'true' && !inputs.skip_ci_gate continue-on-error: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -221,12 +405,92 @@ jobs: export GITHUB_SHA GITHUB_REF_NAME node scripts/release-ci-gate.mjs --dispatch + - name: Reconcile backport-labeled PRs vs the lane (ship-time audit) + # The dual-lane contract: intent to ride the next patch release is + # expressed by the `backport` label (on the source PR) and/or an open + # `backport-carry` PR against this lane. A cherry-pick conflict is + # visible inside its carry PR but easy to overlook at ship time, and + # CI green on the lane head says nothing about ABSENT fixes (#4474). + # This audit cross-checks, at the last human decision point (the ship + # PR), every backport-labeled merge since the lane's base tag against + # the cherry-pick -x trailers on the lane, AND every OPEN carry PR + # targeting this lane, rendering any no-show loudly in the ship PR + # body. It never fails the run: the owner may legitimately ship + # without the straggler — but they must SEE it. + id: reconcile + if: steps.train.outputs.name != '' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TRAIN_NAME: ${{ steps.train.outputs.name }} + run: | + set -euo pipefail + git fetch -q origin master --tags + # HEAD = train + ship commit; HEAD~1 = last pick. The nearest tag + # reachable from there is the tag this train was cut from. + BASE_TAG="$(git describe --match 'v[0-9]*' --tags --abbrev=0 HEAD~1)" + MISSING="" + LABELED=0 + on_train() { # every own-commit of the PR must have a pick trailer + for C in $1; do + if [ -z "$(git log HEAD --grep="cherry picked from commit ${C}" --format=%H)" ]; then + return 1 + fi + done + return 0 + } + audit_pr() { # $1 = PR number, $2 = commit range / single sha + local LABELS + LABELS="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/$1" --jq '[.labels[].name] | join(",")' 2>/dev/null || true)" + case ",$LABELS," in *,backport,*) ;; *) return 0 ;; esac + LABELED=$((LABELED+1)) + if ! on_train "$2"; then + local TITLE + TITLE="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/$1" --jq '.title' 2>/dev/null || echo '?')" + MISSING="${MISSING}- #$1 ${TITLE}"$'\n' + fi + } + # 1) merge-commit merges: "Merge pull request #N from …" — range M^1..M^2 + for M in $(git log --merges --ancestry-path "${BASE_TAG}..origin/master" --format='%H'); do + N="$(git log -1 --format='%s' "$M" | sed -n 's/^Merge pull request #\([0-9]*\) from .*/\1/p')" + [ -z "$N" ] && continue + audit_pr "$N" "$(git rev-list --no-merges "${M}^1..${M}^2")" + done + # 2) squash-shape merges: subject ends in "(#N)" — single sha + while read -r C SUBJECT; do + N="${SUBJECT##*(#}" + N="${N%)}" + case "$N" in ''|*[!0-9]*) continue ;; esac + audit_pr "$N" "$C" + done < <(git log --no-merges "${BASE_TAG}..origin/master" --format='%H %s' | grep -E '\(#[0-9]+\)$' || true) + # 3) open carry PRs against THIS lane — shipped around (unmerged, + # possibly still holding conflicts) = deliberately left behind; + # the human must see it at the last decision point. + while read -r N TITLE; do + [ -z "$N" ] && continue + LABELED=$((LABELED+1)) + MISSING="${MISSING}- PR #$N ${TITLE} (open/unmerged against this lane at ship time)"$'\n' + done < <(gh pr list --repo "$GITHUB_REPOSITORY" --state open --base "$TRAIN_NAME" \ + --json number,title --jq '.[] | [(.number|tostring), .title] | @tsv' 2>/dev/null || true) + echo "labeled=$LABELED" >> "$GITHUB_OUTPUT" + echo "audited ${LABELED} backport-labeled item(s) since ${BASE_TAG} against $TRAIN_NAME" + if [ -n "$MISSING" ]; then + { + echo "missing_md<> "$GITHUB_OUTPUT" + echo "::warning::backport-labeled item(s) missing from $TRAIN_NAME — see the ship PR body" + fi + - name: Open fallback PR (best effort) if: steps.push.outputs.needs_pr == 'true' continue-on-error: true env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_BRANCH: ${{ steps.push.outputs.pr_branch }} + TRAIN_NAME: ${{ steps.train.outputs.name }} + RECONCILE: ${{ steps.reconcile.outputs.missing_md }} + SKIP_GATE: ${{ inputs.skip_ci_gate }} run: | VER="${{ steps.version.outputs.version }}" LINK="https://github.com/${{ github.repository }}/pull/new/${PR_BRANCH}" @@ -238,11 +502,19 @@ jobs: fi PAYLOAD_FILE="$(mktemp)" BODY_FILE="$(mktemp)" - VER="$VER" PR_BRANCH="$PR_BRANCH" LAST_TAG="$LAST_TAG" NOTES="$NOTES" node -e ' + VER="$VER" PR_BRANCH="$PR_BRANCH" LAST_TAG="$LAST_TAG" NOTES="$NOTES" TRAIN_NAME="$TRAIN_NAME" node -e ' const fs = require("fs"); + const intro = process.env.TRAIN_NAME + ? "Ship PR for the patch train (dual-lane release): merging publishes the PRE-MERGE head tree — the base tag plus exactly this train\u2019s fixes, none of master\u2019s unreleased work — via release-bugfix.yml." + : "Auto-fallback from the one-click release workflow: direct push to master was blocked by branch protection. Merging this PR publishes via the standard release.yml flow."; + const skipBanner = process.env.SKIP_GATE === "true" + ? "\u{1F6A8} **EMERGENCY BYPASS ACTIVE**: the one-click run that prepared this PR ticked `skip_ci_gate` — no full-CI lane was dispatched or awaited at this sha. Merging publishes code CI has not verified here; the audit warning lives in that run log.\n\n" + : ""; + const warn = process.env.RECONCILE ? process.env.RECONCILE + "\n" : ""; const body = [ - "Auto-fallback from the one-click release workflow: direct push to master was blocked by branch protection. Merging this PR publishes via the standard release.yml flow.", + skipBanner + intro, "", + warn, "## Changes since " + (process.env.LAST_TAG || "n/a"), "", process.env.NOTES || "(no changes recorded)", @@ -297,7 +569,9 @@ jobs: exit 0 - name: Wait for full CI green on fallback branch (track head) - if: steps.push.outputs.needs_pr == 'true' + # Same guard as the dispatch step above: the emergency checkbox must not + # be silently ignored on the fallback path (v0.1.211 stuck here 2026-11-01). + if: steps.push.outputs.needs_pr == 'true' && !inputs.skip_ci_gate continue-on-error: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}