-
Notifications
You must be signed in to change notification settings - Fork 11
ci(release): scheduled release train auto-merges the Version Packages PR #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c129393
ci(release): scheduled release train auto-merges the Version Packages PR
LukasParke 98c1ca4
Merge branch 'main' into LukasParke/package-release-flow
cortex-github-agent[bot] d42bbc5
fix(release): persist the PAT in publish.yaml checkout so Version PR …
LukasParke e6226af
fix(release): harden the release train against mid-gate holds, PAT ex…
LukasParke b1b00fe
fix(release): fail-closed diff scope, head pin for the gate, tighter …
LukasParke 135b76d
fix(release): fail-closed hold check, merge-failure alert, mid-gate r…
LukasParke d05cb08
fix(release): content-vet package.json diffs, paginate the file list,…
LukasParke 08ece38
fix(release): close file-cap bypass, exclude fork PRs, pin changesets…
LukasParke 09c7c7f
fix(release): atomic vetted-head merge, base-branch pin, alert on eve…
LukasParke 13cbe29
fix(release): vet the immutable SHA via compare API, guard head read,…
LukasParke 8012521
fix(release): restart the overall gate deadline when a re-vetted head…
LukasParke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # verify-version-pr-scope.sh — assert a Version Packages PR contains only | ||
| # mechanical `changeset version` output before an unattended merge. | ||
| # | ||
| # Two layers, both fail-closed: | ||
| # 1. Path allowlist: consumed changesets (.changeset/*.md) and per-package | ||
| # package.json / CHANGELOG.md. No root package.json (private, | ||
| # unversioned), no lockfile (workspace:* deps don't touch it). | ||
| # 2. Content vet for package.json: paths alone are not enough — a smuggled | ||
| # `"postinstall"` script in packages/*/package.json passes a path check, | ||
| # survives `pnpm install --frozen-lockfile` (script-only edits don't | ||
| # desync the lockfile), and executes inside the publish job where the | ||
| # npm OIDC id-token is in scope. So every changed line in a package.json | ||
| # must be a version bump or an internal @openrouter/* dependency range | ||
| # bump — exactly what `changeset version` emits (cf. Version PR #57). | ||
| # | ||
| # File list is paginated via the REST API: `gh pr view --json files` caps at | ||
| # 100 entries and sorts .changeset/ first, so a padded PR could hide an | ||
| # out-of-scope file past the page boundary. | ||
| # | ||
| # Inputs (env): PR, REPO required; GH_TOKEN for gh. | ||
| # Output: "head_sha=<sha>" on stdout (the head this check vetted). | ||
| # Exit: 0 = in scope; 1 = out of scope or the diff could not be read, with | ||
| # offending entries on stderr. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| : "${PR:?PR is required}" | ||
| : "${REPO:?REPO is required}" | ||
|
|
||
| PR_INFO="$(gh pr view "$PR" -R "$REPO" --json headRefOid,baseRefName,changedFiles)" | ||
| HEAD_SHA="$(echo "$PR_INFO" | python3 -c 'import sys,json; print(json.load(sys.stdin)["headRefOid"])')" | ||
| BASE_REF="$(echo "$PR_INFO" | python3 -c 'import sys,json; print(json.load(sys.stdin)["baseRefName"])')" | ||
| DECLARED="$(echo "$PR_INFO" | python3 -c 'import sys,json; print(json.load(sys.stdin)["changedFiles"])')" | ||
|
|
||
| # Vet the diff of the immutable SHA itself (compare API), not "the PR's | ||
| # current files": with the mutable pulls/N/files endpoint, an A→B→A flip-flop | ||
| # timed inside this script could get files from revision B vetted while | ||
| # head_sha reports A. compare/<base>...<sha> is cryptographically bound to | ||
| # HEAD_SHA, so what we vet is exactly what the caller pins and merges | ||
| # (pr-gate.sh passes it to --match-head-commit). | ||
| FILES_NDJSON="$(gh api "repos/${REPO}/compare/${BASE_REF}...${HEAD_SHA}" \ | ||
| --jq '.files[] | {filename, patch}')" | ||
|
|
||
| echo "head_sha=${HEAD_SHA}" | ||
|
|
||
| if [ -z "$FILES_NDJSON" ]; then | ||
| echo "::error::Could not read diff for ${HEAD_SHA:0:7} (empty) — refusing" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # The compare endpoint caps the files array (~300), so a padded PR could hide | ||
| # an out-of-scope path past the cap. Cross-check against the PR's own | ||
| # changed-files count and refuse on any mismatch — covers truncation AND a | ||
| # base that moved enough to skew the diff. (A real Version PR is small; a | ||
| # false refusal here just goes red and re-vets on re-run.) | ||
| ENUMERATED="$(printf '%s\n' "$FILES_NDJSON" | grep -c .)" | ||
| if [ "$ENUMERATED" != "$DECLARED" ]; then | ||
| echo "::error::Diff for ${HEAD_SHA:0:7} enumerated ${ENUMERATED} files but PR declares ${DECLARED} — refusing" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| printf '%s\n' "$FILES_NDJSON" | python3 -c ' | ||
| import json, re, sys | ||
|
|
||
| ALLOW = re.compile(r"^(\.changeset/[^/]+\.md|packages/[^/]+/(package\.json|CHANGELOG\.md))$") | ||
| # The only lines `changeset version` changes in a package.json: the version | ||
| # field, and internal dependency ranges when updateInternalDependencies fires. | ||
| OK_LINE = re.compile( | ||
| r"^[+-]\s*\"(version|@openrouter/[A-Za-z0-9._-]+)\":\s*\"[^\"]*\",?\s*$" | ||
| ) | ||
|
|
||
| bad = [] | ||
| for raw in sys.stdin: | ||
| raw = raw.strip() | ||
| if not raw: | ||
| continue | ||
| f = json.loads(raw) | ||
| name = f["filename"] | ||
| if not ALLOW.match(name): | ||
| bad.append(f"path outside allowlist: {name}") | ||
| continue | ||
| if name.endswith("package.json"): | ||
| patch = f.get("patch") | ||
| if patch is None: | ||
| # No inline patch (file too large / binary flag) — cannot vet. | ||
| bad.append(f"unvettable package.json diff: {name}") | ||
| continue | ||
| for line in patch.splitlines(): | ||
| if line.startswith(("+++", "---")) or not line.startswith(("+", "-")): | ||
| continue | ||
| if not OK_LINE.match(line): | ||
| bad.append(f"non-version change in {name}: {line[:100]}") | ||
| break | ||
|
|
||
| if bad: | ||
| for b in bad: | ||
| print(f"::error::{b}", file=sys.stderr) | ||
| sys.exit(1) | ||
| print("Diff scope OK — only mechanical changeset version output.", file=sys.stderr) | ||
| ' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.