Repository navigation
feat: sign pin commits and guard draft releases in the pin pr flow - #21
nullPointerEnjoyer wants to merge 1 commit into
Conversation
|
🔍 OpenCodeReview found 8 issue(s) in this PR.
📄
|
| # 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; } |
There was a problem hiding this comment.
The draft-release gate runs just before the commit, after git checkout -B and git add have 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 the assert_no_mutations guarantee in the test harness structurally obvious rather than incidental.
Suggestion:
| # 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; } | |
| # Hoist near the top of the script, before `git checkout -B`: | |
| 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; } |
| 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 |
There was a problem hiding this comment.
With set -euo pipefail, if git commit -S fails (missing/invalid SSH key, signing failure), the script exits immediately without executing rm -f "${key_file}" or the git config --unset calls. The BOT_SIGNING_KEY private key material is then left on disk (world-readable-nameable mktemp path) and user.signingkey keeps pointing at it for any later steps in the same job. Move cleanup into an EXIT trap so it runs on every path, and drop the persisted repo config in favor of one-shot -c options so interrupted runs can't leave a dangling signingkey in the checkout.
Suggestion:
| 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 | |
| key_file="$(mktemp)" | |
| printf '%s\n' "${BOT_SIGNING_KEY}" > "${key_file}" | |
| chmod 600 "${key_file}" | |
| trap 'rm -f "${key_file}"' EXIT | |
| git -c gpg.format=ssh -c user.signingkey="${key_file}" \ | |
| commit -S -m "chore: pin the SPM checksum to ${TAG}" | |
| rm -f "${key_file}" | |
| trap - EXIT |
Root-cause fixes for the two manual-firefight loops this release cycle hit on every tag:
1. Signed pin commits. The workflow-authored pin commit was unsigned, so the default-branch commit-signature ruleset blocked every pin PR (#13/#19 both needed a manual signed re-author).
open-spm-pr.shnow SSH-signs the pin commit whenBOT_SIGNING_KEY(SSH private key) is configured — key written 0600, used for exactly that commit, removed right after; without the secret the behavior is unchanged.release.ymlpasses the optional secret through.Owner action to activate signing (one time): create an SSH keypair, register the public key as a signing key on the repository (or bot account), and add the private key as the
BOT_SIGNING_KEYactions secret. Until then the existing manual rewrite continues to work.2. Draft-release guard. The v0.1.1 tag move flipped the release to draft, and the failure surfaced later as an opaque pin-gate refusal.
open-spm-pr.shnow verifies the release is published before opening the pin PR and fails closed with an actionable message (publish command included), before any mutation.Tests: suite extended 164 → 168 assertions (draft refusal + message, unreadable state fail-closed, signed commit invocation with signing config, unsigned fallback unchanged). actionlint + shellcheck clean.