From b15d5639e6c51abed657d1dcc5fe26c6c727d736 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 28 Nov 2026 10:21:19 +0100 Subject: [PATCH] feat: sign pin commits and guard draft releases in the pin pr flow --- .github/workflows/release.yml | 5 ++ scripts/release/open-spm-pr.sh | 33 +++++++++++- scripts/release/test-open-spm-pr.sh | 79 +++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ce7c058..aacff4e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -307,6 +307,11 @@ jobs: env: GH_TOKEN: ${{ github.token }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + # Optional SSH private key; when present the pin commit is + # SSH-signed so the default-branch commit-signature ruleset + # accepts it. Without it the pin PR needs a manual signed + # re-author before it can merge. + BOT_SIGNING_KEY: ${{ secrets.BOT_SIGNING_KEY }} run: | # Runs after the release exists: the pin PR body references the # published artifact, and merging before publication would diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index de8276f..8c096d9 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -23,6 +23,9 @@ source "${BASH_SOURCE[0]%/*}/semver.sh" # # Usage: open-spm-pr.sh # 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 +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 diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index e5c7949..32f0a63 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -86,6 +86,12 @@ EOF cat > "${STUBS}/gh" << 'EOF' #!/usr/bin/env bash echo "gh $*" >> "${LOG}" +if [ "$1" = "release" ] && [ "$2" = "view" ]; then + draft="$(cat "${CASE_DIR}/release_is_draft" 2>/dev/null || echo false)" + [ "${draft}" = "fail" ] && exit 1 + printf '%s' "${draft}" + exit 0 +fi if [ "$1" = "api" ]; then # Two-stage fetch: metadata (asset list) then the sums body. Each # stage has its own fail knob value so both closed paths are covered. @@ -196,6 +202,7 @@ set_fixtures() { printf 'tagcommitsha' > "${TMP}/head_commit" printf 'tagcommitsha' > "${TMP}/tag_commit" printf 'false' > "${TMP}/is_shallow" + printf 'false' > "${TMP}/release_is_draft" # Realistic shape: the file header comment also carries a # wallet-bindings-vX.Y.Z literal ahead of the pin line. # shellcheck disable=SC2016 # \n are printf escapes, no expansion @@ -222,10 +229,12 @@ run_case() { local name="$1" expected="$2" repo="${3:-mintlayer/rust-sdk}" local branch="${4:-main}" xcsum="${5:-${XCSUM}}" actual=0 local version="${6:-1.2.3}" tag="${7:-wallet-bindings-v1.2.3}" + local bot_key="${8:-}" : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" \ GITHUB_REPOSITORY="${repo}" \ + BOT_SIGNING_KEY="${bot_key}" \ CASE_DIR="${TMP}" \ bash "${UNDER_TEST}" "${tag}" "${version}" "${xcsum}" "${branch}" \ > "${OUT}" 2>&1 ) || actual=$? @@ -1477,5 +1486,75 @@ else bad "tag regex identical across all ten copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}, gate=${gate}, pin-order=${cpo}" fi +# 78. Draft release -> refuse before any mutation. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'true' > "${TMP}/release_is_draft" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "1" ] && grep -q "is a draft" <<< "$(cat "${OUT}")"; then + ok "draft release refuses the pin pr" +else + bad "draft release refuses the pin pr" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + +# 79. Unreadable release state -> fail closed, no mutations. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'fail' > "${TMP}/release_is_draft" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "1" ] && grep -q "cannot verify the release state" <<< "$(cat "${OUT}")"; then + ok "unreadable release state fails closed" +else + bad "unreadable release state fails closed" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + +# 80. BOT_SIGNING_KEY set -> the pin commit is signed (-S). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'false' > "${TMP}/release_is_draft" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + BOT_SIGNING_KEY="test-key-material" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "0" ] \ + && grep -q "git commit -S -m chore: pin the SPM checksum to wallet-bindings-v1.2.3" <<< "${LOG_CONTENTS}" \ + && grep -q "git config user.signingkey" <<< "${LOG_CONTENTS}"; then + ok "signing key produces a signed commit invocation" +else + bad "signing key produces a signed commit invocation" "exit ${rc}: $(cat "${OUT}")" +fi + +# 81. No BOT_SIGNING_KEY -> plain unsigned commit (unchanged behavior). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "0" ] \ + && grep -q "git commit -m chore: pin the SPM checksum to wallet-bindings-v1.2.3" <<< "${LOG_CONTENTS}" \ + && ! grep -q "git commit -S" <<< "${LOG_CONTENTS}"; then + ok "unsigned fallback unchanged" +else + bad "unsigned fallback unchanged" "exit ${rc}: $(cat "${OUT}")" +fi + echo "passed: ${pass}, failed: ${fail}" [ "${fail}" = "0" ]