-
Notifications
You must be signed in to change notification settings - Fork 0
fix(release): make publish protected-branch safe #235
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { pathToFileURL } from 'node:url' | ||
|
|
||
| function parseBoolean(value, name) { | ||
| if (value === 'true') return true | ||
| if (value === 'false') return false | ||
| throw new Error(`${name} must be true or false`) | ||
| } | ||
|
|
||
| export function planReleaseState({ | ||
| published, | ||
| tagTarget, | ||
| head, | ||
| tagPayloadMatches, | ||
| registryPayloadMatches, | ||
| }) { | ||
| if (!head) throw new Error('head is required') | ||
|
|
||
| if (published && !registryPayloadMatches) { | ||
| throw new Error('published package payload or provenance does not match this checkout') | ||
| } | ||
|
|
||
| if (!tagTarget) { | ||
| return { | ||
| state: published ? 'recover-missing-tag' : 'new-release', | ||
| createTag: true, | ||
| publish: !published, | ||
| } | ||
| } | ||
|
|
||
| if (tagTarget === head) { | ||
| return { | ||
| state: published ? 'complete' : 'resume-after-tag', | ||
| createTag: false, | ||
| publish: !published, | ||
| } | ||
| } | ||
|
|
||
| if (published && tagPayloadMatches) { | ||
| return { | ||
| state: 'complete-equivalent-legacy-tag', | ||
| createTag: false, | ||
| publish: false, | ||
| } | ||
| } | ||
|
|
||
| throw new Error(`release tag points to ${tagTarget}, not ${head}`) | ||
| } | ||
|
|
||
| function readArgs(argv) { | ||
| const values = new Map() | ||
| for (let index = 0; index < argv.length; index += 2) { | ||
| const key = argv[index] | ||
| const value = argv[index + 1] | ||
| if (!key?.startsWith('--') || value === undefined) { | ||
| throw new Error(`invalid argument near ${key ?? '<end>'}`) | ||
| } | ||
| values.set(key.slice(2), value) | ||
| } | ||
| return { | ||
| published: parseBoolean(values.get('published'), 'published'), | ||
| tagTarget: values.get('tag-target') ?? '', | ||
| head: values.get('head') ?? '', | ||
| tagPayloadMatches: parseBoolean(values.get('tag-payload-matches'), 'tag-payload-matches'), | ||
| registryPayloadMatches: parseBoolean( | ||
| values.get('registry-payload-matches'), | ||
| 'registry-payload-matches', | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { | ||
| try { | ||
| console.log(JSON.stringify(planReleaseState(readArgs(process.argv.slice(2))))) | ||
| } catch (error) { | ||
| console.error(error instanceof Error ? error.message : String(error)) | ||
| process.exitCode = 1 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| VERSION=${1:?usage: verify-release-payload.sh VERSION [LOCAL_PACKAGE_DIR]} | ||
| LOCAL_PACKAGE_DIR=${2:-$PWD} | ||
| PACKAGE_NAME=@agent-relay/factory | ||
| TMP_DIR=$(mktemp -d) | ||
| trap 'rm -rf "$TMP_DIR"' EXIT | ||
|
|
||
| mkdir "$TMP_DIR/local" "$TMP_DIR/registry" "$TMP_DIR/local-x" "$TMP_DIR/registry-x" | ||
| (cd "$LOCAL_PACKAGE_DIR" && npm pack --pack-destination "$TMP_DIR/local" --silent >/dev/null) | ||
| npm pack "$PACKAGE_NAME@$VERSION" --pack-destination "$TMP_DIR/registry" --silent >/dev/null | ||
| tar -xzf "$TMP_DIR/local"/*.tgz -C "$TMP_DIR/local-x" | ||
| tar -xzf "$TMP_DIR/registry"/*.tgz -C "$TMP_DIR/registry-x" | ||
| diff -qr "$TMP_DIR/local-x/package" "$TMP_DIR/registry-x/package" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Release recovery can accept an npm payload whose executable bits differ from this checkout because Prompt for AI agents |
||
|
|
||
| PROVENANCE=$(npm view "$PACKAGE_NAME@$VERSION" \ | ||
| dist.attestations.provenance.predicateType 2>/dev/null || true) | ||
| if [ "$PROVENANCE" != "https://slsa.dev/provenance/v1" ]; then | ||
| echo "Expected SLSA provenance for $PACKAGE_NAME@$VERSION, got: ${PROVENANCE:-<missing>}" >&2 | ||
| exit 1 | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: A merge to main during the workflow can make this check stale, while the later tag and npm publish still use
$GITHUB_SHA; the job can therefore release a commit that is no longer currentorigin/main. Revalidation immediately before both side effects, together with serialization or an atomic head check, would preserve the canonical-main guarantee.Prompt for AI agents