Repository navigation
feat: sign pin commits and guard draft releases in the pin pr flow #21
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,9 @@ source "${BASH_SOURCE[0]%/*}/semver.sh" | |||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||
| # Usage: open-spm-pr.sh <TAG> <VERSION> <XCSUM> <DEFAULT_BRANCH> | ||||||||||||||||||||||||||||||||||||
| # Requires: GH_TOKEN, GITHUB_REPOSITORY (provided by Actions). | ||||||||||||||||||||||||||||||||||||
| # Optional: BOT_SIGNING_KEY (SSH private key) — when set, the pin commit | ||||||||||||||||||||||||||||||||||||
| # is SSH-signed so the default-branch commit-signature ruleset accepts | ||||||||||||||||||||||||||||||||||||
| # it; the key material is removed right after the commit. | ||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| TAG="${1:?TAG required}" | ||||||||||||||||||||||||||||||||||||
|
|
@@ -211,7 +214,35 @@ elif [ -n "${origin_pin_tag}" ]; then | |||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
| git commit -m "chore: pin the SPM checksum to ${TAG}" | ||||||||||||||||||||||||||||||||||||
| # The release must be published (not a draft) before pinning: SPM | ||||||||||||||||||||||||||||||||||||
| # resolves the pinned checksum against the release's published assets, | ||||||||||||||||||||||||||||||||||||
| # and the pin-order gate refuses draft releases later with a less | ||||||||||||||||||||||||||||||||||||
| # actionable error. Fail closed when the release state cannot be read. | ||||||||||||||||||||||||||||||||||||
| release_is_draft="$(gh release view "${TAG}" --repo "${GITHUB_REPOSITORY}" \ | ||||||||||||||||||||||||||||||||||||
| --json isDraft --jq '.isDraft' 2>/dev/null)" \ | ||||||||||||||||||||||||||||||||||||
| || { echo "::error::cannot verify the release state for $(esc "${TAG}")"; exit 1; } | ||||||||||||||||||||||||||||||||||||
| if [ "${release_is_draft}" != "false" ]; then | ||||||||||||||||||||||||||||||||||||
| echo "::error::release $(esc "${TAG}") is a draft; publish it (gh release edit $(esc "${TAG}") --draft=false) before opening the pin pr" | ||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Sign the pin commit when a bot signing key is configured (the | ||||||||||||||||||||||||||||||||||||
| # default-branch ruleset requires verified commits; workflow-authored | ||||||||||||||||||||||||||||||||||||
| # commits are unsigned without it). The key is written with owner-only | ||||||||||||||||||||||||||||||||||||
| # permissions, used for exactly this commit, and removed right after. | ||||||||||||||||||||||||||||||||||||
| if [ -n "${BOT_SIGNING_KEY:-}" ]; then | ||||||||||||||||||||||||||||||||||||
| key_file="$(mktemp)" | ||||||||||||||||||||||||||||||||||||
| printf '%s\n' "${BOT_SIGNING_KEY}" > "${key_file}" | ||||||||||||||||||||||||||||||||||||
| chmod 600 "${key_file}" | ||||||||||||||||||||||||||||||||||||
| git config gpg.format ssh | ||||||||||||||||||||||||||||||||||||
| git config user.signingkey "${key_file}" | ||||||||||||||||||||||||||||||||||||
| git commit -S -m "chore: pin the SPM checksum to ${TAG}" | ||||||||||||||||||||||||||||||||||||
| rm -f "${key_file}" | ||||||||||||||||||||||||||||||||||||
| git config --unset gpg.format || true | ||||||||||||||||||||||||||||||||||||
| git config --unset user.signingkey || true | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+234
to
+242
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.
Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||
| git commit -m "chore: pin the SPM checksum to ${TAG}" | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Preflight canary: fail fast when the PR-state lookups are broken | ||||||||||||||||||||||||||||||||||||
| # before anything is mutated. The value itself is discarded (hence the | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
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.
The draft-release gate runs just before the commit, after
git checkout -Bandgit addhave already mutated the local checkout. The remote is untouched (no push/PR create happens before it), so the fail-closed intent holds, but the check reads only from the GitHub API and depends on no local state — hoisting it above the tag-ancestor/HEAD checks (near the other input validations at the top of the script) would make it a pure precondition, fail earlier, and make theassert_no_mutationsguarantee in the test harness structurally obvious rather than incidental.Suggestion: