From b65d4b446b5f098543898276e724b654ba6a9af0 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 12:12:11 +0100 Subject: [PATCH 01/53] ci: open the spm checksum pin as a pull request --- .github/workflows/release.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4ab4d3..7dc9777 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -154,21 +154,24 @@ jobs: Package.swift grep -E "releaseTag|checksum" Package.swift - - name: Push the checksum update to the default branch + - name: Open the SPM checksum-pin PR + env: + GH_TOKEN: ${{ github.token }} run: | + # Branch protection on the default branch rejects direct pushes + # (GH013), so the checksum pin lands via a pull request that a + # maintainer merges to activate SPM resolution for the release. + BRANCH="pin-spm-checksum-${VERSION}" git config user.name "mintlayer-release-bot" git config user.email "hello@mintlayer.org" + git checkout -B "$BRANCH" git add Package.swift - if git diff --cached --quiet; then - echo "Package.swift already pinned to this checksum" - else - git commit -m "chore: pin the SPM checksum to $TAG" - fi - DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" - git fetch origin "$DEFAULT_BRANCH" - # Non-fast-forward = the tag was not cut from the default branch - # tip; that is a release-process error and must fail loudly. - git push origin "HEAD:refs/heads/$DEFAULT_BRANCH" + git commit -m "chore: pin the SPM checksum to $TAG" + git push origin "$BRANCH" + gh pr create \ + --head "$BRANCH" \ + --title "chore: pin the SPM checksum to $TAG" \ + --body "Attaches the released XCFramework checksum to the root Package.swift so SPM resolves the $TAG artifact. Merge to activate." - name: Create the GitHub release env: From c38a09ffef04eed578f2c929390392605a43eda8 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 15:58:09 +0100 Subject: [PATCH 02/53] ci: make the spm checksum pin pr idempotent and spoof-proof --- .github/workflows/lint.yml | 27 ++++++++++++++ .github/workflows/release.yml | 19 ++-------- scripts/release/open-spm-pr.sh | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100755 scripts/release/open-spm-pr.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..44bacaf --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +name: Lint workflows and scripts + +on: + push: + branches: [main] + paths: [".github/workflows/**", "scripts/release/**"] + pull_request: + branches: [main] + paths: [".github/workflows/**", "scripts/release/**"] + +permissions: + contents: read + +jobs: + lint: + name: actionlint + shellcheck + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: shellcheck release scripts + run: shellcheck scripts/release/*.sh + - name: actionlint + run: | + bash <(curl --proto '=https' --tlsv1.2 -fsSL \ + https://raw.githubusercontent.com/rhysd/actionlint/v1.7.7/scripts/download-actionlint.bash) 1.7.7 + ./actionlint -color diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7dc9777..33ea571 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -100,6 +100,7 @@ jobs: timeout-minutes: 15 permissions: contents: write + pull-requests: write env: TAG: ${{ github.ref_name }} VERSION: "" @@ -153,25 +154,13 @@ jobs: -e "s|checksum: \"[0-9a-f]*\"|checksum: \"$xcsum\"|" \ Package.swift grep -E "releaseTag|checksum" Package.swift + echo "XCSUM=$xcsum" >> "$GITHUB_ENV" - name: Open the SPM checksum-pin PR env: GH_TOKEN: ${{ github.token }} - run: | - # Branch protection on the default branch rejects direct pushes - # (GH013), so the checksum pin lands via a pull request that a - # maintainer merges to activate SPM resolution for the release. - BRANCH="pin-spm-checksum-${VERSION}" - git config user.name "mintlayer-release-bot" - git config user.email "hello@mintlayer.org" - git checkout -B "$BRANCH" - git add Package.swift - git commit -m "chore: pin the SPM checksum to $TAG" - git push origin "$BRANCH" - gh pr create \ - --head "$BRANCH" \ - --title "chore: pin the SPM checksum to $TAG" \ - --body "Attaches the released XCFramework checksum to the root Package.swift so SPM resolves the $TAG artifact. Merge to activate." + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: scripts/release/open-spm-pr.sh "$TAG" "$VERSION" "$XCSUM" "$DEFAULT_BRANCH" - name: Create the GitHub release env: diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh new file mode 100755 index 0000000..a5ef5ce --- /dev/null +++ b/scripts/release/open-spm-pr.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Open (or reuse) the SPM checksum-pin pull request for a release tag. +# +# Branch protection on the default branch rejects direct pushes (GH013), +# so the checksum pin lands via a pull request that a maintainer merges +# to activate SPM resolution for the release. Every step is idempotent so +# the workflow can be re-run after a transient failure. +# +# Usage: open-spm-pr.sh +# Requires: GH_TOKEN, GITHUB_REPOSITORY (provided by Actions). +set -euo pipefail + +TAG="${1:?TAG required}" +VERSION="${2:?VERSION required}" +XCSUM="${3:?XCSUM required}" +DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" + +BRANCH="pin-spm-checksum-${VERSION}" + +git config user.name "mintlayer-release-bot" +git config user.email "hello@mintlayer.org" + +# The tag must sit on the default branch's history; otherwise the pin PR +# would carry unrelated commits. Fail loudly before any push. Fetch with +# an explicit refspec so the remote-tracking ref exists regardless of the +# checkout action's fetch configuration. +git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" +if ! git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}"; then + # Workflow-command values need %-/CR-/LF-escaping to stay one annotation. + esc() { printf '%s' "$1" | sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/\n/%0A/g'; } + echo "::error::tag $(esc "${TAG}") is not an ancestor of $(esc "${DEFAULT_BRANCH}"); cut the tag from the default branch tip" + exit 1 +fi + +git checkout -B "${BRANCH}" +git add Package.swift +if git diff --cached --quiet; then + # The tag is an ancestor of the default branch, so an empty diff means + # the pin is already merged; publishing can proceed without a PR. + echo "Package.swift already pinned to this checksum; nothing to do" + exit 0 +fi +git commit -m "chore: pin the SPM checksum to ${TAG}" + +# Only an OPEN pull request from this repository's own branch counts. +# A fork PR with a colliding head-branch name must not suppress the +# genuine bot PR (checksum-spoofing guard). +owner="${GITHUB_REPOSITORY%%/*}" +existing_pr="$(gh pr list --head "${BRANCH}" --state open --json number,headRepositoryOwner \ + --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\")][0].number // empty")" + +# The branch is disposable bot state; force-push keeps re-runs working +# when the remote branch already exists. It happens after the existence +# decision so a spoofed PR never references the bot commit. +git push --force origin "${BRANCH}" + +if [ -n "${existing_pr}" ]; then + echo "checksum-pin PR already exists (#${existing_pr}); updated its head branch" +else + gh pr create \ + --head "${BRANCH}" \ + --title "chore: pin the SPM checksum to ${TAG}" \ + --body "Attaches the released XCFramework checksum to the root Package.swift so SPM resolves the ${TAG} artifact. + +Checksum: \`${XCSUM}\` + +Merge to activate." +fi From 8548ce5fbea35f27502d03cc390ed89f4b00d678 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 16:11:25 +0100 Subject: [PATCH 03/53] ci: verify the pin, checksum the linter, test the script --- .github/workflows/lint.yml | 15 ++- .github/workflows/release.yml | 23 +++-- CHANGELOG.md | 6 +- docs/mobile-bindings.md | 6 +- scripts/release/open-spm-pr.sh | 41 ++++++-- scripts/release/test-open-spm-pr.sh | 153 ++++++++++++++++++++++++++++ 6 files changed, 220 insertions(+), 24 deletions(-) create mode 100755 scripts/release/test-open-spm-pr.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 44bacaf..694e661 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,16 @@ jobs: - name: shellcheck release scripts run: shellcheck scripts/release/*.sh - name: actionlint + env: + # SHA-256 of actionlint_1.7.7_linux_amd64.tar.gz, cross-checked + # against the release's actionlint_1.7.7_checksums.txt. + ACTIONLINT_SHA256: "023070a287cd8cccd71515fedc843f1985bf96c436b7effaecce67290e7e0757" run: | - bash <(curl --proto '=https' --tlsv1.2 -fsSL \ - https://raw.githubusercontent.com/rhysd/actionlint/v1.7.7/scripts/download-actionlint.bash) 1.7.7 - ./actionlint -color + curl --proto '=https' --tlsv1.2 -fsSL -o actionlint.tar.gz \ + https://github.com/rhysd/actionlint/releases/download/v1.7.7/actionlint_1.7.7_linux_amd64.tar.gz + echo "${ACTIONLINT_SHA256} actionlint.tar.gz" | sha256sum --check --strict + tar xzf actionlint.tar.gz actionlint + ./actionlint + rm -f actionlint actionlint.tar.gz + - name: Unit-test the release scripts + run: scripts/release/test-open-spm-pr.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33ea571..bbce28a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,9 @@ name: Release # Cutting a release: bump `version` in bindings/Cargo.toml, commit, then # tag `wallet-bindings-vX.Y.Z` and push the tag. The workflow builds the # Android AAR and the iOS XCFramework from the tagged commit, attaches -# them (with checksums) to a GitHub Release, and pins the SPM checksum in -# the root Package.swift to the released artifact. +# them (with checksums) to a GitHub Release, and opens a checksum-pin PR +# for the root Package.swift (a maintainer merges it to activate SPM +# resolution). on: push: @@ -41,7 +42,9 @@ jobs: add-to-path: false - name: Export NDK environment - run: echo "ANDROID_NDK_HOME=${{ steps.ndk.outputs.ndk-path }}" >> "$GITHUB_ENV" + env: + NDK_PATH: ${{ steps.ndk.outputs.ndk-path }} + run: echo "ANDROID_NDK_HOME=${NDK_PATH}" >> "$GITHUB_ENV" - uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4 with: @@ -109,9 +112,12 @@ jobs: - name: Verify tag matches the crate version run: | - case "$TAG" in - *'&'*|*'|'*|*';'*) echo "::error::tag contains characters unusable in this workflow"; exit 1 ;; - esac + # Positive validation: everything downstream (sed programs, + # commit message, PR title/body) interpolates TAG. + if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v" + exit 1 + fi VERSION="${TAG#wallet-bindings-v}" echo "VERSION=$VERSION" >> "$GITHUB_ENV" declared=$(grep -m1 '^version = ' bindings/Cargo.toml | sed 's/version = "\(.*\)"/\1/') @@ -145,7 +151,7 @@ jobs: - name: Pin the SPM checksum to the released artifact run: | xcsum=$(grep 'MintlayerWalletBindings.xcframework.zip' dist/SHA256SUMS | awk '{print $1}') - if [ ${#xcsum} -ne 64 ] || [ "$xcsum" = "0000000000000000000000000000000000000000000000000000000000000000" ]; then + if [[ ! "$xcsum" =~ ^[0-9a-f]{64}$ ]] || [ "$xcsum" = "0000000000000000000000000000000000000000000000000000000000000000" ]; then echo "::error::refusing to release with an invalid xcframework checksum" exit 1 fi @@ -153,6 +159,9 @@ jobs: -e "s|let releaseTag = \"wallet-bindings-v[^\"]*\"|let releaseTag = \"$TAG\"|" \ -e "s|checksum: \"[0-9a-f]*\"|checksum: \"$xcsum\"|" \ Package.swift + # The substitutions must actually land; a no-op sed on a drifted + # Package.swift must fail the release rather than skip the pin. + grep -F "$xcsum" Package.swift >/dev/null grep -E "releaseTag|checksum" Package.swift echo "XCSUM=$xcsum" >> "$GITHUB_ENV" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c11076..a1d396e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,8 +28,10 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). replay the public BIP39 vectors through the generated Swift bindings. - bindings: release workflow — pushing a `wallet-bindings-v*` tag builds the Android AAR and the iOS XCFramework from the tagged commit, attaches - them with checksums to a GitHub Release, and pins the SPM checksum in - the root `Package.swift` to the released artifact. The generated Kotlin + them with checksums to a GitHub Release, and opens a pull request that + pins the SPM checksum in the root `Package.swift` to the released + artifact (a maintainer merges the pin PR to activate SPM resolution). + The generated Kotlin package is `org.mintlayer.wallet.bindings`; the Swift module is `MintlayerWalletBindings`. - indexer: cursor (keyset) pagination for api-server v2 diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 375ad41..9d51f06 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -171,8 +171,10 @@ Binding releases are tagged `wallet-bindings-vX.Y.Z` (matching the `version` in `bindings/Cargo.toml`). Pushing such a tag triggers the release workflow, which builds the AAR and the XCFramework from the tagged commit, attaches them with a `SHA256SUMS` manifest to the GitHub -release, and pins the SPM checksum in the root `Package.swift` to the -released artifact. Consumers never need a Rust toolchain. +release, and opens a pull request that pins the SPM checksum in the root +`Package.swift` to the released artifact. A maintainer merges that pin +PR to activate SPM resolution for the release. Consumers never need a +Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded in the repository `CHANGELOG.md`. diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index a5ef5ce..6bd211c 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -6,6 +6,9 @@ # to activate SPM resolution for the release. Every step is idempotent so # the workflow can be re-run after a transient failure. # +# The branch namespace "pin-spm-checksum-*" is reserved for this script: +# it force-pushes the branch as disposable bot state on every run. +# # Usage: open-spm-pr.sh # Requires: GH_TOKEN, GITHUB_REPOSITORY (provided by Actions). set -euo pipefail @@ -27,7 +30,13 @@ git config user.email "hello@mintlayer.org" git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" if ! git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}"; then # Workflow-command values need %-/CR-/LF-escaping to stay one annotation. - esc() { printf '%s' "$1" | sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/\n/%0A/g'; } + esc() { + local s="$1" + s="${s//%/%25}" + s="${s//$'\r'/%0D}" + s="${s//$'\n'/%0A}" + printf '%s' "$s" + } echo "::error::tag $(esc "${TAG}") is not an ancestor of $(esc "${DEFAULT_BRANCH}"); cut the tag from the default branch tip" exit 1 fi @@ -35,23 +44,35 @@ fi git checkout -B "${BRANCH}" git add Package.swift if git diff --cached --quiet; then - # The tag is an ancestor of the default branch, so an empty diff means - # the pin is already merged; publishing can proceed without a PR. - echo "Package.swift already pinned to this checksum; nothing to do" - exit 0 + # An empty diff is only success if the pin is genuinely present; an + # unchanged file could equally mean the substitutions no-op'd on a + # drifted Package.swift. Fail closed instead of skipping the pin. + if grep -qF "${XCSUM}" Package.swift && grep -qF "${TAG}" Package.swift; then + echo "Package.swift already pinned to this checksum; nothing to do" + exit 0 + fi + echo "::error::Package.swift did not change and does not carry the expected release tag or checksum" + exit 1 fi git commit -m "chore: pin the SPM checksum to ${TAG}" # Only an OPEN pull request from this repository's own branch counts. -# A fork PR with a colliding head-branch name must not suppress the -# genuine bot PR (checksum-spoofing guard). +# Fork PRs with a colliding head-branch name (same owner via an org repo +# or otherwise) must not suppress the genuine bot PR. The owner name is +# validated before it is interpolated into the jq program; repo names +# cannot contain quotes or backslashes, and this fails closed otherwise. owner="${GITHUB_REPOSITORY%%/*}" -existing_pr="$(gh pr list --head "${BRANCH}" --state open --json number,headRepositoryOwner \ - --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\")][0].number // empty")" +if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then + echo "::error::unexpected repository owner format: ${owner}" + exit 1 +fi +existing_pr="$(gh pr list --head "${BRANCH}" --state open --limit 200 \ + --json number,headRepositoryOwner,isCrossRepository \ + --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false)][0].number // empty")" # The branch is disposable bot state; force-push keeps re-runs working # when the remote branch already exists. It happens after the existence -# decision so a spoofed PR never references the bot commit. +# decision so a spoofed fork PR never references the bot commit. git push --force origin "${BRANCH}" if [ -n "${existing_pr}" ]; then diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh new file mode 100755 index 0000000..92383f7 --- /dev/null +++ b/scripts/release/test-open-spm-pr.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash +# Unit tests for scripts/release/open-spm-pr.sh using stub git/gh on PATH. +# Covers: tag-ancestry guard, empty-diff idempotency (pin present vs +# drifted file), owner/cross-repo PR detection, force-push ordering, and +# the create path. Run by lint.yml and locally before releases. +set -uo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +UNDER_TEST="${SCRIPT_DIR}/open-spm-pr.sh" +TMP="$(mktemp -d)" +STUBS="${TMP}/stubs" +LOG="${TMP}/stub.log" +trap 'rm -rf "${TMP}"' EXIT +mkdir -p "${STUBS}/repo" +export LOG + +pass=0 +fail=0 +ok() { pass=$((pass + 1)); echo "ok - $1"; } +bad() { fail=$((fail + 1)); echo "NOT OK - $1: $2"; } + +# --- stub git/gh ------------------------------------------------------- +# Each stub logs its arguments and returns scripted behavior controlled +# by fixture files in $TMP: +# ancestry=<0|1> git merge-base --is-ancestor result +# staged_diff=<0|1> git diff --cached --quiet result (0 = empty) +# package_swift=file content the checkout writes to Package.swift +# existing_pr= gh pr list output +cat > "${STUBS}/git" << 'EOF' +#!/usr/bin/env bash +echo "git $*" >> "${LOG}" +case "$1 $2" in + "merge-base --is-ancestor") exit "$(cat "${CASE_DIR}/ancestry" 2>/dev/null || echo 1)" ;; + "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; + "checkout -B") + # The script runs git checkout inside the repo dir; copy the fixture + # next to it so `git add Package.swift` / `grep` see controlled data. + cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" + exit 0 ;; +esac +exit 0 +EOF +cat > "${STUBS}/gh" << 'EOF' +#!/usr/bin/env bash +echo "gh $*" >> "${LOG}" +if [ "$1" = "pr" ] && [ "$2" = "list" ]; then + payload="$(cat "${CASE_DIR}/existing_pr" 2>/dev/null || echo "[]")" + prog="" + prev="" + for a in "$@"; do + [ "${prev}" = "--jq" ] && prog="$a" + prev="$a" + done + if [ -n "${prog}" ] && command -v jq >/dev/null 2>&1; then + printf '%s' "${payload}" | jq -r "${prog}" + else + printf '%s' "${payload}" + fi +fi +exit 0 +EOF +chmod +x "${STUBS}/git" "${STUBS}/gh" + +XCSUM="aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97" +PINNED="let releaseTag = \"wallet-bindings-v1.2.3\" // ... +checksum: \"${XCSUM}\"" +DRIFTED="let releaseTag = \"wallet-bindings-v9.9.9\" // ... +checksum: \"deadbeef\"" + +LOG_CONTENTS="" +run_case() { # + local name="$1" expected="$2" actual=0 + ( 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 \ + >/dev/null 2>&1 ) || actual=$? + LOG_CONTENTS="$(cat "${LOG}" 2>/dev/null || true)" + if [ "${actual}" = "${expected}" ]; then ok "${name}"; else bad "${name}" "exit ${actual}, want ${expected}"; fi + : > "${LOG}" +} + +printf '%s' "${PINNED}" > "${TMP}/package_swift.pinned" +printf '%s' "${DRIFTED}" > "${TMP}/package_swift.drifted" +echo '[]' > "${TMP}/existing_pr.empty" +echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false}]' > "${TMP}/existing_pr.own" +echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": true}]' > "${TMP}/existing_pr.fork" + +# 1. Tag not an ancestor of the default branch -> fail loudly. +printf '1' > "${TMP}/ancestry"; printf '1' > "${TMP}/staged_diff" +cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +run_case "non-ancestor tag fails" 1 + +# 2. Ancestor + real diff -> success; push issued before create. +printf '0' > "${TMP}/ancestry"; printf '1' > "${TMP}/staged_diff" +cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +run_case "diff present creates PR" 0 +if grep -q -- "push --force origin pin-spm-checksum-1.2.3" <<< "${LOG_CONTENTS}"; then + ok "force-push issued" +else + bad "force-push issued" "${LOG_CONTENTS}" +fi +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + ok "pr create called" +else + bad "pr create called" "${LOG_CONTENTS}" +fi +push_line="$(grep -n -- '--force' <<< "${LOG_CONTENTS}" | head -1 | cut -d: -f1)" +create_line="$(grep -n 'gh pr create' <<< "${LOG_CONTENTS}" | head -1 | cut -d: -f1)" +if [ -n "${push_line}" ] && [ -n "${create_line}" ] && [ "${push_line}" -lt "${create_line}" ]; then + ok "push precedes create" +else + bad "push precedes create" "${LOG_CONTENTS}" +fi + +# 3. Empty diff + pin genuinely present -> idempotent success, no create. +printf '0' > "${TMP}/ancestry"; printf '0' > "${TMP}/staged_diff" +cp "${TMP}/package_swift.pinned" "${TMP}/package_swift" +run_case "empty diff with pin exits 0" 0 +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + bad "no create when pinned" "${LOG_CONTENTS}" +else + ok "no create when pinned" +fi + +# 4. Empty diff + pin ABSENT (sed no-op'd on drifted file) -> fail closed. +printf '0' > "${TMP}/ancestry"; printf '0' > "${TMP}/staged_diff" +cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +run_case "empty diff without pin fails" 1 + +# 5. Open same-repo PR exists -> detected, no duplicate create. +printf '0' > "${TMP}/ancestry"; printf '1' > "${TMP}/staged_diff" +cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +cp "${TMP}/existing_pr.own" "${TMP}/existing_pr" +run_case "own open PR detected" 0 +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + bad "no duplicate create" "${LOG_CONTENTS}" +else + ok "no duplicate create" +fi + +# 6. Open fork PR with colliding head branch -> ignored, create proceeds. +cp "${TMP}/existing_pr.fork" "${TMP}/existing_pr" +run_case "fork PR ignored, create proceeds" 0 +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + ok "create despite fork PR" +else + bad "create despite fork PR" "${LOG_CONTENTS}" +fi + +echo "passed: ${pass}, failed: ${fail}" +[ "${fail}" = "0" ] From 52623652546f758c171a261a737c550addcf72e0 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 16:21:08 +0100 Subject: [PATCH 04/53] ci: verify both pin substitutions and harden the pr guard --- .github/workflows/release.yml | 21 ++++- scripts/release/open-spm-pr.sh | 66 ++++++++------- scripts/release/test-open-spm-pr.sh | 124 ++++++++++++++++++---------- 3 files changed, 134 insertions(+), 77 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bbce28a..10ca241 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,10 @@ jobs: timeout-minutes: 45 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + # The job never pushes; keep the token off disk so a compromised + # build script cannot read it from .git/config. + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: @@ -77,6 +81,8 @@ jobs: timeout-minutes: 45 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: @@ -109,6 +115,10 @@ jobs: VERSION: "" steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + # The ancestry check in open-spm-pr.sh needs the full graph; a + # shallow clone would reduce it to a tip-equality check. + fetch-depth: 0 - name: Verify tag matches the crate version run: | @@ -122,7 +132,11 @@ jobs: echo "VERSION=$VERSION" >> "$GITHUB_ENV" declared=$(grep -m1 '^version = ' bindings/Cargo.toml | sed 's/version = "\(.*\)"/\1/') if [ "$declared" != "$VERSION" ]; then - echo "::error::tag version ($VERSION) does not match bindings/Cargo.toml version ($declared)" + # Plain log lines, not a workflow annotation: $declared comes + # from the repo at the tag and is not %-escaped here. + echo "::error::tag version does not match bindings/Cargo.toml version" + echo "tag version: ${VERSION}" + echo "crate version: ${declared}" exit 1 fi @@ -141,7 +155,7 @@ jobs: cd dist # The xcframework zip ships its own SHA256SUMS; merge everything # into one manifest covering all release artifacts. - grep -v 'MintlayerWalletBindings.xcframework.zip' SHA256SUMS > /tmp/manifest || true + grep -v 'MintlayerWalletBindings.xcframework.zip' SHA256SUMS > /tmp/manifest sha256sum MintlayerWalletBindings.xcframework.zip >> /tmp/manifest sha256sum mintlayer-wallet-bindings-*.aar >> /tmp/manifest sha256sum swift-sources/MintlayerWalletBindings.swift >> /tmp/manifest @@ -159,9 +173,10 @@ jobs: -e "s|let releaseTag = \"wallet-bindings-v[^\"]*\"|let releaseTag = \"$TAG\"|" \ -e "s|checksum: \"[0-9a-f]*\"|checksum: \"$xcsum\"|" \ Package.swift - # The substitutions must actually land; a no-op sed on a drifted + # Both substitutions must actually land; a no-op sed on a drifted # Package.swift must fail the release rather than skip the pin. grep -F "$xcsum" Package.swift >/dev/null + grep -F "let releaseTag = \"$TAG\"" Package.swift >/dev/null grep -E "releaseTag|checksum" Package.swift echo "XCSUM=$xcsum" >> "$GITHUB_ENV" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 6bd211c..a0a2d7e 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -20,65 +20,73 @@ DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" BRANCH="pin-spm-checksum-${VERSION}" +# Workflow-command values need %-/CR-/LF-escaping to stay one annotation. +esc() { + local s="$1" + s="${s//%/%25}" + s="${s//$'\r'/%0D}" + s="${s//$'\n'/%0A}" + printf '%s' "$s" +} + git config user.name "mintlayer-release-bot" git config user.email "hello@mintlayer.org" +if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then + echo "::error::unexpected default branch format: $(esc "${DEFAULT_BRANCH}")" + exit 1 +fi + # The tag must sit on the default branch's history; otherwise the pin PR # would carry unrelated commits. Fail loudly before any push. Fetch with -# an explicit refspec so the remote-tracking ref exists regardless of the -# checkout action's fetch configuration. -git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" +# an explicit full-history refspec so the ancestry check sees the real +# graph (the release checkout is shallow by default). +git fetch --unshallow origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" 2>/dev/null \ + || git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" if ! git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}"; then - # Workflow-command values need %-/CR-/LF-escaping to stay one annotation. - esc() { - local s="$1" - s="${s//%/%25}" - s="${s//$'\r'/%0D}" - s="${s//$'\n'/%0A}" - printf '%s' "$s" - } echo "::error::tag $(esc "${TAG}") is not an ancestor of $(esc "${DEFAULT_BRANCH}"); cut the tag from the default branch tip" exit 1 fi git checkout -B "${BRANCH}" git add Package.swift -if git diff --cached --quiet; then - # An empty diff is only success if the pin is genuinely present; an - # unchanged file could equally mean the substitutions no-op'd on a - # drifted Package.swift. Fail closed instead of skipping the pin. - if grep -qF "${XCSUM}" Package.swift && grep -qF "${TAG}" Package.swift; then - echo "Package.swift already pinned to this checksum; nothing to do" - exit 0 - fi - echo "::error::Package.swift did not change and does not carry the expected release tag or checksum" +# Both substitutions must be present, on every path: an empty diff with +# the pin present is idempotent success, anything else fails closed. +if ! grep -qF "${XCSUM}" Package.swift \ + || ! grep -qF "let releaseTag = \"${TAG}\"" Package.swift; then + echo "::error::Package.swift does not carry the expected release tag and checksum after substitution" exit 1 fi +if git diff --cached --quiet; then + echo "Package.swift already pinned to this checksum; nothing to do" + exit 0 +fi git commit -m "chore: pin the SPM checksum to ${TAG}" -# Only an OPEN pull request from this repository's own branch counts. -# Fork PRs with a colliding head-branch name (same owner via an org repo -# or otherwise) must not suppress the genuine bot PR. The owner name is -# validated before it is interpolated into the jq program; repo names -# cannot contain quotes or backslashes, and this fails closed otherwise. +# Only an OPEN pull request against the default branch from this +# repository's own branch counts. Fork PRs and same-owner cross-repo PRs +# with a colliding head-branch name must not suppress the genuine bot PR; +# a PR targeting a non-default base must not capture the force-push. The +# owner name is validated before it is interpolated into the jq program. owner="${GITHUB_REPOSITORY%%/*}" if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then - echo "::error::unexpected repository owner format: ${owner}" + echo "::error::unexpected repository owner format: $(esc "${owner}")" exit 1 fi existing_pr="$(gh pr list --head "${BRANCH}" --state open --limit 200 \ - --json number,headRepositoryOwner,isCrossRepository \ - --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false)][0].number // empty")" + --json number,headRepositoryOwner,isCrossRepository,baseRefName \ + --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" # The branch is disposable bot state; force-push keeps re-runs working # when the remote branch already exists. It happens after the existence -# decision so a spoofed fork PR never references the bot commit. +# decision so a spoofed PR never references the bot commit. git push --force origin "${BRANCH}" if [ -n "${existing_pr}" ]; then echo "checksum-pin PR already exists (#${existing_pr}); updated its head branch" else gh pr create \ + --base "${DEFAULT_BRANCH}" \ --head "${BRANCH}" \ --title "chore: pin the SPM checksum to ${TAG}" \ --body "Attaches the released XCFramework checksum to the root Package.swift so SPM resolves the ${TAG} artifact. diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 92383f7..7e2aa0a 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash # Unit tests for scripts/release/open-spm-pr.sh using stub git/gh on PATH. -# Covers: tag-ancestry guard, empty-diff idempotency (pin present vs -# drifted file), owner/cross-repo PR detection, force-push ordering, and -# the create path. Run by lint.yml and locally before releases. +# Covers: tag-ancestry guard, both substitution verifications (pin fully +# present / partially drifted / absent), owner/cross-repo/base-branch PR +# detection, force-push ordering, and owner validation. Run by lint.yml +# and locally before releases. set -uo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -10,10 +11,13 @@ UNDER_TEST="${SCRIPT_DIR}/open-spm-pr.sh" TMP="$(mktemp -d)" STUBS="${TMP}/stubs" LOG="${TMP}/stub.log" +OUT="${TMP}/out.log" trap 'rm -rf "${TMP}"' EXIT mkdir -p "${STUBS}/repo" export LOG +command -v jq >/dev/null 2>&1 || { echo "jq is required by this test harness"; exit 1; } + pass=0 fail=0 ok() { pass=$((pass + 1)); echo "ok - $1"; } @@ -33,8 +37,6 @@ case "$1 $2" in "merge-base --is-ancestor") exit "$(cat "${CASE_DIR}/ancestry" 2>/dev/null || echo 1)" ;; "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "checkout -B") - # The script runs git checkout inside the repo dir; copy the fixture - # next to it so `git add Package.swift` / `grep` see controlled data. cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" exit 0 ;; esac @@ -51,50 +53,59 @@ if [ "$1" = "pr" ] && [ "$2" = "list" ]; then [ "${prev}" = "--jq" ] && prog="$a" prev="$a" done - if [ -n "${prog}" ] && command -v jq >/dev/null 2>&1; then - printf '%s' "${payload}" | jq -r "${prog}" - else - printf '%s' "${payload}" - fi + printf '%s' "${payload}" | jq -r "${prog}" fi exit 0 EOF chmod +x "${STUBS}/git" "${STUBS}/gh" XCSUM="aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97" -PINNED="let releaseTag = \"wallet-bindings-v1.2.3\" // ... -checksum: \"${XCSUM}\"" -DRIFTED="let releaseTag = \"wallet-bindings-v9.9.9\" // ... -checksum: \"deadbeef\"" - -LOG_CONTENTS="" -run_case() { # - local name="$1" expected="$2" actual=0 +FULLY_PINNED='let releaseTag = "wallet-bindings-v1.2.3" // ... +checksum: "'"${XCSUM}"'"' +PARTIAL_DRIFT='let releaseTag = "wallet-bindings-v1.2.2" // ... +checksum: "'"${XCSUM}"'"' +NOT_PINNED='let releaseTag = "wallet-bindings-v9.9.9" // ... +checksum: "deadbeef"' + +# PR fixtures; baseRefName is main unless stated. +echo '[]' > "${TMP}/pr.none" +echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.own" +echo '[{"number": 9, "headRepositoryOwner": {"login": "evil"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.evillow" +echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": true, "baseRefName": "main"}]' > "${TMP}/pr.fork" +echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "develop"}]' > "${TMP}/pr.wrongbase" + +# set_fixtures +set_fixtures() { + printf '%s' "$1" > "${TMP}/ancestry" + printf '%s' "$2" > "${TMP}/staged_diff" + printf '%s' "$3" > "${TMP}/package_swift" + cp "${TMP}/$4" "${TMP}/existing_pr" +} + +# run_case [repository] +run_case() { + local name="$1" expected="$2" repo="${3:-mintlayer/rust-sdk}" actual=0 + : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" \ - GITHUB_REPOSITORY="mintlayer/rust-sdk" \ + GITHUB_REPOSITORY="${repo}" \ CASE_DIR="${TMP}" \ bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ - >/dev/null 2>&1 ) || actual=$? - LOG_CONTENTS="$(cat "${LOG}" 2>/dev/null || true)" - if [ "${actual}" = "${expected}" ]; then ok "${name}"; else bad "${name}" "exit ${actual}, want ${expected}"; fi - : > "${LOG}" + > "${OUT}" 2>&1 ) || actual=$? + LOG_CONTENTS="$(cat "${LOG}")" + if [ "${actual}" = "${expected}" ]; then + ok "${name}" + else + bad "${name}" "exit ${actual}, want ${expected}; output: $(cat "${OUT}")" + fi } -printf '%s' "${PINNED}" > "${TMP}/package_swift.pinned" -printf '%s' "${DRIFTED}" > "${TMP}/package_swift.drifted" -echo '[]' > "${TMP}/existing_pr.empty" -echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false}]' > "${TMP}/existing_pr.own" -echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": true}]' > "${TMP}/existing_pr.fork" - # 1. Tag not an ancestor of the default branch -> fail loudly. -printf '1' > "${TMP}/ancestry"; printf '1' > "${TMP}/staged_diff" -cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +set_fixtures 1 1 "${NOT_PINNED}" pr.none run_case "non-ancestor tag fails" 1 # 2. Ancestor + real diff -> success; push issued before create. -printf '0' > "${TMP}/ancestry"; printf '1' > "${TMP}/staged_diff" -cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "diff present creates PR" 0 if grep -q -- "push --force origin pin-spm-checksum-1.2.3" <<< "${LOG_CONTENTS}"; then ok "force-push issued" @@ -114,9 +125,8 @@ else bad "push precedes create" "${LOG_CONTENTS}" fi -# 3. Empty diff + pin genuinely present -> idempotent success, no create. -printf '0' > "${TMP}/ancestry"; printf '0' > "${TMP}/staged_diff" -cp "${TMP}/package_swift.pinned" "${TMP}/package_swift" +# 3. Empty diff + both substitutions present -> idempotent success. +set_fixtures 0 0 "${FULLY_PINNED}" pr.none run_case "empty diff with pin exits 0" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then bad "no create when pinned" "${LOG_CONTENTS}" @@ -124,15 +134,17 @@ else ok "no create when pinned" fi -# 4. Empty diff + pin ABSENT (sed no-op'd on drifted file) -> fail closed. -printf '0' > "${TMP}/ancestry"; printf '0' > "${TMP}/staged_diff" -cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" +# 4. Empty diff + pin absent -> fail closed. +set_fixtures 0 0 "${NOT_PINNED}" pr.none run_case "empty diff without pin fails" 1 -# 5. Open same-repo PR exists -> detected, no duplicate create. -printf '0' > "${TMP}/ancestry"; printf '1' > "${TMP}/staged_diff" -cp "${TMP}/package_swift.drifted" "${TMP}/package_swift" -cp "${TMP}/existing_pr.own" "${TMP}/existing_pr" +# 5. Partial drift: new checksum but OLD tag -> fail closed (the sed for +# the tag no-op'd; publishing would break the binaryTarget URL). +set_fixtures 0 1 "${PARTIAL_DRIFT}" pr.none +run_case "partial drift (checksum new, tag old) fails" 1 + +# 6. Open same-repo PR against main -> detected, no duplicate create. +set_fixtures 0 1 "${FULLY_PINNED}" pr.own run_case "own open PR detected" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then bad "no duplicate create" "${LOG_CONTENTS}" @@ -140,8 +152,17 @@ else ok "no duplicate create" fi -# 6. Open fork PR with colliding head branch -> ignored, create proceeds. -cp "${TMP}/existing_pr.fork" "${TMP}/existing_pr" +# 7. Open different-owner PR with colliding head branch -> create proceeds. +set_fixtures 0 1 "${FULLY_PINNED}" pr.evillow +run_case "different-owner PR ignored, create proceeds" 0 +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + ok "create despite different-owner PR" +else + bad "create despite different-owner PR" "${LOG_CONTENTS}" +fi + +# 8. Open fork PR with colliding head branch -> create proceeds. +set_fixtures 0 1 "${FULLY_PINNED}" pr.fork run_case "fork PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then ok "create despite fork PR" @@ -149,5 +170,18 @@ else bad "create despite fork PR" "${LOG_CONTENTS}" fi +# 9. Open same-owner PR against a non-default base -> create proceeds. +set_fixtures 0 1 "${FULLY_PINNED}" pr.wrongbase +run_case "wrong-base PR ignored, create proceeds" 0 +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + ok "create despite wrong-base PR" +else + bad "create despite wrong-base PR" "${LOG_CONTENTS}" +fi + +# 10. Malformed repository owner -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +run_case "invalid owner fails" 1 "bad..owner/rust-sdk" + echo "passed: ${pass}, failed: ${fail}" [ "${fail}" = "0" ] From c3600334858b7eb139d7824db673ad6176ee50cc Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 16:35:45 +0100 Subject: [PATCH 05/53] ci: rebuild the manifest and validate inputs in the script --- .github/workflows/lint.yml | 4 +++ .github/workflows/release.yml | 39 +++++++++++++++++++++++------ scripts/release/open-spm-pr.sh | 13 +++++++++- scripts/release/test-open-spm-pr.sh | 29 ++++++++++++++++++--- 4 files changed, 74 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 694e661..0ad4806 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,6 +18,10 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + # The job downloads and runs a third-party binary; keep the + # token off disk like the release build jobs do. + persist-credentials: false - name: shellcheck release scripts run: shellcheck scripts/release/*.sh - name: actionlint diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 10ca241..28390a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,6 +12,12 @@ on: tags: - "wallet-bindings-v*" +# Tag re-pushes and manual re-runs must not interleave: they would race +# the force-pushes to the pin branch and the release-existence check. +concurrency: + group: release-${{ github.ref_name }} + cancel-in-progress: false + permissions: contents: read @@ -27,6 +33,15 @@ jobs: # build script cannot read it from .git/config. persist-credentials: false + - name: Validate tag format + env: + TAG: ${{ github.ref_name }} + run: | + if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v" + exit 1 + fi + - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: targets: aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android @@ -84,6 +99,15 @@ jobs: with: persist-credentials: false + - name: Validate tag format + env: + TAG: ${{ github.ref_name }} + run: | + if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v" + exit 1 + fi + - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: targets: aarch64-apple-ios,aarch64-apple-ios-sim @@ -153,13 +177,14 @@ jobs: - name: Build the checksum manifest run: | cd dist - # The xcframework zip ships its own SHA256SUMS; merge everything - # into one manifest covering all release artifacts. - grep -v 'MintlayerWalletBindings.xcframework.zip' SHA256SUMS > /tmp/manifest - sha256sum MintlayerWalletBindings.xcframework.zip >> /tmp/manifest - sha256sum mintlayer-wallet-bindings-*.aar >> /tmp/manifest - sha256sum swift-sources/MintlayerWalletBindings.swift >> /tmp/manifest - mv /tmp/manifest SHA256SUMS + # Rebuild the manifest from scratch (the xcframework artifact + # ships a zip-only SHA256SUMS) and record the Swift wrapper by + # its bare asset name so `sha256sum -c` works against the + # downloaded release files. + rm -f SHA256SUMS + sha256sum MintlayerWalletBindings.xcframework.zip > SHA256SUMS + sha256sum mintlayer-wallet-bindings-*.aar >> SHA256SUMS + (cd swift-sources && sha256sum MintlayerWalletBindings.swift) >> SHA256SUMS cat SHA256SUMS - name: Pin the SPM checksum to the released artifact diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index a0a2d7e..f48fc5f 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -20,6 +20,17 @@ DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" BRANCH="pin-spm-checksum-${VERSION}" +# Mirror the workflow's validation so direct/manual invocations get the +# same fail-closed guarantees as the release run. +if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v" + exit 1 +fi +if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]]; then + echo "::error::checksum is not 64 lowercase hex characters" + exit 1 +fi + # Workflow-command values need %-/CR-/LF-escaping to stay one annotation. esc() { local s="$1" @@ -73,7 +84,7 @@ if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then echo "::error::unexpected repository owner format: $(esc "${owner}")" exit 1 fi -existing_pr="$(gh pr list --head "${BRANCH}" --state open --limit 200 \ +existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ --json number,headRepositoryOwner,isCrossRepository,baseRefName \ --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 7e2aa0a..dd3a97c 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -82,15 +82,16 @@ set_fixtures() { cp "${TMP}/$4" "${TMP}/existing_pr" } -# run_case [repository] +# run_case [repository] [default_branch] [xcsum] run_case() { - local name="$1" expected="$2" repo="${3:-mintlayer/rust-sdk}" actual=0 + local name="$1" expected="$2" repo="${3:-mintlayer/rust-sdk}" + local branch="${4:-main}" xcsum="${5:-${XCSUM}}" actual=0 : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" \ GITHUB_REPOSITORY="${repo}" \ CASE_DIR="${TMP}" \ - bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${xcsum}" "${branch}" \ > "${OUT}" 2>&1 ) || actual=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${actual}" = "${expected}" ]; then @@ -124,6 +125,12 @@ if [ -n "${push_line}" ] && [ -n "${create_line}" ] && [ "${push_line}" -lt "${c else bad "push precedes create" "${LOG_CONTENTS}" fi +if grep -q -- "--base main" <<< "${LOG_CONTENTS}" \ + && grep -q -- "--head pin-spm-checksum-1.2.3" <<< "${LOG_CONTENTS}"; then + ok "create pins base and head explicitly" +else + bad "create pins base and head explicitly" "${LOG_CONTENTS}" +fi # 3. Empty diff + both substitutions present -> idempotent success. set_fixtures 0 0 "${FULLY_PINNED}" pr.none @@ -143,6 +150,14 @@ run_case "empty diff without pin fails" 1 set_fixtures 0 1 "${PARTIAL_DRIFT}" pr.none run_case "partial drift (checksum new, tag old) fails" 1 +# 5b. Mirror drift: new tag but STALE checksum -> fail closed (the sed +# for the checksum no-op'd; SPM consumers would resolve a stale artifact). +OLD_XCSUM="1111111111111111111111111111111111111111111111111111111111111111" +STALE_CKSUM='let releaseTag = "wallet-bindings-v1.2.3" // ... +checksum: "'"${OLD_XCSUM}"'"' +set_fixtures 0 1 "${STALE_CKSUM}" pr.none +run_case "mirror drift (tag new, checksum stale) fails" 1 + # 6. Open same-repo PR against main -> detected, no duplicate create. set_fixtures 0 1 "${FULLY_PINNED}" pr.own run_case "own open PR detected" 0 @@ -183,5 +198,13 @@ fi set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "invalid owner fails" 1 "bad..owner/rust-sdk" +# 11. Malformed DEFAULT_BRANCH -> fail closed before any fetch. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "invalid default branch fails" 1 "mintlayer/rust-sdk" $'ma\tin' + +# 12. Malformed XCSUM -> fail closed before any fetch. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" + echo "passed: ${pass}, failed: ${fail}" [ "${fail}" = "0" ] From 532a0f1d822bb9903e07e243b8d43d6efe907de0 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 16:47:31 +0100 Subject: [PATCH 06/53] ci: handle merged pins and strip the release job token --- .github/workflows/release.yml | 3 +- scripts/release/open-spm-pr.sh | 77 +++++++++++++++++++---------- scripts/release/test-open-spm-pr.sh | 39 ++++++++++++++- 3 files changed, 89 insertions(+), 30 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 28390a8..a272361 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -229,7 +229,8 @@ jobs: (also in-repo at `SwiftSources/`) Byte-parity with `@mintlayer/wasm-lib` 1.4.0 is verified by the - differential suite on the tagged commit. See + differential suite in CI on the pull request that carried this + release. See `docs/mobile-bindings.md` for usage from Kotlin and Swift. EOF ) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index f48fc5f..3a2e0df 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -4,7 +4,9 @@ # Branch protection on the default branch rejects direct pushes (GH013), # so the checksum pin lands via a pull request that a maintainer merges # to activate SPM resolution for the release. Every step is idempotent so -# the workflow can be re-run after a transient failure. +# the workflow can be re-run after a transient failure: an open pin PR is +# updated, an already-merged pin (identical Package.swift on the default +# branch) short-circuits successfully. # # The branch namespace "pin-spm-checksum-*" is reserved for this script: # it force-pushes the branch as disposable bot state on every run. @@ -20,17 +22,6 @@ DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" BRANCH="pin-spm-checksum-${VERSION}" -# Mirror the workflow's validation so direct/manual invocations get the -# same fail-closed guarantees as the release run. -if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then - echo "::error::tag does not match wallet-bindings-v" - exit 1 -fi -if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]]; then - echo "::error::checksum is not 64 lowercase hex characters" - exit 1 -fi - # Workflow-command values need %-/CR-/LF-escaping to stay one annotation. esc() { local s="$1" @@ -40,13 +31,32 @@ esc() { printf '%s' "$s" } -git config user.name "mintlayer-release-bot" -git config user.email "hello@mintlayer.org" - +# Mirror the workflow's validation so direct/manual invocations get the +# same fail-closed guarantees as the release run. +if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v" + exit 1 +fi +if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::version does not match " + exit 1 +fi +if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]] || [ "${XCSUM//0/}" = "" ]; then + echo "::error::checksum is not 64 lowercase hex characters (all-zero refused)" + exit 1 +fi if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then echo "::error::unexpected default branch format: $(esc "${DEFAULT_BRANCH}")" exit 1 fi +owner="${GITHUB_REPOSITORY%%/*}" +if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then + echo "::error::unexpected repository owner format: $(esc "${owner}")" + exit 1 +fi + +git config user.name "mintlayer-release-bot" +git config user.email "hello@mintlayer.org" # The tag must sit on the default branch's history; otherwise the pin PR # would carry unrelated commits. Fail loudly before any push. Fetch with @@ -59,31 +69,44 @@ if ! git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}"; exit 1 fi +# Manual invocations must run from the tagged commit, or the pin commit +# would be built (and force-pushed) on the wrong base. +tag_commit="$(git rev-parse "refs/tags/${TAG}^{commit}")" +if [ "$(git rev-parse HEAD)" != "${tag_commit}" ]; then + echo "::error::HEAD is not the tagged commit; run from a checkout of ${TAG}" + exit 1 +fi + git checkout -B "${BRANCH}" git add Package.swift -# Both substitutions must be present, on every path: an empty diff with -# the pin present is idempotent success, anything else fails closed. +# Both substitutions must be present, on every path: anything else means +# the sed no-op'd or corrupted the file; fail closed. if ! grep -qF "${XCSUM}" Package.swift \ || ! grep -qF "let releaseTag = \"${TAG}\"" Package.swift; then echo "::error::Package.swift does not carry the expected release tag and checksum after substitution" exit 1 fi +# Empty staged diff = the tag commit itself carries the pin. The tag is +# an ancestor of the default branch, so that pin already shipped; any +# pin PR for it was merged previously. Nothing to open. if git diff --cached --quiet; then - echo "Package.swift already pinned to this checksum; nothing to do" + echo "the tag already carries the pin; nothing to do" + exit 0 +fi +# An identical Package.swift on the default branch means the pin PR was +# already merged; short-circuit instead of attempting a create that +# GitHub would reject with "No commits between". +if git diff --quiet "origin/${DEFAULT_BRANCH}" -- Package.swift; then + echo "checksum pin is already merged into ${DEFAULT_BRANCH}; nothing to do" exit 0 fi git commit -m "chore: pin the SPM checksum to ${TAG}" # Only an OPEN pull request against the default branch from this -# repository's own branch counts. Fork PRs and same-owner cross-repo PRs -# with a colliding head-branch name must not suppress the genuine bot PR; -# a PR targeting a non-default base must not capture the force-push. The -# owner name is validated before it is interpolated into the jq program. -owner="${GITHUB_REPOSITORY%%/*}" -if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then - echo "::error::unexpected repository owner format: $(esc "${owner}")" - exit 1 -fi +# repository's own branch counts. Fork PRs, same-owner cross-repo PRs, +# and PRs targeting a non-default base must not suppress the genuine bot +# PR. The owner name is validated before it is interpolated into the jq +# program; --paginate keeps the check independent of list windows. existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ --json number,headRepositoryOwner,isCrossRepository,baseRefName \ --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index dd3a97c..179526b 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -36,6 +36,7 @@ echo "git $*" >> "${LOG}" case "$1 $2" in "merge-base --is-ancestor") exit "$(cat "${CASE_DIR}/ancestry" 2>/dev/null || echo 1)" ;; "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; + "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "checkout -B") cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" exit 0 ;; @@ -74,12 +75,23 @@ echo '[{"number": 9, "headRepositoryOwner": {"login": "evil"}, "isCrossRepositor echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": true, "baseRefName": "main"}]' > "${TMP}/pr.fork" echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "develop"}]' > "${TMP}/pr.wrongbase" -# set_fixtures +# set_fixtures [default_diff] +# default_diff: 0 = Package.swift identical to the default branch (pin merged). set_fixtures() { printf '%s' "$1" > "${TMP}/ancestry" printf '%s' "$2" > "${TMP}/staged_diff" printf '%s' "$3" > "${TMP}/package_swift" cp "${TMP}/$4" "${TMP}/existing_pr" + printf '%s' "${5:-1}" > "${TMP}/default_diff" +} + +# assert_no_mutations: fail-closed cases must not push or open PRs. +assert_no_mutations() { + if grep -q "git push" <<< "${LOG_CONTENTS}" || grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + bad "no mutations on failure" "${LOG_CONTENTS}" + else + ok "no mutations on failure" + fi } # run_case [repository] [default_branch] [xcsum] @@ -104,6 +116,7 @@ run_case() { # 1. Tag not an ancestor of the default branch -> fail loudly. set_fixtures 1 1 "${NOT_PINNED}" pr.none run_case "non-ancestor tag fails" 1 +assert_no_mutations # 2. Ancestor + real diff -> success; push issued before create. set_fixtures 0 1 "${FULLY_PINNED}" pr.none @@ -133,7 +146,7 @@ else fi # 3. Empty diff + both substitutions present -> idempotent success. -set_fixtures 0 0 "${FULLY_PINNED}" pr.none +set_fixtures 0 0 "${FULLY_PINNED}" pr.none 1 run_case "empty diff with pin exits 0" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then bad "no create when pinned" "${LOG_CONTENTS}" @@ -144,11 +157,13 @@ fi # 4. Empty diff + pin absent -> fail closed. set_fixtures 0 0 "${NOT_PINNED}" pr.none run_case "empty diff without pin fails" 1 +assert_no_mutations # 5. Partial drift: new checksum but OLD tag -> fail closed (the sed for # the tag no-op'd; publishing would break the binaryTarget URL). set_fixtures 0 1 "${PARTIAL_DRIFT}" pr.none run_case "partial drift (checksum new, tag old) fails" 1 +assert_no_mutations # 5b. Mirror drift: new tag but STALE checksum -> fail closed (the sed # for the checksum no-op'd; SPM consumers would resolve a stale artifact). @@ -157,6 +172,12 @@ STALE_CKSUM='let releaseTag = "wallet-bindings-v1.2.3" // ... checksum: "'"${OLD_XCSUM}"'"' set_fixtures 0 1 "${STALE_CKSUM}" pr.none run_case "mirror drift (tag new, checksum stale) fails" 1 +assert_no_mutations + +# 5c. Pin already merged: Package.swift identical to the default branch +# -> short-circuit success even though the checkout diff is non-empty. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none 0 +run_case "already-merged pin exits 0" 0 # 6. Open same-repo PR against main -> detected, no duplicate create. set_fixtures 0 1 "${FULLY_PINNED}" pr.own @@ -197,14 +218,28 @@ fi # 10. Malformed repository owner -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "invalid owner fails" 1 "bad..owner/rust-sdk" +assert_no_mutations # 11. Malformed DEFAULT_BRANCH -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid default branch fails" 1 "mintlayer/rust-sdk" $'ma\tin' +assert_no_mutations # 12. Malformed XCSUM -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" +assert_no_mutations + +# Static check: the TAG regex must be byte-identical in every copy +# (three occurrences in release.yml, one in the script under test). +TAG_REGEX='^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' +wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release.yml" || true)" +sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" +if [ "${wf}" = "3" ] && [ "${sc}" = "1" ]; then + ok "tag regex identical across all four copies" +else + bad "tag regex identical across all four copies" "release.yml=${wf}, script=${sc}" +fi echo "passed: ${pass}, failed: ${fail}" [ "${fail}" = "0" ] From 9e8f00251be648522d4e3080e04f9683ee456eac Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 16:57:16 +0100 Subject: [PATCH 07/53] ci: publish the release before opening the pin pr --- .github/workflows/release.yml | 29 +++++++++++++++-------- docs/mobile-bindings.md | 8 +++---- scripts/release/open-spm-pr.sh | 19 +++++++++++---- scripts/release/test-open-spm-pr.sh | 36 ++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a272361..3bf61a5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -136,13 +136,15 @@ jobs: pull-requests: write env: TAG: ${{ github.ref_name }} - VERSION: "" steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: # The ancestry check in open-spm-pr.sh needs the full graph; a # shallow clone would reduce it to a tip-equality check. fetch-depth: 0 + # Keep the write-scoped token off disk for the whole job; the + # pin-PR step authenticates its push via `gh auth setup-git`. + persist-credentials: false - name: Verify tag matches the crate version run: | @@ -154,7 +156,7 @@ jobs: fi VERSION="${TAG#wallet-bindings-v}" echo "VERSION=$VERSION" >> "$GITHUB_ENV" - declared=$(grep -m1 '^version = ' bindings/Cargo.toml | sed 's/version = "\(.*\)"/\1/') + declared=$(grep -m1 '^version = ' bindings/Cargo.toml | sed 's/version = "\(.*\)"/\1/' | tr -d '[:cntrl:]') if [ "$declared" != "$VERSION" ]; then # Plain log lines, not a workflow annotation: $declared comes # from the repo at the tag and is not %-escaped here. @@ -202,15 +204,11 @@ jobs: # Package.swift must fail the release rather than skip the pin. grep -F "$xcsum" Package.swift >/dev/null grep -F "let releaseTag = \"$TAG\"" Package.swift >/dev/null - grep -E "releaseTag|checksum" Package.swift + # Neutralize a leading '::' so a crafted Package.swift line + # cannot forge workflow annotations in this log. + grep -E "releaseTag|checksum" Package.swift | sed 's/^::/[::/' echo "XCSUM=$xcsum" >> "$GITHUB_ENV" - - name: Open the SPM checksum-pin PR - env: - GH_TOKEN: ${{ github.token }} - DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} - run: scripts/release/open-spm-pr.sh "$TAG" "$VERSION" "$XCSUM" "$DEFAULT_BRANCH" - - name: Create the GitHub release env: GH_TOKEN: ${{ github.token }} @@ -245,3 +243,16 @@ jobs: dist/swift-sources/MintlayerWalletBindings.swift \ --title "Mobile bindings $TAG" \ --notes "$notes" + + - name: Open the SPM checksum-pin PR + env: + GH_TOKEN: ${{ github.token }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: | + # Runs after the release exists: the pin PR body references the + # published artifact, and merging before publication would + # point SPM at a nonexistent release. + # The checkout no longer persists a token; give git a credential + # helper backed by GH_TOKEN for the script's force-push. + gh auth setup-git + scripts/release/open-spm-pr.sh "$TAG" "$VERSION" "$XCSUM" "$DEFAULT_BRANCH" diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 9d51f06..5cb1b51 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -171,10 +171,10 @@ Binding releases are tagged `wallet-bindings-vX.Y.Z` (matching the `version` in `bindings/Cargo.toml`). Pushing such a tag triggers the release workflow, which builds the AAR and the XCFramework from the tagged commit, attaches them with a `SHA256SUMS` manifest to the GitHub -release, and opens a pull request that pins the SPM checksum in the root -`Package.swift` to the released artifact. A maintainer merges that pin -PR to activate SPM resolution for the release. Consumers never need a -Rust toolchain. +release, and then opens a pull request that pins the SPM checksum in the +root `Package.swift` to the released artifact. The release exists before +the pin PR is opened; a maintainer merges that pin PR to activate SPM +resolution for the release. Consumers never need a Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded in the repository `CHANGELOG.md`. diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 3a2e0df..991f708 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -49,6 +49,12 @@ if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then echo "::error::unexpected default branch format: $(esc "${DEFAULT_BRANCH}")" exit 1 fi +# The default branch must never live in the reserved bot namespace: a +# force-push there would rewind main instead of a disposable branch. +if [[ "${DEFAULT_BRANCH}" == "${BRANCH}" || "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then + echo "::error::default branch must not use the reserved pin-spm-checksum-* namespace" + exit 1 +fi owner="${GITHUB_REPOSITORY%%/*}" if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then echo "::error::unexpected repository owner format: $(esc "${owner}")" @@ -59,11 +65,13 @@ git config user.name "mintlayer-release-bot" git config user.email "hello@mintlayer.org" # The tag must sit on the default branch's history; otherwise the pin PR -# would carry unrelated commits. Fail loudly before any push. Fetch with -# an explicit full-history refspec so the ancestry check sees the real -# graph (the release checkout is shallow by default). -git fetch --unshallow origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" 2>/dev/null \ - || git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" +# would carry unrelated commits. Fail loudly before any push. Unshallow +# only when needed, and keep stderr visible for genuine fetch failures. +if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then + git fetch --unshallow origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" +else + git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" +fi if ! git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}"; then echo "::error::tag $(esc "${TAG}") is not an ancestor of $(esc "${DEFAULT_BRANCH}"); cut the tag from the default branch tip" exit 1 @@ -127,5 +135,6 @@ else Checksum: \`${XCSUM}\` +The GitHub release for this tag is published before this PR is opened. Merge to activate." fi diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 179526b..89fd364 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -37,6 +37,9 @@ case "$1 $2" in "merge-base --is-ancestor") exit "$(cat "${CASE_DIR}/ancestry" 2>/dev/null || echo 1)" ;; "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; + "rev-parse --is-shallow-repository") echo "false" ;; + "rev-parse HEAD") echo "git $*" >> "${LOG}"; cat "${CASE_DIR}/head_commit" ;; + rev-parse\ refs/tags/*) cat "${CASE_DIR}/tag_commit" ;; "checkout -B") cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" exit 0 ;; @@ -83,6 +86,8 @@ set_fixtures() { printf '%s' "$3" > "${TMP}/package_swift" cp "${TMP}/$4" "${TMP}/existing_pr" printf '%s' "${5:-1}" > "${TMP}/default_diff" + printf 'tagcommitsha' > "${TMP}/head_commit" + printf 'tagcommitsha' > "${TMP}/tag_commit" } # assert_no_mutations: fail-closed cases must not push or open PRs. @@ -95,15 +100,17 @@ assert_no_mutations() { } # run_case [repository] [default_branch] [xcsum] +# [version] [tag] 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}" : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" \ GITHUB_REPOSITORY="${repo}" \ CASE_DIR="${TMP}" \ - bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${xcsum}" "${branch}" \ + bash "${UNDER_TEST}" "${tag}" "${version}" "${xcsum}" "${branch}" \ > "${OUT}" 2>&1 ) || actual=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${actual}" = "${expected}" ]; then @@ -153,6 +160,7 @@ if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then else ok "no create when pinned" fi +assert_no_mutations # 4. Empty diff + pin absent -> fail closed. set_fixtures 0 0 "${NOT_PINNED}" pr.none @@ -178,6 +186,7 @@ assert_no_mutations # -> short-circuit success even though the checkout diff is non-empty. set_fixtures 0 1 "${FULLY_PINNED}" pr.none 0 run_case "already-merged pin exits 0" 0 +assert_no_mutations # 6. Open same-repo PR against main -> detected, no duplicate create. set_fixtures 0 1 "${FULLY_PINNED}" pr.own @@ -228,6 +237,31 @@ assert_no_mutations # 12. Malformed XCSUM -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" + +# 13. HEAD is not the tagged commit -> fail closed, no push. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'othercommitsha' > "${TMP}/head_commit" +run_case "HEAD differs from tag fails" 1 +printf 'tagcommitsha' > "${TMP}/head_commit" + +# 14. All-zero checksum -> fail closed before any fetch. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "all-zero checksum fails" 1 "mintlayer/rust-sdk" main \ + "0000000000000000000000000000000000000000000000000000000000000000" + +# 15. VERSION that is not semver -> fail closed before any fetch. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "invalid version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 + +# 16. TAG not matching the release pattern -> fail closed before fetch. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "invalid tag (no patch) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 "wallet-bindings-v1.2" +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "invalid tag (wrong prefix) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2.3 "evil-wallet-bindings-v1.2.3" + +# 17. Default branch inside the reserved namespace -> fail closed. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "reserved-namespace default branch fails" 1 "mintlayer/rust-sdk" "pin-spm-checksum-1.2.3" assert_no_mutations # Static check: the TAG regex must be byte-identical in every copy From f3150d9c7555ddc555d27f3c8d7d20beab1615d9 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 17:06:31 +0100 Subject: [PATCH 08/53] ci: guard the rewind path and lint every repo script --- .github/workflows/lint.yml | 4 +-- scripts/release/open-spm-pr.sh | 16 +++++++++- scripts/release/test-open-spm-pr.sh | 46 +++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0ad4806..f972955 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,8 +22,8 @@ jobs: # The job downloads and runs a third-party binary; keep the # token off disk like the release build jobs do. persist-credentials: false - - name: shellcheck release scripts - run: shellcheck scripts/release/*.sh + - name: shellcheck repo scripts + run: shellcheck $(git ls-files 'scripts/*.sh') - name: actionlint env: # SHA-256 of actionlint_1.7.7_linux_amd64.tar.gz, cross-checked diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 991f708..3c7e3be 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -51,7 +51,7 @@ if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then fi # The default branch must never live in the reserved bot namespace: a # force-push there would rewind main instead of a disposable branch. -if [[ "${DEFAULT_BRANCH}" == "${BRANCH}" || "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then +if [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then echo "::error::default branch must not use the reserved pin-spm-checksum-* namespace" exit 1 fi @@ -108,6 +108,20 @@ if git diff --quiet "origin/${DEFAULT_BRANCH}" -- Package.swift; then echo "checksum pin is already merged into ${DEFAULT_BRANCH}; nothing to do" exit 0 fi +# If the default branch carries an ACTIVE pin for a different release +# (non-placeholder checksum, different tag), creating this PR would +# rewind that pin; only the newest release may pin. Fail closed on +# manual invocations for stale tags. +origin_pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ + | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ + | grep -oE 'v[0-9][^"]*' || true)" +origin_pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ + | grep -oE 'checksum: "[0-9a-f]{64}"' | grep -oE '[0-9a-f]{64}' || true)" +if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ] \ + && [ -n "${origin_pin_tag}" ] && [ "${origin_pin_tag}" != "v${VERSION}" ]; then + echo "::error::origin/${DEFAULT_BRANCH} already pins ${origin_pin_tag}; this script may only pin the newest release" + exit 1 +fi git commit -m "chore: pin the SPM checksum to ${TAG}" # Only an OPEN pull request against the default branch from this diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 89fd364..431e01d 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1,9 +1,12 @@ #!/usr/bin/env bash # Unit tests for scripts/release/open-spm-pr.sh using stub git/gh on PATH. -# Covers: tag-ancestry guard, both substitution verifications (pin fully -# present / partially drifted / absent), owner/cross-repo/base-branch PR -# detection, force-push ordering, and owner validation. Run by lint.yml -# and locally before releases. +# Covers: tag-ancestry guard (shallow-aware fetch both ways), HEAD==tag +# guard, both substitution verifications (pin fully present / either half +# drifted / absent), already-merged and pre-pinned short-circuits, +# owner/cross-repo/base-branch/rewind PR detection, force-push ordering +# and its absence on failure paths, owner/branch/checksum/tag validation, +# and the byte-identical TAG regex across all copies. Run by lint.yml and +# locally before releases. set -uo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -37,8 +40,9 @@ case "$1 $2" in "merge-base --is-ancestor") exit "$(cat "${CASE_DIR}/ancestry" 2>/dev/null || echo 1)" ;; "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; - "rev-parse --is-shallow-repository") echo "false" ;; - "rev-parse HEAD") echo "git $*" >> "${LOG}"; cat "${CASE_DIR}/head_commit" ;; + "rev-parse --is-shallow-repository") cat "${CASE_DIR}/is_shallow" ;; + "rev-parse HEAD") cat "${CASE_DIR}/head_commit" ;; + "show origin/"*) cat "${CASE_DIR}/origin_swift" ;; rev-parse\ refs/tags/*) cat "${CASE_DIR}/tag_commit" ;; "checkout -B") cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" @@ -88,6 +92,8 @@ set_fixtures() { printf '%s' "${5:-1}" > "${TMP}/default_diff" printf 'tagcommitsha' > "${TMP}/head_commit" printf 'tagcommitsha' > "${TMP}/tag_commit" + printf 'false' > "${TMP}/is_shallow" + printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" } # assert_no_mutations: fail-closed cases must not push or open PRs. @@ -264,6 +270,34 @@ set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "reserved-namespace default branch fails" 1 "mintlayer/rust-sdk" "pin-spm-checksum-1.2.3" assert_no_mutations +# 18. Shallow clone -> the unshallow fetch is used. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'true' > "${TMP}/is_shallow" +run_case "shallow clone unshallows" 0 +if grep -q -- "fetch --unshallow origin" <<< "${LOG_CONTENTS}"; then + ok "unshallow fetch issued" +else + bad "unshallow fetch issued" "${LOG_CONTENTS}" +fi +printf 'false' > "${TMP}/is_shallow" + +# 19. Complete clone -> plain fetch with the explicit full refspec. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +run_case "complete clone plain fetch" 0 +if grep -q -- "fetch origin +refs/heads/main:refs/remotes/origin/main" <<< "${LOG_CONTENTS}"; then + ok "plain fetch carries the full refspec" +else + bad "plain fetch carries the full refspec" "${LOG_CONTENTS}" +fi + +# 20. Default branch already pins a DIFFERENT release -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +run_case "stale tag against a newer pin fails" 1 +assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +assert_no_mutations + # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). TAG_REGEX='^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' From c00bebf6b176736fc228fa3757d208c5c37f77e9 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 17:20:29 +0100 Subject: [PATCH 09/53] ci: semver the rewind guard and make releases re-runnable --- .github/workflows/lint.yml | 4 +-- .github/workflows/release.yml | 25 +++++++++----- docs/mobile-bindings.md | 5 ++- scripts/release/open-spm-pr.sh | 51 ++++++++++++++++++++--------- scripts/release/test-open-spm-pr.sh | 30 ++++++++++++----- 5 files changed, 78 insertions(+), 37 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f972955..00d7559 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,10 +3,10 @@ name: Lint workflows and scripts on: push: branches: [main] - paths: [".github/workflows/**", "scripts/release/**"] + paths: [".github/workflows/**", "scripts/**"] pull_request: branches: [main] - paths: [".github/workflows/**", "scripts/release/**"] + paths: [".github/workflows/**", "scripts/**"] permissions: contents: read diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3bf61a5..7f49109 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -232,17 +232,24 @@ jobs: `docs/mobile-bindings.md` for usage from Kotlin and Swift. EOF ) + # Idempotent for re-runs after a transient pin-PR failure: an + # existing release is reused and its assets refreshed in place. if gh release view "$TAG" >/dev/null 2>&1; then - echo "::error::release $TAG already exists; delete it or cut a new version" - exit 1 + echo "release $TAG already exists; refreshing assets" + gh release upload "$TAG" --clobber \ + dist/mintlayer-wallet-bindings-*.aar \ + dist/MintlayerWalletBindings.xcframework.zip \ + dist/SHA256SUMS \ + dist/swift-sources/MintlayerWalletBindings.swift + else + gh release create "$TAG" \ + dist/mintlayer-wallet-bindings-*.aar \ + dist/MintlayerWalletBindings.xcframework.zip \ + dist/SHA256SUMS \ + dist/swift-sources/MintlayerWalletBindings.swift \ + --title "Mobile bindings $TAG" \ + --notes "$notes" fi - gh release create "$TAG" \ - dist/mintlayer-wallet-bindings-*.aar \ - dist/MintlayerWalletBindings.xcframework.zip \ - dist/SHA256SUMS \ - dist/swift-sources/MintlayerWalletBindings.swift \ - --title "Mobile bindings $TAG" \ - --notes "$notes" - name: Open the SPM checksum-pin PR env: diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 5cb1b51..10b991d 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -25,9 +25,8 @@ against captured reference outputs of `@mintlayer/wasm-lib` 1.4.0 (see | Android 6.0+ (API 24) | `mintlayer-wallet-bindings-.aar` | `arm64-v8a`, `armeabi-v7a`, `x86_64` | | iOS 15+ | `MintlayerWalletBindings.xcframework` | `ios-arm64` (device), `ios-arm64_x86_64-simulator` | -The Intel simulator slice (`x86_64-apple-ios-sim`) is omitted: recent Xcode -releases no longer ship Intel simulator runtimes, and Rust 1.92 does not -publish that target's standard library. +The Intel simulator slice (`x86_64-apple-ios-sim`) is omitted: recent +Xcode releases no longer ship Intel simulator runtimes. ## API surface diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 3c7e3be..9f02c45 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -64,6 +64,12 @@ fi git config user.name "mintlayer-release-bot" git config user.email "hello@mintlayer.org" +# The remaining git/grep logic assumes the repository root. +if [ ! -d .git ] || [ ! -f Package.swift ]; then + echo "::error::run this script from the repository root" + exit 1 +fi + # The tag must sit on the default branch's history; otherwise the pin PR # would carry unrelated commits. Fail loudly before any push. Unshallow # only when needed, and keep stderr visible for genuine fetch failures. @@ -72,7 +78,13 @@ if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then else git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" fi -if ! git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}"; then +merge_rc=0 +git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}" || merge_rc=$? +if [ "${merge_rc}" -gt 1 ]; then + echo "::error::failed to compare ${TAG} against origin/${DEFAULT_BRANCH} (git exit ${merge_rc}); check the fetch and the tag" + exit 1 +fi +if [ "${merge_rc}" -eq 1 ]; then echo "::error::tag $(esc "${TAG}") is not an ancestor of $(esc "${DEFAULT_BRANCH}"); cut the tag from the default branch tip" exit 1 fi @@ -94,13 +106,6 @@ if ! grep -qF "${XCSUM}" Package.swift \ echo "::error::Package.swift does not carry the expected release tag and checksum after substitution" exit 1 fi -# Empty staged diff = the tag commit itself carries the pin. The tag is -# an ancestor of the default branch, so that pin already shipped; any -# pin PR for it was merged previously. Nothing to open. -if git diff --cached --quiet; then - echo "the tag already carries the pin; nothing to do" - exit 0 -fi # An identical Package.swift on the default branch means the pin PR was # already merged; short-circuit instead of attempting a create that # GitHub would reject with "No commits between". @@ -108,19 +113,35 @@ if git diff --quiet "origin/${DEFAULT_BRANCH}" -- Package.swift; then echo "checksum pin is already merged into ${DEFAULT_BRANCH}; nothing to do" exit 0 fi -# If the default branch carries an ACTIVE pin for a different release -# (non-placeholder checksum, different tag), creating this PR would -# rewind that pin; only the newest release may pin. Fail closed on -# manual invocations for stale tags. +# Empty staged diff = the tag commit itself carries the pin. That is +# only benign when the default branch agrees (handled above); if the +# default branch differs, the pin on main was reverted and the release +# is effectively unpinned. Fail closed rather than claim success. +if git diff --cached --quiet; then + echo "::error::the tag commit carries the pin but origin/${DEFAULT_BRANCH} does not; the pin was reverted on the default branch and needs manual repair" + exit 1 +fi +# The default branch carrying an ACTIVE pin for a NEWER-or-equal +# release means this invocation would rewind that pin; refuse. Older +# active pins are the normal forward-release state and proceed. origin_pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ | grep -oE 'v[0-9][^"]*' || true)" origin_pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ | grep -oE 'checksum: "[0-9a-f]{64}"' | grep -oE '[0-9a-f]{64}' || true)" if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ] \ - && [ -n "${origin_pin_tag}" ] && [ "${origin_pin_tag}" != "v${VERSION}" ]; then - echo "::error::origin/${DEFAULT_BRANCH} already pins ${origin_pin_tag}; this script may only pin the newest release" - exit 1 + && [ -n "${origin_pin_tag}" ]; then + origin_version="${origin_pin_tag#v}" + if [[ ! "${origin_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" + exit 1 + fi + # sort -V: the first line is the smaller version. If the incoming + # VERSION sorts first, the origin pin is newer-or-equal -> rewind. + if [ "$(printf '%s\n%s\n' "${origin_version}" "${VERSION}" | sort -V | head -1)" = "${VERSION}" ]; then + echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" + exit 1 + fi fi git commit -m "chore: pin the SPM checksum to ${TAG}" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 431e01d..a73886f 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -16,7 +16,8 @@ STUBS="${TMP}/stubs" LOG="${TMP}/stub.log" OUT="${TMP}/out.log" trap 'rm -rf "${TMP}"' EXIT -mkdir -p "${STUBS}/repo" +mkdir -p "${STUBS}/repo/.git" +printf 'placeholder\n' > "${STUBS}/repo/Package.swift" export LOG command -v jq >/dev/null 2>&1 || { echo "jq is required by this test harness"; exit 1; } @@ -158,14 +159,10 @@ else bad "create pins base and head explicitly" "${LOG_CONTENTS}" fi -# 3. Empty diff + both substitutions present -> idempotent success. +# 3. Empty diff + pin present but main DIFFERS -> the pin on main was +# reverted; fail closed instead of claiming success. set_fixtures 0 0 "${FULLY_PINNED}" pr.none 1 -run_case "empty diff with pin exits 0" 0 -if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then - bad "no create when pinned" "${LOG_CONTENTS}" -else - ok "no create when pinned" -fi +run_case "empty diff with reverted main fails" 1 assert_no_mutations # 4. Empty diff + pin absent -> fail closed. @@ -248,6 +245,7 @@ run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'othercommitsha' > "${TMP}/head_commit" run_case "HEAD differs from tag fails" 1 +assert_no_mutations printf 'tagcommitsha' > "${TMP}/head_commit" # 14. All-zero checksum -> fail closed before any fetch. @@ -295,8 +293,24 @@ set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "stale tag against a newer pin fails" 1 assert_no_mutations + +# 21. Forward release over an OLDER active pin -> allowed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +run_case "forward release over older pin proceeds" 0 +if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then + ok "create proceeds over older pin" +else + bad "create proceeds over older pin" "${LOG_CONTENTS}" +fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 22. Same-version active pin with differing content -> rewind guard. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +run_case "same-version conflicting pin fails" 1 assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). From b9c3a2e51158cb7a23ec1f487640bd648c346411 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 17:29:37 +0100 Subject: [PATCH 10/53] ci: serialize releases and harden one-sided pin states --- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 7 +++--- CHANGELOG.md | 6 ++++- docs/mobile-bindings.md | 2 +- scripts/release/open-spm-pr.sh | 34 ++++++++++++++++++++----- scripts/release/test-open-spm-pr.sh | 39 ++++++++++++++++++++++++++++- 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 00d7559..e4b926e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,7 +23,7 @@ jobs: # token off disk like the release build jobs do. persist-credentials: false - name: shellcheck repo scripts - run: shellcheck $(git ls-files 'scripts/*.sh') + run: git ls-files -z 'scripts/*.sh' | xargs -0 shellcheck - name: actionlint env: # SHA-256 of actionlint_1.7.7_linux_amd64.tar.gz, cross-checked diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f49109..7731fd4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,10 +12,11 @@ on: tags: - "wallet-bindings-v*" -# Tag re-pushes and manual re-runs must not interleave: they would race -# the force-pushes to the pin branch and the release-existence check. +# Releases are fully serialized: two tags cut near-simultaneously would +# race the pin PRs (the rewind guard runs at PR-creation time, so merge +# order would decide which pin wins). One group queues every release. concurrency: - group: release-${{ github.ref_name }} + group: release-${{ github.repository }} cancel-in-progress: false permissions: diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d396e..c0b6865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,11 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). artifact (a maintainer merges the pin PR to activate SPM resolution). The generated Kotlin package is `org.mintlayer.wallet.bindings`; the Swift module is - `MintlayerWalletBindings`. + `MintlayerWalletBindings`. The workflow publishes the release before + opening a checksum-pin PR for `Package.swift` (a maintainer merges it + to activate SPM resolution), and a `lint.yml` gate runs actionlint and + shellcheck (plus unit tests for `scripts/release/`) on workflow and + script changes. - indexer: cursor (keyset) pagination for api-server v2 (mintlayer-core PR #2130): `Page`, the reusable `Pager` walker (`*_pager` constructors for pools, the global transaction listing, both diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 10b991d..59de80d 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -22,7 +22,7 @@ against captured reference outputs of `@mintlayer/wasm-lib` 1.4.0 (see | Platform | Artifact | Architectures | |---|---|---| -| Android 6.0+ (API 24) | `mintlayer-wallet-bindings-.aar` | `arm64-v8a`, `armeabi-v7a`, `x86_64` | +| Android 7.0+ (API 24) | `mintlayer-wallet-bindings-.aar` | `arm64-v8a`, `armeabi-v7a`, `x86_64` | | iOS 15+ | `MintlayerWalletBindings.xcframework` | `ios-arm64` (device), `ios-arm64_x86_64-simulator` | The Intel simulator slice (`x86_64-apple-ios-sim`) is omitted: recent diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 9f02c45..c2eef10 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -61,12 +61,19 @@ if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then exit 1 fi +# The remaining git/grep logic assumes the repository root; enforce it +# before touching the checkout's git config. +if [ ! -d .git ] || [ ! -f Package.swift ]; then + echo "::error::run this script from the repository root" + exit 1 +fi + git config user.name "mintlayer-release-bot" git config user.email "hello@mintlayer.org" -# The remaining git/grep logic assumes the repository root. -if [ ! -d .git ] || [ ! -f Package.swift ]; then - echo "::error::run this script from the repository root" +# TAG and VERSION must describe the same release. +if [ "${TAG}" != "wallet-bindings-v${VERSION}" ]; then + echo "::error::TAG (${TAG}) and VERSION (${VERSION}) do not describe the same release" exit 1 fi @@ -129,10 +136,17 @@ origin_pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ | grep -oE 'v[0-9][^"]*' || true)" origin_pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ | grep -oE 'checksum: "[0-9a-f]{64}"' | grep -oE '[0-9a-f]{64}' || true)" -if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ] \ - && [ -n "${origin_pin_tag}" ]; then +origin_pin_sum_raw="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ + | grep -oE 'checksum: "[^"]*"' | grep -oE '"[^"]*"' | tr -d '"' | head -1 || true)" +origin_pin_active=0 +if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ]; then + origin_pin_active=1 +fi +if [ "${origin_pin_active}" = "1" ]; then + # An active (non-placeholder) pin requires a parsable tag line; a + # missing/mangled tag line is itself a fail-closed state. origin_version="${origin_pin_tag#v}" - if [[ ! "${origin_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + if [ -z "${origin_pin_tag}" ] || [[ ! "${origin_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" exit 1 fi @@ -142,6 +156,14 @@ if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "000000000000000000000 echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi +elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then + # A checksum line exists but is not 64 lowercase hex: mangled pin. + echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${origin_pin_sum_raw}")" + exit 1 +elif [ -z "${origin_pin_sum_raw}" ] && [ -n "${origin_pin_tag}" ]; then + # A tag line without any checksum line: mangled pin. + echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" + exit 1 fi git commit -m "chore: pin the SPM checksum to ${TAG}" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index a73886f..22560bb 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -25,7 +25,19 @@ command -v jq >/dev/null 2>&1 || { echo "jq is required by this test harness"; e pass=0 fail=0 ok() { pass=$((pass + 1)); echo "ok - $1"; } -bad() { fail=$((fail + 1)); echo "NOT OK - $1: $2"; } +# Sanitize log output: the script under test and stub args are +# PR-controlled on pull_request runs, so neutralize workflow-command +# forgery and control characters before echoing. +sanitize() { + local s="$1" + s="${s//$'\r'/}" + s="${s//$'\n'/ | }" + s="${s//^::/[::}" + s="${s//::error::/[error] }" + s="${s//::warning::/[warning] }" + printf '%s' "$s" +} +bad() { fail=$((fail + 1)); echo "NOT OK - $1: $(sanitize "$2")"; } # --- stub git/gh ------------------------------------------------------- # Each stub logs its arguments and returns scripted behavior controlled @@ -312,6 +324,31 @@ run_case "same-version conflicting pin fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +# 23. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf '128' > "${TMP}/ancestry" +run_case "merge-base git error fails" 1 +assert_no_mutations +printf '0' > "${TMP}/ancestry" + +# 24. Unparseable origin pin tag -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-vx"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +run_case "unparseable origin pin tag fails" 1 +assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 25. Active checksum with missing tag line -> fail closed (one-sided). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +run_case "one-sided active checksum fails" 1 +assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 26. TAG/VERSION mismatch -> fail closed before any fetch. +set_fixtures 0 1 "${NOT_PINNED}" pr.none +run_case "mismatched tag and version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 9.9.9 + # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). TAG_REGEX='^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' From 9019953f92cda53f52374ef379ce58b768f3165f Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 17:42:45 +0100 Subject: [PATCH 11/53] ci: semver the rewind compare and guard release clobbering --- .github/workflows/release.yml | 16 +++++++++++++- .gitignore | 1 - CHANGELOG.md | 11 ++++------ docs/mobile-bindings.md | 2 +- scripts/release/open-spm-pr.sh | 23 ++++++++++++++++--- scripts/release/test-open-spm-pr.sh | 34 +++++++++++++++++------------ 6 files changed, 60 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7731fd4..9564fda 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -157,7 +157,7 @@ jobs: fi VERSION="${TAG#wallet-bindings-v}" echo "VERSION=$VERSION" >> "$GITHUB_ENV" - declared=$(grep -m1 '^version = ' bindings/Cargo.toml | sed 's/version = "\(.*\)"/\1/' | tr -d '[:cntrl:]') + declared=$(awk '/^\[package\]/{f=1;next} /^\[/{f=0} f&&/^version/{sub(/^version[[:space:]]*=[[:space:]]*"/,"");sub(/".*/,"");print;exit}' bindings/Cargo.toml | tr -d '[:cntrl:]') if [ "$declared" != "$VERSION" ]; then # Plain log lines, not a workflow annotation: $declared comes # from the repo at the tag and is not %-escaped here. @@ -213,6 +213,7 @@ jobs: - name: Create the GitHub release env: GH_TOKEN: ${{ github.token }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | notes=$(cat << 'EOF' ## Mobile bindings release @@ -235,6 +236,19 @@ jobs: ) # Idempotent for re-runs after a transient pin-PR failure: an # existing release is reused and its assets refreshed in place. + # Guard: if the default branch already pins THIS release and a + # rebuild is not bit-reproducible, clobbering would desync the + # published artifacts from the merged checksum. Fail closed + # before any public mutation; forward releases are unaffected. + pin_on_main="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ + | grep -oE 'checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" + pin_tag_on_main="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ + | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' | grep -oE 'v[^"]*' || true)" + if [ "$pin_tag_on_main" = "$TAG" ] && [ -n "$pin_on_main" ] \ + && [ "$pin_on_main" != "$xcsum" ]; then + echo "::error::rebuilt artifacts (checksum ${xcsum}) do not match the pin merged on ${DEFAULT_BRANCH} (${pin_on_main}); release assets left untouched - repair manually" + exit 1 + fi if gh release view "$TAG" >/dev/null 2>&1; then echo "release $TAG already exists; refreshing assets" gh release upload "$TAG" --clobber \ diff --git a/.gitignore b/.gitignore index 1f0fbdf..15e6716 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,6 @@ secrets/ .cargo/credentials # Local development scripts -.orc/ bindings/tests/fixtures/ node_modules/ bindings/kotlin/build/ diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b6865..cb751c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,14 +28,11 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). replay the public BIP39 vectors through the generated Swift bindings. - bindings: release workflow — pushing a `wallet-bindings-v*` tag builds the Android AAR and the iOS XCFramework from the tagged commit, attaches - them with checksums to a GitHub Release, and opens a pull request that - pins the SPM checksum in the root `Package.swift` to the released - artifact (a maintainer merges the pin PR to activate SPM resolution). - The generated Kotlin + them with checksums to a GitHub Release, and opens a checksum-pin pull + request for the root `Package.swift` after the release is published (a + maintainer merges it to activate SPM resolution). The generated Kotlin package is `org.mintlayer.wallet.bindings`; the Swift module is - `MintlayerWalletBindings`. The workflow publishes the release before - opening a checksum-pin PR for `Package.swift` (a maintainer merges it - to activate SPM resolution), and a `lint.yml` gate runs actionlint and + `MintlayerWalletBindings`. A `lint.yml` gate runs actionlint and shellcheck (plus unit tests for `scripts/release/`) on workflow and script changes. - indexer: cursor (keyset) pagination for api-server v2 diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 59de80d..3957ace 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -25,7 +25,7 @@ against captured reference outputs of `@mintlayer/wasm-lib` 1.4.0 (see | Android 7.0+ (API 24) | `mintlayer-wallet-bindings-.aar` | `arm64-v8a`, `armeabi-v7a`, `x86_64` | | iOS 15+ | `MintlayerWalletBindings.xcframework` | `ios-arm64` (device), `ios-arm64_x86_64-simulator` | -The Intel simulator slice (`x86_64-apple-ios-sim`) is omitted: recent +The Intel simulator slice (`x86_64-apple-ios`) is omitted: recent Xcode releases no longer ship Intel simulator runtimes. ## API surface diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index c2eef10..2053955 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -150,9 +150,26 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" exit 1 fi - # sort -V: the first line is the smaller version. If the incoming - # VERSION sorts first, the origin pin is newer-or-equal -> rewind. - if [ "$(printf '%s\n%s\n' "${origin_version}" "${VERSION}" | sort -V | head -1)" = "${VERSION}" ]; then + # Semver precedence: numeric triple, then the pre-release rule (a + # pre-release is less than the final release). + semver_cmp() { # <0 if $1 < $2, 0 if equal, >0 if $1 > $2 + local a="${1%%-*}" b="${2%%-*}" + local ap="" bp="" + [[ "$1" == *-* ]] && ap="${1#*-}" + [[ "$2" == *-* ]] && bp="${2#*-}" + local -a A B + read -ra A <<< "${a//[^0-9]/ }" + read -ra B <<< "${b//[^0-9]/ }" + local i + for i in 0 1 2; do + [ "${A[i]:-0}" -lt "${B[i]:-0}" ] && { echo -1; return; } + [ "${A[i]:-0}" -gt "${B[i]:-0}" ] && { echo 1; return; } + done + if [ -z "${ap}" ] && [ -n "${bp}" ]; then echo 1; return; fi + if [ -n "${ap}" ] && [ -z "${bp}" ]; then echo -1; return; fi + echo 0 + } + if [ "$(semver_cmp "${VERSION}" "${origin_version}")" -le 0 ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 22560bb..3f874d9 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1,12 +1,15 @@ #!/usr/bin/env bash # Unit tests for scripts/release/open-spm-pr.sh using stub git/gh on PATH. -# Covers: tag-ancestry guard (shallow-aware fetch both ways), HEAD==tag -# guard, both substitution verifications (pin fully present / either half -# drifted / absent), already-merged and pre-pinned short-circuits, -# owner/cross-repo/base-branch/rewind PR detection, force-push ordering -# and its absence on failure paths, owner/branch/checksum/tag validation, -# and the byte-identical TAG regex across all copies. Run by lint.yml and -# locally before releases. +# Covers: tag-ancestry guard (shallow-aware fetch both ways, git-error +# disambiguation), HEAD==tag guard, both substitution verifications (pin +# fully present / either half drifted / absent), already-merged, +# pre-pinned and reverted-main short-circuits, semver rewind guard +# (forward allowed, stale/same-version refused, one-sided and mangled +# origin pins refused), owner/cross-repo/base-branch PR detection, +# force-push ordering and its absence on failure paths, +# owner/branch/checksum/tag/version validation, and the byte-identical +# TAG regex across all copies. Run by lint.yml and locally before +# releases. set -uo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -29,13 +32,10 @@ ok() { pass=$((pass + 1)); echo "ok - $1"; } # PR-controlled on pull_request runs, so neutralize workflow-command # forgery and control characters before echoing. sanitize() { - local s="$1" - s="${s//$'\r'/}" - s="${s//$'\n'/ | }" - s="${s//^::/[::}" - s="${s//::error::/[error] }" - s="${s//::warning::/[warning] }" - printf '%s' "$s" + # PR-controlled output: neutralize every workflow-command prefix + # (::error::, ::notice::, ::group::, ::add-mask::, ...) and control + # characters before echoing into the check log. + printf '%s' "$1" | tr -d '\000-\010\013\014\016-\037' | sed -E 's/::[a-z][a-z-]*:([^:]|$)/[::\1/g' } bad() { fail=$((fail + 1)); echo "NOT OK - $1: $(sanitize "$2")"; } @@ -252,6 +252,7 @@ assert_no_mutations # 12. Malformed XCSUM -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" +assert_no_mutations # 13. HEAD is not the tagged commit -> fail closed, no push. set_fixtures 0 1 "${FULLY_PINNED}" pr.none @@ -264,16 +265,20 @@ printf 'tagcommitsha' > "${TMP}/head_commit" set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "all-zero checksum fails" 1 "mintlayer/rust-sdk" main \ "0000000000000000000000000000000000000000000000000000000000000000" +assert_no_mutations # 15. VERSION that is not semver -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 +assert_no_mutations # 16. TAG not matching the release pattern -> fail closed before fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid tag (no patch) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 "wallet-bindings-v1.2" +assert_no_mutations set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid tag (wrong prefix) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2.3 "evil-wallet-bindings-v1.2.3" +assert_no_mutations # 17. Default branch inside the reserved namespace -> fail closed. set_fixtures 0 1 "${NOT_PINNED}" pr.none @@ -348,6 +353,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 # 26. TAG/VERSION mismatch -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "mismatched tag and version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 9.9.9 +assert_no_mutations # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). From c54a85c528d93b6b13f560a7bdef5e4ad995af8c Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 17:53:22 +0100 Subject: [PATCH 12/53] ci: testable clobber guard and full semver precedence --- .github/workflows/release.yml | 10 +--- scripts/release/guard-release-refresh.sh | 32 +++++++++++ scripts/release/open-spm-pr.sh | 45 ++++++++++++--- scripts/release/test-open-spm-pr.sh | 73 ++++++++++++++++++++++-- 4 files changed, 140 insertions(+), 20 deletions(-) create mode 100755 scripts/release/guard-release-refresh.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9564fda..84c27ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -240,15 +240,7 @@ jobs: # rebuild is not bit-reproducible, clobbering would desync the # published artifacts from the merged checksum. Fail closed # before any public mutation; forward releases are unaffected. - pin_on_main="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ - | grep -oE 'checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" - pin_tag_on_main="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ - | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' | grep -oE 'v[^"]*' || true)" - if [ "$pin_tag_on_main" = "$TAG" ] && [ -n "$pin_on_main" ] \ - && [ "$pin_on_main" != "$xcsum" ]; then - echo "::error::rebuilt artifacts (checksum ${xcsum}) do not match the pin merged on ${DEFAULT_BRANCH} (${pin_on_main}); release assets left untouched - repair manually" - exit 1 - fi + scripts/release/guard-release-refresh.sh "$TAG" "$XCSUM" "$DEFAULT_BRANCH" if gh release view "$TAG" >/dev/null 2>&1; then echo "release $TAG already exists; refreshing assets" gh release upload "$TAG" --clobber \ diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh new file mode 100755 index 0000000..77d3712 --- /dev/null +++ b/scripts/release/guard-release-refresh.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# Refuse to clobber published release assets when the default branch +# already pins THIS release and the rebuilt artifacts are not +# bit-reproducible: publishing mismatched artifacts would desync SPM +# resolution from the merged checksum on the default branch. Forward +# releases are unaffected (the default branch pins an older release, or +# nothing at all). +# +# Usage: guard-release-refresh.sh +set -euo pipefail + +TAG="${1:?TAG required}" +XCSUM="${2:?XCSUM required}" +DEFAULT_BRANCH="${3:?DEFAULT_BRANCH required}" + +if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ + || [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then + echo "::error::unexpected default branch: ${DEFAULT_BRANCH}" + exit 1 +fi + +pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ + | grep -oE 'checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" +pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ + | grep -oE 'wallet-bindings-v[^"]*' | head -1 || true)" + +# Only a pin for THIS release constrains the refresh; identical +# checksums make the refresh a harmless no-op. +if [ "${pin_tag}" = "${TAG}" ] && [ -n "${pin_sum}" ] && [ "${pin_sum}" != "${XCSUM}" ]; then + echo "::error::rebuilt artifacts (checksum ${XCSUM}) do not match the pin merged on ${DEFAULT_BRANCH} (${pin_sum}); release assets left untouched - repair manually" + exit 1 +fi diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 2053955..f221fe8 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -150,8 +150,41 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" exit 1 fi - # Semver precedence: numeric triple, then the pre-release rule (a - # pre-release is less than the final release). + # Semver precedence: numeric triple (10# forces decimal, so leading + # zeros cannot octal-flip the verdict), then identifier-wise + # pre-release comparison (a pre-release is less than the final; + # numeric identifiers are lower than alphanumeric; fewer identifiers + # are lower). + semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 + # A final release outranks any pre-release of the same triple. + if [ -z "$1" ] && [ -n "$2" ]; then echo 1; return; fi + if [ -n "$1" ] && [ -z "$2" ]; then echo -1; return; fi + if [ -z "$1" ] && [ -z "$2" ]; then echo 0; return; fi + local -a A B + IFS='.' read -ra A <<< "${1}" + IFS='.' read -ra B <<< "${2}" + local i n + n=$(( ${#A[@]} > ${#B[@]} ? ${#A[@]} : ${#B[@]} )) + for ((i = 0; i < n; i++)); do + local x="${A[i]:-}" y="${B[i]:-}" + if [ -z "${x}" ] && [ -z "${y}" ]; then continue; fi + if [ -z "${x}" ]; then echo -1; return; fi + if [ -z "${y}" ]; then echo 1; return; fi + if [[ "${x}" =~ ^[0-9]+$ ]] && [[ "${y}" =~ ^[0-9]+$ ]]; then + [ "$((10#${x}))" -lt "$((10#${y}))" ] && { echo -1; return; } + [ "$((10#${x}))" -gt "$((10#${y}))" ] && { echo 1; return; } + elif [[ "${x}" =~ ^[0-9]+$ ]]; then + echo -1; return + elif [[ "${y}" =~ ^[0-9]+$ ]]; then + echo 1; return + elif [[ "${x^^}" < "${y^^}" ]]; then + echo -1; return + elif [[ "${x^^}" > "${y^^}" ]]; then + echo 1; return + fi + done + echo 0 + } semver_cmp() { # <0 if $1 < $2, 0 if equal, >0 if $1 > $2 local a="${1%%-*}" b="${2%%-*}" local ap="" bp="" @@ -162,12 +195,10 @@ if [ "${origin_pin_active}" = "1" ]; then read -ra B <<< "${b//[^0-9]/ }" local i for i in 0 1 2; do - [ "${A[i]:-0}" -lt "${B[i]:-0}" ] && { echo -1; return; } - [ "${A[i]:-0}" -gt "${B[i]:-0}" ] && { echo 1; return; } + [ "$((10#${A[i]:-0}))" -lt "$((10#${B[i]:-0}))" ] && { echo -1; return; } + [ "$((10#${A[i]:-0}))" -gt "$((10#${B[i]:-0}))" ] && { echo 1; return; } done - if [ -z "${ap}" ] && [ -n "${bp}" ]; then echo 1; return; fi - if [ -n "${ap}" ] && [ -z "${bp}" ]; then echo -1; return; fi - echo 0 + semver_prerelease_cmp "${ap}" "${bp}" } if [ "$(semver_cmp "${VERSION}" "${origin_version}")" -le 0 ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 3f874d9..02f11c9 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -32,10 +32,11 @@ ok() { pass=$((pass + 1)); echo "ok - $1"; } # PR-controlled on pull_request runs, so neutralize workflow-command # forgery and control characters before echoing. sanitize() { - # PR-controlled output: neutralize every workflow-command prefix - # (::error::, ::notice::, ::group::, ::add-mask::, ...) and control - # characters before echoing into the check log. - printf '%s' "$1" | tr -d '\000-\010\013\014\016-\037' | sed -E 's/::[a-z][a-z-]*:([^:]|$)/[::\1/g' + # PR-controlled output: neutralize every workflow-command prefix — + # both ::cmd:: and the parameterized ::cmd key=value:: forms — and + # control characters (including LF) before echoing into the log. + printf '%s' "$1" | tr -d '\000-\010\011\013\014\016-\037' \ + | sed -E 's/::[a-z][a-z-]*([ ][^:]*)?::/[::]/g; s/::[a-z][a-z-]*:/[::]/g' } bad() { fail=$((fail + 1)); echo "NOT OK - $1: $(sanitize "$2")"; } @@ -355,6 +356,70 @@ set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "mismatched tag and version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 9.9.9 assert_no_mutations +# 27. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "deadbeef"\n' > "${TMP}/origin_swift" +run_case "mangled origin checksum fails" 1 +assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 28. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-rc.1" // ... +checksum: "'"${XCSUM}"'"' pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3-rc.1 1.2.3-rc.1 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "prerelease after final refused"; else bad "prerelease after final refused" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 29. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3-rc1"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( 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=$? +if [ "${rc}" = "0" ] && grep -q "gh pr create" "${LOG}"; then + ok "final over prerelease proceeds" +else + bad "final over prerelease proceeds" "exit ${rc}: $(cat "${OUT}")" +fi +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 30. Guard script: same tag + differing checksum -> refuse. +GUARD="${SCRIPT_DIR}/guard-release-refresh.sh" +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${GUARD}" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard refuses mismatched rebuild"; else bad "guard refuses mismatched rebuild" "exit ${rc}"; fi + +# 31. Guard script: same tag + identical checksum -> allow. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${GUARD}" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "guard allows identical rebuild"; else bad "guard allows identical rebuild" "exit ${rc}"; fi + +# 32. Guard script: older pin on main (forward release) -> allow. +printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${GUARD}" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). TAG_REGEX='^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' From 2cb7c99e1a0819cbab273b6e46167c0539019707 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 18:05:59 +0100 Subject: [PATCH 13/53] ci: shellcheck-quiet the fixture printf escapes --- .github/workflows/release.yml | 12 ++++++++--- .gitignore | 4 ++-- CHANGELOG.md | 1 - scripts/release/guard-release-refresh.sh | 26 +++++++++++++++++++++--- scripts/release/open-spm-pr.sh | 9 ++++++-- scripts/release/test-open-spm-pr.sh | 25 +++++++++++++++-------- 6 files changed, 58 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84c27ea..1919ab7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -205,9 +205,15 @@ jobs: # Package.swift must fail the release rather than skip the pin. grep -F "$xcsum" Package.swift >/dev/null grep -F "let releaseTag = \"$TAG\"" Package.swift >/dev/null - # Neutralize a leading '::' so a crafted Package.swift line - # cannot forge workflow annotations in this log. - grep -E "releaseTag|checksum" Package.swift | sed 's/^::/[::/' + # A second checksum line would silently receive the same pin; + # refuse if the file ever gains additional binary targets. + if [ "$(grep -c 'checksum:' Package.swift)" != "1" ]; then + echo "::error::Package.swift carries more than one checksum line; refusing to pin" + exit 1 + fi + # Neutralize every '::' so no crafted Package.swift line can + # forge workflow commands (leading or mid-line) in this log. + grep -E "releaseTag|checksum" Package.swift | sed 's/::/[::]/g' echo "XCSUM=$xcsum" >> "$GITHUB_ENV" - name: Create the GitHub release diff --git a/.gitignore b/.gitignore index 15e6716..89bde9e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ tarpaulin-report.html .DS_Store # ── misc ────────────────────────────────────────────────────────────────────── -.wrangler/ # ── secrets: never commit credentials or key material ──────────────────────── .env @@ -25,7 +24,8 @@ tarpaulin-report.html secrets/ .cargo/credentials -# Local development scripts +# Local generated output +.wrangler/ bindings/tests/fixtures/ node_modules/ bindings/kotlin/build/ diff --git a/CHANGELOG.md b/CHANGELOG.md index cb751c3..285a928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,6 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). mapped from the api-server error bodies (`{"error": ...}`). - `examples/indexer-pagination.rs`: runnable walks for holders, the order book, the global transaction listing and pools. - - `node::Error::OutcomeUnknown` / `wallet::Error::OutcomeUnknown`: the request was delivered but its outcome could not be confirmed (lost, oversized, undecodable or mismatched response, or a timeout while diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 77d3712..64e5750 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -13,20 +13,40 @@ TAG="${1:?TAG required}" XCSUM="${2:?XCSUM required}" DEFAULT_BRANCH="${3:?DEFAULT_BRANCH required}" +esc() { + local s="$1" + s="${s//%/%25}" + s="${s//$'\r'/%0D}" + s="${s//$'\n'/%0A}" + printf '%s' "$s" +} + +# Mirror the workflow's validation so direct invocations fail closed. +if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v" + exit 1 +fi +if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]]; then + echo "::error::checksum is not 64 lowercase hex characters" + exit 1 +fi if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ || [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then - echo "::error::unexpected default branch: ${DEFAULT_BRANCH}" + echo "::error::unexpected default branch: $(esc "${DEFAULT_BRANCH}")" exit 1 fi pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ | grep -oE 'checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" +# Anchor to the releaseTag assignment line: the file header comment also +# contains a wallet-bindings-vX.Y.Z literal and must not be matched. pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ - | grep -oE 'wallet-bindings-v[^"]*' | head -1 || true)" + | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' | head -1 \ + | grep -oE 'wallet-bindings-v[^"]*' || true)" # Only a pin for THIS release constrains the refresh; identical # checksums make the refresh a harmless no-op. if [ "${pin_tag}" = "${TAG}" ] && [ -n "${pin_sum}" ] && [ "${pin_sum}" != "${XCSUM}" ]; then - echo "::error::rebuilt artifacts (checksum ${XCSUM}) do not match the pin merged on ${DEFAULT_BRANCH} (${pin_sum}); release assets left untouched - repair manually" + echo "::error::rebuilt artifacts (checksum $(esc "${XCSUM}")) do not match the pin merged on $(esc "${DEFAULT_BRANCH}") ($(esc "${pin_sum}")); release assets left untouched - repair manually" exit 1 fi diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index f221fe8..db15050 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# LC_ALL=C pins collation for the semver string comparisons below. +export LC_ALL=C # Open (or reuse) the SPM checksum-pin pull request for a release tag. # # Branch protection on the default branch rejects direct pushes (GH013), @@ -88,7 +90,7 @@ fi merge_rc=0 git merge-base --is-ancestor "refs/tags/${TAG}" "origin/${DEFAULT_BRANCH}" || merge_rc=$? if [ "${merge_rc}" -gt 1 ]; then - echo "::error::failed to compare ${TAG} against origin/${DEFAULT_BRANCH} (git exit ${merge_rc}); check the fetch and the tag" + echo "::error::failed to compare $(esc "${TAG}") against origin/${DEFAULT_BRANCH} (git exit ${merge_rc}); check the fetch and the tag" exit 1 fi if [ "${merge_rc}" -eq 1 ]; then @@ -100,7 +102,7 @@ fi # would be built (and force-pushed) on the wrong base. tag_commit="$(git rev-parse "refs/tags/${TAG}^{commit}")" if [ "$(git rev-parse HEAD)" != "${tag_commit}" ]; then - echo "::error::HEAD is not the tagged commit; run from a checkout of ${TAG}" + echo "::error::HEAD is not the tagged commit; run from a checkout of $(esc "${TAG}")" exit 1 fi @@ -190,6 +192,9 @@ if [ "${origin_pin_active}" = "1" ]; then local ap="" bp="" [[ "$1" == *-* ]] && ap="${1#*-}" [[ "$2" == *-* ]] && bp="${2#*-}" + # Build metadata is excluded from precedence: strip it from both. + ap="${ap%%+*}" + bp="${bp%%+*}" local -a A B read -ra A <<< "${a//[^0-9]/ }" read -ra B <<< "${b//[^0-9]/ }" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 02f11c9..a049b82 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -# Unit tests for scripts/release/open-spm-pr.sh using stub git/gh on PATH. +# Unit tests for scripts/release/open-spm-pr.sh and +# scripts/release/guard-release-refresh.sh using stub git/gh on PATH. # Covers: tag-ancestry guard (shallow-aware fetch both ways, git-error # disambiguation), HEAD==tag guard, both substitution verifications (pin # fully present / either half drifted / absent), already-merged, @@ -32,11 +33,11 @@ ok() { pass=$((pass + 1)); echo "ok - $1"; } # PR-controlled on pull_request runs, so neutralize workflow-command # forgery and control characters before echoing. sanitize() { - # PR-controlled output: neutralize every workflow-command prefix — - # both ::cmd:: and the parameterized ::cmd key=value:: forms — and - # control characters (including LF) before echoing into the log. - printf '%s' "$1" | tr -d '\000-\010\011\013\014\016-\037' \ - | sed -E 's/::[a-z][a-z-]*([ ][^:]*)?::/[::]/g; s/::[a-z][a-z-]*:/[::]/g' + # PR-controlled output: replace every '::' so no workflow command can + # survive, per line. LF/CR are intentionally preserved — deleting them + # could splice two benign fragments into a new command — and each + # resulting line is safe because '::' no longer occurs in it. + printf '%s' "$1" | tr -d '\000-\010\011\013\014\016-\037' | sed 's/::/[::]/g' } bad() { fail=$((fail + 1)); echo "NOT OK - $1: $(sanitize "$2")"; } @@ -107,7 +108,11 @@ set_fixtures() { printf 'tagcommitsha' > "${TMP}/head_commit" printf 'tagcommitsha' > "${TMP}/tag_commit" printf 'false' > "${TMP}/is_shallow" - printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + # 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 + printf '// The binary target is attached to the `wallet-bindings-vX.Y.Z`\n// GitHub release; its checksum is updated by the release workflow.\n' > "${TMP}/origin_swift" + printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' >> "${TMP}/origin_swift" } # assert_no_mutations: fail-closed cases must not push or open PRs. @@ -401,8 +406,12 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses mismatched rebuild"; else bad "guard refuses mismatched rebuild" "exit ${rc}"; fi -# 31. Guard script: same tag + identical checksum -> allow. +# 31. Guard script: same tag + identical checksum (with a header +# comment whose version literal differs) -> allow. set_fixtures 0 1 "${FULLY_PINNED}" pr.none +# shellcheck disable=SC2016 # \n are printf escapes, no expansion +printf '// The binary target is attached to the `wallet-bindings-v9.9.9`\n// GitHub release; its checksum is updated by the release workflow.\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" >> "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ bash "${GUARD}" wallet-bindings-v1.2.3 "${XCSUM}" main \ From 77690166abad9957a4cef332d12a255b0ee977fd Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 18:19:47 +0100 Subject: [PATCH 14/53] ci: fail closed on decoys, overflow, and missing state --- .github/workflows/release.yml | 6 +-- .gitignore | 2 - scripts/release/guard-release-refresh.sh | 37 ++++++++++++------ scripts/release/open-spm-pr.sh | 32 +++++++++++----- scripts/release/test-open-spm-pr.sh | 48 ++++++++++++++++++++++-- 5 files changed, 96 insertions(+), 29 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1919ab7..7d2cae5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,7 +38,7 @@ jobs: env: TAG: ${{ github.ref_name }} run: | - if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" exit 1 fi @@ -104,7 +104,7 @@ jobs: env: TAG: ${{ github.ref_name }} run: | - if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" exit 1 fi @@ -151,7 +151,7 @@ jobs: run: | # Positive validation: everything downstream (sed programs, # commit message, PR title/body) interpolates TAG. - if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + if [[ ! "$TAG" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" exit 1 fi diff --git a/.gitignore b/.gitignore index 89bde9e..faad6b8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,6 @@ tarpaulin-report.html *.swo .DS_Store -# ── misc ────────────────────────────────────────────────────────────────────── - # ── secrets: never commit credentials or key material ──────────────────────── .env .env.* diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 64e5750..03c38b6 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -22,12 +22,12 @@ esc() { } # Mirror the workflow's validation so direct invocations fail closed. -if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then +if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" exit 1 fi -if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]]; then - echo "::error::checksum is not 64 lowercase hex characters" +if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]] || [ "${XCSUM//0/}" = "" ]; then + echo "::error::checksum is not 64 lowercase hex characters (all-zero refused)" exit 1 fi if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ @@ -36,17 +36,32 @@ if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ exit 1 fi -pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ - | grep -oE 'checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" -# Anchor to the releaseTag assignment line: the file header comment also -# contains a wallet-bindings-vX.Y.Z literal and must not be matched. -pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null \ - | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' | head -1 \ - | grep -oE 'wallet-bindings-v[^"]*' || true)" +origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" \ + || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } +# Only real code lines constitute the pin: comment lines are ignored so +# a decoy literal in a comment cannot flip the guard's verdict. +origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//')" + +pin_tag_matches="$(printf '%s\n' "${origin_code}" \ + | grep -cE '^[[:space:]]*let releaseTag = "wallet-bindings-v[^"]*"$' || true)" +if [ "${pin_tag_matches}" != "1" ]; then + echo "::error::expected exactly one releaseTag assignment on ${DEFAULT_BRANCH}, found ${pin_tag_matches}" + exit 1 +fi +pin_sum_matches="$(printf '%s\n' "${origin_code}" \ + | grep -cE '^[[:space:]]*checksum: "[0-9a-f]{64}"$' || true)" +if [ "${pin_sum_matches}" != "1" ]; then + echo "::error::expected exactly one checksum assignment on ${DEFAULT_BRANCH}, found ${pin_sum_matches}" + exit 1 +fi +pin_tag="$(printf '%s\n' "${origin_code}" \ + | grep -E '^[[:space:]]*let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" +pin_sum="$(printf '%s\n' "${origin_code}" \ + | grep -E '^[[:space:]]*checksum: ' | grep -oE '[0-9a-f]{64}')" # Only a pin for THIS release constrains the refresh; identical # checksums make the refresh a harmless no-op. -if [ "${pin_tag}" = "${TAG}" ] && [ -n "${pin_sum}" ] && [ "${pin_sum}" != "${XCSUM}" ]; then +if [ "${pin_tag}" = "${TAG}" ] && [ "${pin_sum}" != "${XCSUM}" ]; then echo "::error::rebuilt artifacts (checksum $(esc "${XCSUM}")) do not match the pin merged on $(esc "${DEFAULT_BRANCH}") ($(esc "${pin_sum}")); release assets left untouched - repair manually" exit 1 fi diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index db15050..3b594ec 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -35,11 +35,11 @@ esc() { # Mirror the workflow's validation so direct/manual invocations get the # same fail-closed guarantees as the release run. -if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then +if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" exit 1 fi -if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then +if [[ ! "${VERSION}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::version does not match " exit 1 fi @@ -57,6 +57,10 @@ if [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then echo "::error::default branch must not use the reserved pin-spm-checksum-* namespace" exit 1 fi +if [ -z "${GITHUB_REPOSITORY:-}" ]; then + echo "::error::GITHUB_REPOSITORY is not set" + exit 1 +fi owner="${GITHUB_REPOSITORY%%/*}" if [[ ! "${owner}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then echo "::error::unexpected repository owner format: $(esc "${owner}")" @@ -65,7 +69,7 @@ fi # The remaining git/grep logic assumes the repository root; enforce it # before touching the checkout's git config. -if [ ! -d .git ] || [ ! -f Package.swift ]; then +if [ ! -e .git ] || [ ! -f Package.swift ]; then echo "::error::run this script from the repository root" exit 1 fi @@ -133,10 +137,15 @@ fi # The default branch carrying an ACTIVE pin for a NEWER-or-equal # release means this invocation would rewind that pin; refuse. Older # active pins are the normal forward-release state and proceed. -origin_pin_tag="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ +origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" \ + || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } +# Only real code lines constitute the pin: comment lines are ignored so +# a decoy literal in a comment cannot flip the guard's verdict. +origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//')" +origin_pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ | grep -oE 'v[0-9][^"]*' || true)" -origin_pin_sum="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ +origin_pin_sum="$(printf '%s\n' "${origin_code}" \ | grep -oE 'checksum: "[0-9a-f]{64}"' | grep -oE '[0-9a-f]{64}' || true)" origin_pin_sum_raw="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ | grep -oE 'checksum: "[^"]*"' | grep -oE '"[^"]*"' | tr -d '"' | head -1 || true)" @@ -148,7 +157,7 @@ if [ "${origin_pin_active}" = "1" ]; then # An active (non-placeholder) pin requires a parsable tag line; a # missing/mangled tag line is itself a fail-closed state. origin_version="${origin_pin_tag#v}" - if [ -z "${origin_pin_tag}" ] || [[ ! "${origin_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$ ]]; then + if [ -z "${origin_pin_tag}" ] || [[ ! "${origin_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" exit 1 fi @@ -179,9 +188,9 @@ if [ "${origin_pin_active}" = "1" ]; then echo -1; return elif [[ "${y}" =~ ^[0-9]+$ ]]; then echo 1; return - elif [[ "${x^^}" < "${y^^}" ]]; then + elif [[ "${x}" < "${y}" ]]; then echo -1; return - elif [[ "${x^^}" > "${y^^}" ]]; then + elif [[ "${x}" > "${y}" ]]; then echo 1; return fi done @@ -205,7 +214,12 @@ if [ "${origin_pin_active}" = "1" ]; then done semver_prerelease_cmp "${ap}" "${bp}" } - if [ "$(semver_cmp "${VERSION}" "${origin_version}")" -le 0 ]; then + cmp="$(semver_cmp "${VERSION}" "${origin_version}")" + if [[ ! "${cmp}" =~ ^-?[012]$ ]]; then + echo "::error::semver comparison failed for ${VERSION} against ${origin_version}" + exit 1 + fi + if [ "${cmp}" -le 0 ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index a049b82..136a48e 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -377,6 +377,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e bash "${UNDER_TEST}" wallet-bindings-v1.2.3-rc.1 1.2.3-rc.1 "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "prerelease after final refused"; else bad "prerelease after final refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" @@ -384,6 +385,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 # 29. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3-rc1"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +: > "${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 \ @@ -396,6 +398,32 @@ else fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +# 29b. Build metadata is excluded from precedence: an origin pin of +# 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3+meta.a 1.2.3+meta.a "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "build-metadata equal precedence refused"; else bad "build-metadata equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations + +# 29c. Origin pin without metadata vs incoming with metadata: equal +# precedence -> refuse. +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3+meta 1.2.3+meta "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + # 30. Guard script: same tag + differing checksum -> refuse. GUARD="${SCRIPT_DIR}/guard-release-refresh.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -429,15 +457,27 @@ rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +# 33. Comment decoys claiming THIS tag+checksum while the real code pin +# differs -> comment stripping makes the guard refuse (fail closed). +printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). -TAG_REGEX='^wallet-bindings-v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' +TAG_REGEX='^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$' wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release.yml" || true)" sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" -if [ "${wf}" = "3" ] && [ "${sc}" = "1" ]; then - ok "tag regex identical across all four copies" +gd="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/guard-release-refresh.sh" || true)" +if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "1" ]; then + ok "tag regex identical across all five copies" else - bad "tag regex identical across all four copies" "release.yml=${wf}, script=${sc}" + bad "tag regex identical across all five copies" "release.yml=${wf}, script=${sc}, guard=${gd}" fi echo "passed: ${pass}, failed: ${fail}" From b8e35d15f2a62647802d258c0639a7dc4704b99f Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 18:30:07 +0100 Subject: [PATCH 15/53] ci: anchored pin verification and merge-time pin ordering --- .github/workflows/ci.yml | 32 ++++++++++++++++++++++++ .github/workflows/release.yml | 9 +++++-- scripts/release/guard-release-refresh.sh | 5 +++- scripts/release/open-spm-pr.sh | 28 +++++++++++++-------- scripts/release/test-open-spm-pr.sh | 14 +++++++++++ 5 files changed, 74 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 037857a..e9ad55e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,38 @@ env: CARGO_TERM_COLOR: always jobs: + # Merge-time pin-order enforcement: a checksum-pin PR must not + # downgrade the release pinned on the default branch. Runs on PRs + # touching Package.swift; branch protection can require it. + pin-order: + name: Pin ordering + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + - name: Refuse a downgrading pin + run: | + changed="$(git diff --name-only "origin/${{ github.base_ref }}...HEAD" | grep -c '^Package.swift$' || true)" + if [ "$changed" = "0" ]; then + echo "Package.swift untouched; nothing to check" + exit 0 + fi + incoming="$(grep -oE 'let releaseTag = "wallet-bindings-v[0-9.]+[^"]*"' Package.swift | grep -oE '[0-9][^"]*' || true)" + current="$(git show "origin/${{ github.base_ref }}:Package.swift" \ + | grep -oE 'let releaseTag = "wallet-bindings-v[0-9.]+[^"]*"' | grep -oE '[0-9][^"]*' || true)" + if [ -z "$incoming" ]; then + echo "::error::pin PR carries no parsable releaseTag" + exit 1 + fi + if [ -n "$current" ] \ + && [ "$(printf '%s\n%s\n' "$incoming" "$current" | sort -V | head -1)" != "$incoming" ]; then + echo "::error::pin PR would downgrade the release from $current to $incoming" + exit 1 + fi + echo "pin order ok (incoming $incoming, current ${current:-none})" + fmt: name: Format runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7d2cae5..99f1aa8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -137,6 +137,7 @@ jobs: pull-requests: write env: TAG: ${{ github.ref_name }} + LC_ALL: C steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: @@ -203,8 +204,12 @@ jobs: Package.swift # Both substitutions must actually land; a no-op sed on a drifted # Package.swift must fail the release rather than skip the pin. - grep -F "$xcsum" Package.swift >/dev/null - grep -F "let releaseTag = \"$TAG\"" Package.swift >/dev/null + pin_tag_lines="$(grep -cE "^[[:space:]]*let releaseTag = \"$TAG\"[[:space:]]*(//.*)?$" Package.swift || true)" + pin_sum_lines="$(grep -cE "^[[:space:]]*checksum: \"$xcsum\"[[:space:]]*(//.*)?$" Package.swift || true)" + if [ "$pin_tag_lines" != "1" ] || [ "$pin_sum_lines" != "1" ]; then + echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" + exit 1 + fi # A second checksum line would silently receive the same pin; # refuse if the file ever gains additional binary targets. if [ "$(grep -c 'checksum:' Package.swift)" != "1" ]; then diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 03c38b6..7bbae85 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +# LC_ALL=C pins collation for the ASCII-range validations below. +export LC_ALL=C # Refuse to clobber published release assets when the default branch # already pins THIS release and the rebuilt artifacts are not # bit-reproducible: publishing mismatched artifacts would desync SPM @@ -14,7 +16,8 @@ XCSUM="${2:?XCSUM required}" DEFAULT_BRANCH="${3:?DEFAULT_BRANCH required}" esc() { - local s="$1" + local s + s="$(printf '%s' "$1" | tr -d '\000-\037\177')" s="${s//%/%25}" s="${s//$'\r'/%0D}" s="${s//$'\n'/%0A}" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 3b594ec..96e04bf 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -26,7 +26,10 @@ BRANCH="pin-spm-checksum-${VERSION}" # Workflow-command values need %-/CR-/LF-escaping to stay one annotation. esc() { - local s="$1" + # Strip C0 control bytes (incl. ESC) so extracted repo content cannot + # spoof the log with terminal escapes, then %-escape the rest. + local s + s="$(printf '%s' "$1" | tr -d '\000-\037\177')" s="${s//%/%25}" s="${s//$'\r'/%0D}" s="${s//$'\n'/%0A}" @@ -114,9 +117,12 @@ git checkout -B "${BRANCH}" git add Package.swift # Both substitutions must be present, on every path: anything else means # the sed no-op'd or corrupted the file; fail closed. -if ! grep -qF "${XCSUM}" Package.swift \ - || ! grep -qF "let releaseTag = \"${TAG}\"" Package.swift; then - echo "::error::Package.swift does not carry the expected release tag and checksum after substitution" +# Anchored, exactly-once verification: substring greps would also match +# a drifted assignment plus a comment carrying the canonical literal. +pin_tag_lines="$(grep -cE "^[[:space:]]*let releaseTag = \"${TAG}\"[[:space:]]*(//.*)?$" Package.swift || true)" +pin_sum_lines="$(grep -cE "^[[:space:]]*checksum: \"${XCSUM}\"[[:space:]]*(//.*)?$" Package.swift || true)" +if [ "${pin_tag_lines}" != "1" ] || [ "${pin_sum_lines}" != "1" ]; then + echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 fi # An identical Package.swift on the default branch means the pin PR was @@ -141,14 +147,14 @@ origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } # Only real code lines constitute the pin: comment lines are ignored so # a decoy literal in a comment cannot flip the guard's verdict. -origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//')" +origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//' || true)" origin_pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ | grep -oE 'v[0-9][^"]*' || true)" -origin_pin_sum="$(printf '%s\n' "${origin_code}" \ - | grep -oE 'checksum: "[0-9a-f]{64}"' | grep -oE '[0-9a-f]{64}' || true)" -origin_pin_sum_raw="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" \ +origin_pin_sum_raw="$(printf '%s\n' "${origin_code}" \ | grep -oE 'checksum: "[^"]*"' | grep -oE '"[^"]*"' | tr -d '"' | head -1 || true)" +origin_pin_sum="$(printf '%s\n' "${origin_pin_sum_raw}" \ + | grep -oE '^[0-9a-f]{64}$' || true)" origin_pin_active=0 if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ]; then origin_pin_active=1 @@ -181,12 +187,12 @@ if [ "${origin_pin_active}" = "1" ]; then if [ -z "${x}" ] && [ -z "${y}" ]; then continue; fi if [ -z "${x}" ]; then echo -1; return; fi if [ -z "${y}" ]; then echo 1; return; fi - if [[ "${x}" =~ ^[0-9]+$ ]] && [[ "${y}" =~ ^[0-9]+$ ]]; then + if [[ "${x}" =~ ^[0-9]{1,18}$ ]] && [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then [ "$((10#${x}))" -lt "$((10#${y}))" ] && { echo -1; return; } [ "$((10#${x}))" -gt "$((10#${y}))" ] && { echo 1; return; } - elif [[ "${x}" =~ ^[0-9]+$ ]]; then + elif [[ "${x}" =~ ^[0-9]{1,18}$ ]]; then echo -1; return - elif [[ "${y}" =~ ^[0-9]+$ ]]; then + elif [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then echo 1; return elif [[ "${x}" < "${y}" ]]; then echo -1; return diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 136a48e..a6ba53c 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -422,6 +422,20 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations + +# 29d. Huge numeric prerelease identifiers (20 digits) compare as +# alphanumeric under the 18-digit cap: an origin pin of rc<20 digits> +# still outranks incoming rc.2 -> refused, no arithmetic wrap. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3-18446744073709551617"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3-2 1.2.3-2 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "huge numeric prerelease refused without wrap"; else bad "huge numeric prerelease refused without wrap" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" # 30. Guard script: same tag + differing checksum -> refuse. From 9ed804df2a9246ed356505881be553cec88f40a6 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 18:51:07 +0100 Subject: [PATCH 16/53] ci: one semver source, annotation-safe pin-order gate --- .github/workflows/ci.yml | 30 +++--- .github/workflows/release.yml | 6 +- scripts/release/check-pin-order.sh | 80 +++++++++++++++ scripts/release/guard-release-refresh.sh | 8 +- scripts/release/open-spm-pr.sh | 82 ++++----------- scripts/release/semver.sh | 61 +++++++++++ scripts/release/test-open-spm-pr.sh | 123 ++++++++++++++++++++++- 7 files changed, 308 insertions(+), 82 deletions(-) create mode 100755 scripts/release/check-pin-order.sh create mode 100755 scripts/release/semver.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9ad55e..456a1bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,32 +21,32 @@ jobs: # touching Package.swift; branch protection can require it. pin-order: name: Pin ordering + if: github.event_name == 'pull_request' runs-on: ubuntu-latest timeout-minutes: 15 + env: + LC_ALL: C steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: fetch-depth: 0 + persist-credentials: false - name: Refuse a downgrading pin + env: + BASE_REF: ${{ github.base_ref }} run: | - changed="$(git diff --name-only "origin/${{ github.base_ref }}...HEAD" | grep -c '^Package.swift$' || true)" - if [ "$changed" = "0" ]; then - echo "Package.swift untouched; nothing to check" - exit 0 - fi - incoming="$(grep -oE 'let releaseTag = "wallet-bindings-v[0-9.]+[^"]*"' Package.swift | grep -oE '[0-9][^"]*' || true)" - current="$(git show "origin/${{ github.base_ref }}:Package.swift" \ - | grep -oE 'let releaseTag = "wallet-bindings-v[0-9.]+[^"]*"' | grep -oE '[0-9][^"]*' || true)" - if [ -z "$incoming" ]; then - echo "::error::pin PR carries no parsable releaseTag" + # Single comparison implementation (scripts/release/semver.sh), + # comment-stripped exactly-one extraction, annotation-safe + # echoes — shared with the release scripts. + if [[ ! "$BASE_REF" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then + echo "::error::unexpected base branch" exit 1 fi - if [ -n "$current" ] \ - && [ "$(printf '%s\n%s\n' "$incoming" "$current" | sort -V | head -1)" != "$incoming" ]; then - echo "::error::pin PR would downgrade the release from $current to $incoming" - exit 1 + if ! git diff --name-only "origin/${BASE_REF}...HEAD" | grep -q '^Package.swift$'; then + echo "Package.swift untouched; nothing to check" + exit 0 fi - echo "pin order ok (incoming $incoming, current ${current:-none})" + scripts/release/check-pin-order.sh "$BASE_REF" fmt: name: Format diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 99f1aa8..b9b88c7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -204,8 +204,10 @@ jobs: Package.swift # Both substitutions must actually land; a no-op sed on a drifted # Package.swift must fail the release rather than skip the pin. - pin_tag_lines="$(grep -cE "^[[:space:]]*let releaseTag = \"$TAG\"[[:space:]]*(//.*)?$" Package.swift || true)" - pin_sum_lines="$(grep -cE "^[[:space:]]*checksum: \"$xcsum\"[[:space:]]*(//.*)?$" Package.swift || true)" + # Fixed strings, not EREs: build-metadata tags contain '+', + # which an interpolated pattern would treat as a quantifier. + pin_tag_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "let releaseTag = \"$TAG\"" || true)" + pin_sum_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "checksum: \"$xcsum\"" || true)" if [ "$pin_tag_lines" != "1" ] || [ "$pin_sum_lines" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh new file mode 100755 index 0000000..67e4b68 --- /dev/null +++ b/scripts/release/check-pin-order.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Merge-time pin-order gate for checksum-pin pull requests. Refuses a +# pin PR whose releaseTag would not advance the release currently +# pinned on the default branch (same-version repairs are manual: the +# rewind guard in open-spm-pr.sh refuses to create them). +# +# Usage: check-pin-order.sh (run from the repo root, in +# the PR checkout; LC_ALL=C is enforced internally). +set -euo pipefail +export LC_ALL=C + +BASE_BRANCH="${1:?base branch required}" +if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then + echo "::error::unexpected base branch: ${BASE_BRANCH}" + exit 1 +fi + +esc() { + # Strip control and non-ASCII bytes (pin tags are ASCII), then + # %-escape for workflow-command safety. + local s + s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" + s="${s//%/%25}" + printf '%s' "$s" +} + +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/semver.sh" + +# Anchored, comment-stripped, exactly-one extraction — the same shape +# the release scripts use on the default branch. +strip_comments() { sed 's#//.*$##'; } + +incoming_matches="$(strip_comments < Package.swift \ + | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" +if [ "${incoming_matches}" != "1" ]; then + echo "::error::expected exactly one releaseTag assignment on the PR head, found ${incoming_matches}" + exit 1 +fi +incoming_tag="$(strip_comments < Package.swift \ + | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" +incoming_version="${incoming_tag#wallet-bindings-v}" +if [[ ! "${incoming_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::unparseable incoming pin version: $(esc "${incoming_version}")" + exit 1 +fi + +origin_swift="$(git show "origin/${BASE_BRANCH}:Package.swift" 2>/dev/null)" \ + || { echo "::error::cannot read origin/${BASE_BRANCH}:Package.swift"; exit 1; } +origin_code="$(printf '%s\n' "${origin_swift}" | strip_comments)" +current_matches="$(printf '%s\n' "${origin_code}" \ + | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" +if [ "${current_matches}" = "0" ]; then + echo "no pin on ${BASE_BRANCH}; any pin order is acceptable" + exit 0 +fi +if [ "${current_matches}" != "1" ]; then + echo "::error::expected at most one releaseTag assignment on ${BASE_BRANCH}, found ${current_matches}" + exit 1 +fi +current_tag="$(printf '%s\n' "${origin_code}" \ + | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" +current_version="${current_tag#wallet-bindings-v}" +if [[ ! "${current_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::unparseable current pin version: $(esc "${current_version}")" + exit 1 +fi + +cmp="$(semver_cmp "${incoming_version}" "${current_version}")" +if [[ ! "${cmp}" =~ ^-?[012]$ ]]; then + echo "::error::semver comparison failed for ${incoming_version} against ${current_version}" + exit 1 +fi +# Only a strictly newer release advances the pin; equal or lower +# (rewind or same-version repair) is refused at merge time. +if [ "${cmp}" -le 0 ]; then + echo "::error::pin PR would not advance the release (incoming ${incoming_tag}, current ${current_tag})" + exit 1 +fi +echo "pin order ok (incoming ${incoming_tag}, current ${current_tag})" diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 7bbae85..4526c34 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -17,7 +17,7 @@ DEFAULT_BRANCH="${3:?DEFAULT_BRANCH required}" esc() { local s - s="$(printf '%s' "$1" | tr -d '\000-\037\177')" + s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" s="${s//%/%25}" s="${s//$'\r'/%0D}" s="${s//$'\n'/%0A}" @@ -43,7 +43,11 @@ origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } # Only real code lines constitute the pin: comment lines are ignored so # a decoy literal in a comment cannot flip the guard's verdict. -origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//')" +origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//' || true)" +if [ -z "${origin_code}" ]; then + echo "::error::origin/${DEFAULT_BRANCH}:Package.swift carries no code lines" + exit 1 +fi pin_tag_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^[[:space:]]*let releaseTag = "wallet-bindings-v[^"]*"$' || true)" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 96e04bf..2ba68bb 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -1,6 +1,11 @@ #!/usr/bin/env bash # LC_ALL=C pins collation for the semver string comparisons below. export LC_ALL=C + +# Shared semver precedence comparator (single source of truth, also +# used by check-pin-order.sh). +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/semver.sh" # Open (or reuse) the SPM checksum-pin pull request for a release tag. # # Branch protection on the default branch rejects direct pushes (GH013), @@ -29,7 +34,7 @@ esc() { # Strip C0 control bytes (incl. ESC) so extracted repo content cannot # spoof the log with terminal escapes, then %-escape the rest. local s - s="$(printf '%s' "$1" | tr -d '\000-\037\177')" + s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" s="${s//%/%25}" s="${s//$'\r'/%0D}" s="${s//$'\n'/%0A}" @@ -117,10 +122,13 @@ git checkout -B "${BRANCH}" git add Package.swift # Both substitutions must be present, on every path: anything else means # the sed no-op'd or corrupted the file; fail closed. -# Anchored, exactly-once verification: substring greps would also match -# a drifted assignment plus a comment carrying the canonical literal. -pin_tag_lines="$(grep -cE "^[[:space:]]*let releaseTag = \"${TAG}\"[[:space:]]*(//.*)?$" Package.swift || true)" -pin_sum_lines="$(grep -cE "^[[:space:]]*checksum: \"${XCSUM}\"[[:space:]]*(//.*)?$" Package.swift || true)" +# Anchored, exactly-once verification with fixed strings (TAG may +# contain ERE metacharacters such as '+'): strip comments and trailing +# whitespace, then count whole-line matches. +expected_tag_line="let releaseTag = \"${TAG}\"" +expected_sum_line="checksum: \"${XCSUM}\"" +pin_tag_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "${expected_tag_line}" || true)" +pin_sum_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "${expected_sum_line}" || true)" if [ "${pin_tag_lines}" != "1" ] || [ "${pin_sum_lines}" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 @@ -145,9 +153,16 @@ fi # active pins are the normal forward-release state and proceed. origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } -# Only real code lines constitute the pin: comment lines are ignored so -# a decoy literal in a comment cannot flip the guard's verdict. +# Only real code lines constitute the pin: block comments, line +# comments, and their decoy literals are all ignored. +origin_swift="$(printf '%s' "${origin_swift}" | perl -0777 -pe 's{\Q/*\E.*?\*/}{}gs')" origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//' || true)" +tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v' || true)" +sum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" +if [ "${tag_assignments}" != "1" ] || [ "${sum_assignments}" != "1" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries ${tag_assignments} releaseTag and ${sum_assignments} checksum assignments; expected exactly one of each" + exit 1 +fi origin_pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ | grep -oE 'v[0-9][^"]*' || true)" @@ -167,59 +182,6 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" exit 1 fi - # Semver precedence: numeric triple (10# forces decimal, so leading - # zeros cannot octal-flip the verdict), then identifier-wise - # pre-release comparison (a pre-release is less than the final; - # numeric identifiers are lower than alphanumeric; fewer identifiers - # are lower). - semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 - # A final release outranks any pre-release of the same triple. - if [ -z "$1" ] && [ -n "$2" ]; then echo 1; return; fi - if [ -n "$1" ] && [ -z "$2" ]; then echo -1; return; fi - if [ -z "$1" ] && [ -z "$2" ]; then echo 0; return; fi - local -a A B - IFS='.' read -ra A <<< "${1}" - IFS='.' read -ra B <<< "${2}" - local i n - n=$(( ${#A[@]} > ${#B[@]} ? ${#A[@]} : ${#B[@]} )) - for ((i = 0; i < n; i++)); do - local x="${A[i]:-}" y="${B[i]:-}" - if [ -z "${x}" ] && [ -z "${y}" ]; then continue; fi - if [ -z "${x}" ]; then echo -1; return; fi - if [ -z "${y}" ]; then echo 1; return; fi - if [[ "${x}" =~ ^[0-9]{1,18}$ ]] && [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then - [ "$((10#${x}))" -lt "$((10#${y}))" ] && { echo -1; return; } - [ "$((10#${x}))" -gt "$((10#${y}))" ] && { echo 1; return; } - elif [[ "${x}" =~ ^[0-9]{1,18}$ ]]; then - echo -1; return - elif [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then - echo 1; return - elif [[ "${x}" < "${y}" ]]; then - echo -1; return - elif [[ "${x}" > "${y}" ]]; then - echo 1; return - fi - done - echo 0 - } - semver_cmp() { # <0 if $1 < $2, 0 if equal, >0 if $1 > $2 - local a="${1%%-*}" b="${2%%-*}" - local ap="" bp="" - [[ "$1" == *-* ]] && ap="${1#*-}" - [[ "$2" == *-* ]] && bp="${2#*-}" - # Build metadata is excluded from precedence: strip it from both. - ap="${ap%%+*}" - bp="${bp%%+*}" - local -a A B - read -ra A <<< "${a//[^0-9]/ }" - read -ra B <<< "${b//[^0-9]/ }" - local i - for i in 0 1 2; do - [ "$((10#${A[i]:-0}))" -lt "$((10#${B[i]:-0}))" ] && { echo -1; return; } - [ "$((10#${A[i]:-0}))" -gt "$((10#${B[i]:-0}))" ] && { echo 1; return; } - done - semver_prerelease_cmp "${ap}" "${bp}" - } cmp="$(semver_cmp "${VERSION}" "${origin_version}")" if [[ ! "${cmp}" =~ ^-?[012]$ ]]; then echo "::error::semver comparison failed for ${VERSION} against ${origin_version}" diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh new file mode 100755 index 0000000..0862252 --- /dev/null +++ b/scripts/release/semver.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Shared semver precedence comparator. Sourced by open-spm-pr.sh and +# check-pin-order.sh so every pin-order verdict uses one implementation. +# Requires LC_ALL=C for the raw-byte identifier comparisons. + +# semver_prerelease_cmp : identifier-wise compare of the +# pre-release parts (without the leading '-'). A final release outranks +# any pre-release of the same triple (the empty part is the final). +semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 + if [ -z "$1" ] && [ -n "$2" ]; then echo 1; return; fi + if [ -n "$1" ] && [ -z "$2" ]; then echo -1; return; fi + if [ -z "$1" ] && [ -z "$2" ]; then echo 0; return; fi + local -a A B + IFS='.' read -ra A <<< "${1}" + IFS='.' read -ra B <<< "${2}" + local i n + n=$(( ${#A[@]} > ${#B[@]} ? ${#A[@]} : ${#B[@]} )) + for ((i = 0; i < n; i++)); do + local x="${A[i]:-}" y="${B[i]:-}" + if [ -z "${x}" ] && [ -z "${y}" ]; then continue; fi + if [ -z "${x}" ]; then echo -1; return; fi + if [ -z "${y}" ]; then echo 1; return; fi + # Numeric identifiers are lower than alphanumeric ones; numerics + # are digit-capped at 18 by the callers' validation regexes, so the + # decimal arithmetic cannot overflow. + if [[ "${x}" =~ ^[0-9]{1,18}$ ]] && [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then + [ "$((10#${x}))" -lt "$((10#${y}))" ] && { echo -1; return; } + [ "$((10#${x}))" -gt "$((10#${y}))" ] && { echo 1; return; } + elif [[ "${x}" =~ ^[0-9]{1,18}$ ]]; then + echo -1; return + elif [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then + echo 1; return + elif [[ "${x}" < "${y}" ]]; then + echo -1; return + elif [[ "${x}" > "${y}" ]]; then + echo 1; return + fi + done + echo 0 +} + +# semver_cmp : echoes -1|0|1 per semver precedence. Build +# metadata (+suffix) is excluded from precedence. +semver_cmp() { # <0 if $1 < $2, 0 if equal, >0 if $1 > $2 + local a="${1%%-*}" b="${2%%-*}" + local ap="" bp="" + [[ "$1" == *-* ]] && ap="${1#*-}" + [[ "$2" == *-* ]] && bp="${2#*-}" + # Build metadata is excluded from precedence: strip it from both. + ap="${ap%%+*}" + bp="${bp%%+*}" + local -a A B + read -ra A <<< "${a//[^0-9]/ }" + read -ra B <<< "${b//[^0-9]/ }" + local i + for i in 0 1 2; do + [ "$((10#${A[i]:-0}))" -lt "$((10#${B[i]:-0}))" ] && { echo -1; return; } + [ "$((10#${A[i]:-0}))" -gt "$((10#${B[i]:-0}))" ] && { echo 1; return; } + done + semver_prerelease_cmp "${ap}" "${bp}" +} diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index a6ba53c..c20b53f 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -57,7 +57,11 @@ case "$1 $2" in "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "rev-parse --is-shallow-repository") cat "${CASE_DIR}/is_shallow" ;; "rev-parse HEAD") cat "${CASE_DIR}/head_commit" ;; - "show origin/"*) cat "${CASE_DIR}/origin_swift" ;; + "show origin/"*) + if [ "$(cat "${CASE_DIR}/show_fails" 2>/dev/null || echo 0)" = "1" ]; then + exit 1 + fi + cat "${CASE_DIR}/origin_swift" ;; rev-parse\ refs/tags/*) cat "${CASE_DIR}/tag_commit" ;; "checkout -B") cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" @@ -400,7 +404,8 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 # 29b. Build metadata is excluded from precedence: an origin pin of # 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. -set_fixtures 0 1 "${FULLY_PINNED}" pr.none +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... +checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -408,11 +413,14 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472 bash "${UNDER_TEST}" wallet-bindings-v1.2.3+meta.a 1.2.3+meta.a "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "build-metadata equal precedence refused"; else bad "build-metadata equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations # 29c. Origin pin without metadata vs incoming with metadata: equal # precedence -> refuse. +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta" // ... +checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -420,13 +428,15 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e bash "${UNDER_TEST}" wallet-bindings-v1.2.3+meta 1.2.3+meta "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations # 29d. Huge numeric prerelease identifiers (20 digits) compare as # alphanumeric under the 18-digit cap: an origin pin of rc<20 digits> # still outranks incoming rc.2 -> refused, no arithmetic wrap. -set_fixtures 0 1 "${FULLY_PINNED}" pr.none +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-2" // ... +checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3-18446744073709551617"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -434,6 +444,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3-18446744073709551617"\nchecksum bash "${UNDER_TEST}" wallet-bindings-v1.2.3-2 1.2.3-2 "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "huge numeric prerelease refused without wrap"; else bad "huge numeric prerelease refused without wrap" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" @@ -471,6 +482,31 @@ rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +# 33b. git show fails -> open-spm-pr.sh fails closed (no silent skip). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf '1' > "${TMP}/show_fails" +: > "${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=$? +if [ "${rc}" = "1" ]; then ok "git show failure fails closed"; else bad "git show failure fails closed" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations +printf '0' > "${TMP}/show_fails" +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 33c. Comment decoys claiming THIS tag+checksum while the real code pin +# differs -> comment stripping makes the script refuse (fail closed). +printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + # 33. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the guard refuse (fail closed). printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -482,6 +518,87 @@ rc=$? if [ "${rc}" = "1" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +# 34. Guard: zero releaseTag assignments -> refuse. +printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard refuses zero assignments"; else bad "guard refuses zero assignments" "exit ${rc}"; fi + +# 35. Guard: two releaseTag assignments -> refuse. +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard refuses duplicate assignments"; else bad "guard refuses duplicate assignments" "exit ${rc}"; fi + +# 36. Guard: invalid checksum -> refuse. +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "nothex" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard rejects invalid checksum"; else bad "guard rejects invalid checksum" "exit ${rc}"; fi + +# 37. Guard: git show failure -> fail closed. +printf '1' > "${TMP}/show_fails" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard fails closed on git show failure"; else bad "guard fails closed on git show failure" "exit ${rc}"; fi +printf '0' > "${TMP}/show_fails" +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 38. Pin-order script: upgrade allows, downgrade refuses, same refuses. +ORDER="${SCRIPT_DIR}/check-pin-order.sh" +printf 'let releaseTag = "wallet-bindings-v1.2.3+meta"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "pin order allows upgrade"; else bad "pin order allows upgrade" "exit ${rc}"; fi + +printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order refuses downgrade"; else bad "pin order refuses downgrade" "exit ${rc}"; fi + +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order refuses same version"; else bad "pin order refuses same version" "exit ${rc}"; fi +printf 'placeholder\n' > "${STUBS}/repo/Package.swift" + +# 39. semver.sh unit checks (sourced directly). +# shellcheck source=/dev/null +semver_tests="${SCRIPT_DIR}/semver.sh" +semver_cmp_check() { + # shellcheck disable=SC1090 # semver.sh is linted directly + ( source "${semver_tests}"; semver_cmp "$1" "$2" ) +} +if [ "$(semver_cmp_check "1.2.3" "1.2.3-rc.1")" = "1" ] \ + && [ "$(semver_cmp_check "1.2.3-rc.1" "1.2.3")" = "-1" ] \ + && [ "$(semver_cmp_check "1.2.3+meta.a" "1.2.3+meta.b")" = "0" ] \ + && [ "$(semver_cmp_check "1.2.3" "1.2.3+meta")" = "0" ] \ + && [ "$(semver_cmp_check "1.2.3-2" "1.2.3-18446744073709551617")" = "-1" ] \ + && [ "$(semver_cmp_check "1.02.3" "1.2.3")" = "0" ]; then + ok "semver comparator unit checks" +else + bad "semver comparator unit checks" "unexpected comparator output" +fi + # Static check: the TAG regex must be byte-identical in every copy # (three occurrences in release.yml, one in the script under test). TAG_REGEX='^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$' From cbf039762043998948819331ac849cceae20c7e2 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 19:04:55 +0100 Subject: [PATCH 17/53] ci: shared pin helpers, block-comment strip, latest flag --- .github/workflows/ci.yml | 14 +++--- .github/workflows/release.yml | 7 ++- scripts/release/check-pin-order.sh | 30 ++++--------- scripts/release/guard-release-refresh.sh | 54 ++++++++++++------------ scripts/release/open-spm-pr.sh | 23 +++------- scripts/release/pinlib.sh | 31 ++++++++++++++ scripts/release/semver.sh | 22 ++++++---- 7 files changed, 99 insertions(+), 82 deletions(-) create mode 100755 scripts/release/pinlib.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 456a1bb..d48926e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 # Pinned to the MSRV so rustfmt matches the version clippy/test use. - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: @@ -69,7 +69,7 @@ jobs: matrix: features: ["--no-default-features", "--no-default-features --features node", "--no-default-features --features indexer", "--no-default-features --features wallet", "--no-default-features --features crypto", "--all-features"] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: components: clippy @@ -87,7 +87,7 @@ jobs: matrix: features: ["--no-default-features", "--no-default-features --features node", "--no-default-features --features indexer", "--no-default-features --features wallet", "--no-default-features --features crypto", "--all-features"] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 with: @@ -112,7 +112,7 @@ jobs: # mintlayer-core git checkouts (same reason mintlayer-core's own # build.yml does this). run: echo "CARGO_HOME=C:\crg" >> "$GITHUB_ENV" - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 with: @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - run: cargo doc --all-features --locked --no-deps @@ -139,7 +139,7 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - uses: actions/setup-node@v4 @@ -159,5 +159,5 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - run: ./scripts/check-license.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b9b88c7..8e3fea9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -262,13 +262,18 @@ jobs: dist/SHA256SUMS \ dist/swift-sources/MintlayerWalletBindings.swift else + # Pre-release versions must not claim the GitHub "Latest" + # badge; only final releases do. + latest_flag="--latest" + case "$VERSION" in *-*|*+*) latest_flag="--latest=false" ;; esac gh release create "$TAG" \ dist/mintlayer-wallet-bindings-*.aar \ dist/MintlayerWalletBindings.xcframework.zip \ dist/SHA256SUMS \ dist/swift-sources/MintlayerWalletBindings.swift \ --title "Mobile bindings $TAG" \ - --notes "$notes" + --notes "$notes" \ + "$latest_flag" fi - name: Open the SPM checksum-pin PR diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 67e4b68..cb6cd74 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -9,35 +9,23 @@ set -euo pipefail export LC_ALL=C -BASE_BRANCH="${1:?base branch required}" -if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then - echo "::error::unexpected base branch: ${BASE_BRANCH}" - exit 1 -fi - -esc() { - # Strip control and non-ASCII bytes (pin tags are ASCII), then - # %-escape for workflow-command safety. - local s - s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" - s="${s//%/%25}" - printf '%s' "$s" -} - +# Shared helpers (esc, comment stripping) and the semver comparator. +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/pinlib.sh" # shellcheck disable=SC1091 # sourced next to this file, linted directly source "${BASH_SOURCE[0]%/*}/semver.sh" -# Anchored, comment-stripped, exactly-one extraction — the same shape -# the release scripts use on the default branch. -strip_comments() { sed 's#//.*$##'; } +BASE_BRANCH="${1:?base branch required}" +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/semver.sh" -incoming_matches="$(strip_comments < Package.swift \ +incoming_matches="$(strip_swift_comments "$(cat Package.swift)" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" if [ "${incoming_matches}" != "1" ]; then echo "::error::expected exactly one releaseTag assignment on the PR head, found ${incoming_matches}" exit 1 fi -incoming_tag="$(strip_comments < Package.swift \ +incoming_tag="$(strip_swift_comments "$(cat Package.swift)" \ | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" incoming_version="${incoming_tag#wallet-bindings-v}" if [[ ! "${incoming_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then @@ -47,7 +35,7 @@ fi origin_swift="$(git show "origin/${BASE_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${BASE_BRANCH}:Package.swift"; exit 1; } -origin_code="$(printf '%s\n' "${origin_swift}" | strip_comments)" +origin_code="$(strip_swift_comments "${origin_swift}")" current_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" if [ "${current_matches}" = "0" ]; then diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 4526c34..e5ec8f6 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash # LC_ALL=C pins collation for the ASCII-range validations below. export LC_ALL=C + +# Shared helpers (esc, comment stripping). +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/pinlib.sh" # Refuse to clobber published release assets when the default branch # already pins THIS release and the rebuilt artifacts are not # bit-reproducible: publishing mismatched artifacts would desync SPM @@ -15,15 +19,6 @@ TAG="${1:?TAG required}" XCSUM="${2:?XCSUM required}" DEFAULT_BRANCH="${3:?DEFAULT_BRANCH required}" -esc() { - local s - s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" - s="${s//%/%25}" - s="${s//$'\r'/%0D}" - s="${s//$'\n'/%0A}" - printf '%s' "$s" -} - # Mirror the workflow's validation so direct invocations fail closed. if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" @@ -39,36 +34,39 @@ if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ exit 1 fi +# Only real code lines constitute the pin: block comments, line +# comments, and their decoy literals are all ignored (shared stripper). origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } -# Only real code lines constitute the pin: comment lines are ignored so -# a decoy literal in a comment cannot flip the guard's verdict. -origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//' || true)" +origin_code="$(strip_swift_comments "${origin_swift}")" if [ -z "${origin_code}" ]; then echo "::error::origin/${DEFAULT_BRANCH}:Package.swift carries no code lines" exit 1 fi -pin_tag_matches="$(printf '%s\n' "${origin_code}" \ - | grep -cE '^[[:space:]]*let releaseTag = "wallet-bindings-v[^"]*"$' || true)" -if [ "${pin_tag_matches}" != "1" ]; then - echo "::error::expected exactly one releaseTag assignment on ${DEFAULT_BRANCH}, found ${pin_tag_matches}" - exit 1 -fi -pin_sum_matches="$(printf '%s\n' "${origin_code}" \ - | grep -cE '^[[:space:]]*checksum: "[0-9a-f]{64}"$' || true)" -if [ "${pin_sum_matches}" != "1" ]; then - echo "::error::expected exactly one checksum assignment on ${DEFAULT_BRANCH}, found ${pin_sum_matches}" +# Exactly one releaseTag and one checksum assignment must exist (any +# version); anything else is a mangled pin state -> fail closed. +tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v' || true)" +checksum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" +if [ "${tag_assignments}" != "1" ] || [ "${checksum_assignments}" != "1" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries ${tag_assignments} releaseTag and ${checksum_assignments} checksum assignments; expected exactly one of each" exit 1 fi +# Fixed-string whole-line comparison (TAG may contain ERE metacharacters +# such as '+'). pin_tag="$(printf '%s\n' "${origin_code}" \ - | grep -E '^[[:space:]]*let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" + | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" pin_sum="$(printf '%s\n' "${origin_code}" \ - | grep -E '^[[:space:]]*checksum: ' | grep -oE '[0-9a-f]{64}')" - -# Only a pin for THIS release constrains the refresh; identical -# checksums make the refresh a harmless no-op. -if [ "${pin_tag}" = "${TAG}" ] && [ "${pin_sum}" != "${XCSUM}" ]; then + | grep -E '^checksum: ' | grep -oE '[0-9a-f]{64}')" +if [ "${pin_tag}" = "${TAG}" ]; then + if [ "${pin_sum}" = "${XCSUM}" ]; then + echo "release ${TAG} is already pinned on ${DEFAULT_BRANCH}; asset refresh is a no-op" + exit 0 + fi echo "::error::rebuilt artifacts (checksum $(esc "${XCSUM}")) do not match the pin merged on $(esc "${DEFAULT_BRANCH}") ($(esc "${pin_sum}")); release assets left untouched - repair manually" exit 1 fi +# A pin for a DIFFERENT release is the normal forward-release state: +# open-spm-pr.sh refuses to create rewind pin PRs, so no pin constrains +# this tag and the asset refresh is safe. +echo "no pin for ${TAG} on ${DEFAULT_BRANCH}; asset refresh allowed" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 2ba68bb..2422fde 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -2,8 +2,10 @@ # LC_ALL=C pins collation for the semver string comparisons below. export LC_ALL=C -# Shared semver precedence comparator (single source of truth, also -# used by check-pin-order.sh). +# Shared helpers, and the semver precedence comparator (single sources +# of truth, also used by check-pin-order.sh and guard-release-refresh.sh). +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/pinlib.sh" # shellcheck disable=SC1091 # sourced next to this file, linted directly source "${BASH_SOURCE[0]%/*}/semver.sh" # Open (or reuse) the SPM checksum-pin pull request for a release tag. @@ -29,18 +31,6 @@ DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" BRANCH="pin-spm-checksum-${VERSION}" -# Workflow-command values need %-/CR-/LF-escaping to stay one annotation. -esc() { - # Strip C0 control bytes (incl. ESC) so extracted repo content cannot - # spoof the log with terminal escapes, then %-escape the rest. - local s - s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" - s="${s//%/%25}" - s="${s//$'\r'/%0D}" - s="${s//$'\n'/%0A}" - printf '%s' "$s" -} - # Mirror the workflow's validation so direct/manual invocations get the # same fail-closed guarantees as the release run. if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then @@ -155,8 +145,7 @@ origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" || { echo "::error::cannot read origin/${DEFAULT_BRANCH}:Package.swift"; exit 1; } # Only real code lines constitute the pin: block comments, line # comments, and their decoy literals are all ignored. -origin_swift="$(printf '%s' "${origin_swift}" | perl -0777 -pe 's{\Q/*\E.*?\*/}{}gs')" -origin_code="$(printf '%s\n' "${origin_swift}" | grep -v '^[[:space:]]*//' || true)" +origin_code="$(strip_swift_comments "${origin_swift}")" tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v' || true)" sum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" if [ "${tag_assignments}" != "1" ] || [ "${sum_assignments}" != "1" ]; then @@ -167,7 +156,7 @@ origin_pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ | grep -oE 'v[0-9][^"]*' || true)" origin_pin_sum_raw="$(printf '%s\n' "${origin_code}" \ - | grep -oE 'checksum: "[^"]*"' | grep -oE '"[^"]*"' | tr -d '"' | head -1 || true)" + | grep -E '^checksum: "' | head -1 | grep -oE '"[^"]*"' | tr -d '"' || true)" origin_pin_sum="$(printf '%s\n' "${origin_pin_sum_raw}" \ | grep -oE '^[0-9a-f]{64}$' || true)" origin_pin_active=0 diff --git a/scripts/release/pinlib.sh b/scripts/release/pinlib.sh new file mode 100755 index 0000000..a3480be --- /dev/null +++ b/scripts/release/pinlib.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# Shared helpers for the release pin scripts (sourced, not executed). +# Callers export LC_ALL=C for raw-byte comparisons. + +esc() { + # Strip control and non-ASCII bytes (pin tags are ASCII-only, so this + # is lossless for legitimate values and kills C0/C1 terminal escapes), + # then %-escape for workflow-command safety. + local s + s="$(printf '%s' "$1" | tr -d '\000-\037\177\200-\377')" + s="${s//%/%25}" + printf '%s' "$s" +} + +# Swift comment removal for pin verification: block comments first +# (perl -0777 so multi-line comments collapse), then whole line +# comments. A decoy literal inside any comment is invisible afterwards. +strip_swift_comments() { + printf '%s' "$1" \ + | perl -0777 -pe 's{/\*.*?\*/}{}gs' \ + | grep -v '^[[:space:]]*//' \ + || true +} + +# Count whole-line assignments after comment stripping and trailing +# whitespace removal. Usage: count_line +count_exact_line() { + local -n _content="$1" + printf '%s\n' "${_content}" | sed 's:[[:space:]]*//.*$::' | sed 's:[[:space:]]*$://' \ + | grep -cF -x -- "$2" || true +} diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh index 0862252..187263a 100755 --- a/scripts/release/semver.sh +++ b/scripts/release/semver.sh @@ -20,15 +20,21 @@ semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 if [ -z "${x}" ] && [ -z "${y}" ]; then continue; fi if [ -z "${x}" ]; then echo -1; return; fi if [ -z "${y}" ]; then echo 1; return; fi - # Numeric identifiers are lower than alphanumeric ones; numerics - # are digit-capped at 18 by the callers' validation regexes, so the - # decimal arithmetic cannot overflow. - if [[ "${x}" =~ ^[0-9]{1,18}$ ]] && [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then - [ "$((10#${x}))" -lt "$((10#${y}))" ] && { echo -1; return; } - [ "$((10#${x}))" -gt "$((10#${y}))" ] && { echo 1; return; } - elif [[ "${x}" =~ ^[0-9]{1,18}$ ]]; then + # Numeric identifiers are lower than alphanumeric ones. Two numeric + # identifiers compare by digit length then bytes (semver forbids + # leading zeros, so this equals numeric order for any length — no + # arithmetic, no overflow). + if [[ "${x}" =~ ^[0-9]+$ ]] && [[ "${y}" =~ ^[0-9]+$ ]]; then + if [ "${#x}" -ne "${#y}" ]; then + [ "${#x}" -lt "${#y}" ] && { echo -1; return; } + [ "${#x}" -gt "${#y}" ] && { echo 1; return; } + fi + [[ "${x}" < "${y}" ]] && { echo -1; return; } + [[ "${x}" > "${y}" ]] && { echo 1; return; } + continue + elif [[ "${x}" =~ ^[0-9]+$ ]]; then echo -1; return - elif [[ "${y}" =~ ^[0-9]{1,18}$ ]]; then + elif [[ "${y}" =~ ^[0-9]+$ ]]; then echo 1; return elif [[ "${x}" < "${y}" ]]; then echo -1; return From 5622bb2b90f1bc57c1d62eb30216c808132bab68 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 19:22:10 +0100 Subject: [PATCH 18/53] ci: indent-tolerant pin verification across the pipeline --- .github/workflows/ci.yml | 16 +++++++++++++++- .github/workflows/release.yml | 7 +++++-- scripts/release/check-pin-order.sh | 7 +++++-- scripts/release/open-spm-pr.sh | 4 ++-- scripts/release/pinlib.sh | 20 ++++++++------------ scripts/release/semver.sh | 17 ++++++++++------- scripts/release/test-open-spm-pr.sh | 25 +++++++++++++------------ 7 files changed, 58 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d48926e..29eadd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,8 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false # Pinned to the MSRV so rustfmt matches the version clippy/test use. - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: @@ -70,6 +72,8 @@ jobs: features: ["--no-default-features", "--no-default-features --features node", "--no-default-features --features indexer", "--no-default-features --features wallet", "--no-default-features --features crypto", "--all-features"] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 with: components: clippy @@ -88,6 +92,8 @@ jobs: features: ["--no-default-features", "--no-default-features --features node", "--no-default-features --features indexer", "--no-default-features --features wallet", "--no-default-features --features crypto", "--all-features"] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 with: @@ -113,6 +119,8 @@ jobs: # build.yml does this). run: echo "CARGO_HOME=C:\crg" >> "$GITHUB_ENV" - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 with: @@ -126,6 +134,8 @@ jobs: timeout-minutes: 30 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - run: cargo doc --all-features --locked --no-deps @@ -140,9 +150,11 @@ jobs: contents: read steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@60edb5dd545a736178b549f63364a802f016e4f3 # v4 with: node-version: 20 cache: npm @@ -160,4 +172,6 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false - run: ./scripts/check-license.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e3fea9..3c60322 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -206,8 +206,11 @@ jobs: # Package.swift must fail the release rather than skip the pin. # Fixed strings, not EREs: build-metadata tags contain '+', # which an interpolated pattern would treat as a quantifier. - pin_tag_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "let releaseTag = \"$TAG\"" || true)" - pin_sum_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "checksum: \"$xcsum\"" || true)" + # Comments, leading whitespace, and trailing whitespace are + # stripped so the whole-line counts match the committed shape + # (the checksum assignment is indented 12 spaces). + pin_tag_lines="$(sed 's#//.*$##' Package.swift | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -cF -x -- "let releaseTag = \"$TAG\"" || true)" + pin_sum_lines="$(sed 's#//.*$##' Package.swift | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -cF -x -- "checksum: \"$xcsum\"" || true)" if [ "$pin_tag_lines" != "1" ] || [ "$pin_sum_lines" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index cb6cd74..e43b6a4 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -16,8 +16,11 @@ source "${BASH_SOURCE[0]%/*}/pinlib.sh" source "${BASH_SOURCE[0]%/*}/semver.sh" BASE_BRANCH="${1:?base branch required}" -# shellcheck disable=SC1091 # sourced next to this file, linted directly -source "${BASH_SOURCE[0]%/*}/semver.sh" +if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ + || [[ "${BASE_BRANCH}" == pin-spm-checksum-* ]]; then + echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" + exit 1 +fi incoming_matches="$(strip_swift_comments "$(cat Package.swift)" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 2422fde..8f2d6d9 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -117,8 +117,8 @@ git add Package.swift # whitespace, then count whole-line matches. expected_tag_line="let releaseTag = \"${TAG}\"" expected_sum_line="checksum: \"${XCSUM}\"" -pin_tag_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "${expected_tag_line}" || true)" -pin_sum_lines="$(sed 's#//.*$##' Package.swift | sed 's/[[:space:]]*$//' | grep -cF -x -- "${expected_sum_line}" || true)" +pin_tag_lines="$(strip_swift_comments "$(cat Package.swift)" | grep -cF -x -- "${expected_tag_line}" || true)" +pin_sum_lines="$(strip_swift_comments "$(cat Package.swift)" | grep -cF -x -- "${expected_sum_line}" || true)" if [ "${pin_tag_lines}" != "1" ] || [ "${pin_sum_lines}" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 diff --git a/scripts/release/pinlib.sh b/scripts/release/pinlib.sh index a3480be..3892dc5 100755 --- a/scripts/release/pinlib.sh +++ b/scripts/release/pinlib.sh @@ -12,20 +12,16 @@ esc() { printf '%s' "$s" } -# Swift comment removal for pin verification: block comments first -# (perl -0777 so multi-line comments collapse), then whole line -# comments. A decoy literal inside any comment is invisible afterwards. +# Swift code-line extraction for pin verification: block comments first +# (perl -0777 so multi-line comments collapse), then line comments, then +# leading/trailing whitespace and blank lines — the emitted lines are +# exactly the assignment lines, normalized to column 0. A decoy literal +# inside any comment is invisible afterwards. strip_swift_comments() { printf '%s' "$1" \ | perl -0777 -pe 's{/\*.*?\*/}{}gs' \ - | grep -v '^[[:space:]]*//' \ + | sed 's://.*$::' \ + | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' \ + | grep -v '^$' \ || true } - -# Count whole-line assignments after comment stripping and trailing -# whitespace removal. Usage: count_line -count_exact_line() { - local -n _content="$1" - printf '%s\n' "${_content}" | sed 's:[[:space:]]*//.*$::' | sed 's:[[:space:]]*$://' \ - | grep -cF -x -- "$2" || true -} diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh index 187263a..4d29f5c 100755 --- a/scripts/release/semver.sh +++ b/scripts/release/semver.sh @@ -46,15 +46,18 @@ semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 } # semver_cmp : echoes -1|0|1 per semver precedence. Build -# metadata (+suffix) is excluded from precedence. +# metadata (+suffix) is excluded from precedence. Accepted deviation: +# the callers' validation regexes permit leading zeros in numeric +# components; the 10# arithmetic below compares them decimally, so +# '1.02.3' equals '1.2.3' rather than being rejected. semver_cmp() { # <0 if $1 < $2, 0 if equal, >0 if $1 > $2 - local a="${1%%-*}" b="${2%%-*}" + # Build metadata is excluded from precedence: strip it FIRST, then + # take the pre-release from the stripped half (a '+' build suffix may + # itself contain '-'). + local a="${1%%+*}" b="${2%%+*}" local ap="" bp="" - [[ "$1" == *-* ]] && ap="${1#*-}" - [[ "$2" == *-* ]] && bp="${2#*-}" - # Build metadata is excluded from precedence: strip it from both. - ap="${ap%%+*}" - bp="${bp%%+*}" + [[ "$a" == *-* ]] && ap="${a#*-}" + [[ "$b" == *-* ]] && bp="${b#*-}" local -a A B read -ra A <<< "${a//[^0-9]/ }" read -ra B <<< "${b//[^0-9]/ }" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index c20b53f..1fe0b57 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -87,12 +87,12 @@ EOF chmod +x "${STUBS}/git" "${STUBS}/gh" XCSUM="aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97" -FULLY_PINNED='let releaseTag = "wallet-bindings-v1.2.3" // ... -checksum: "'"${XCSUM}"'"' -PARTIAL_DRIFT='let releaseTag = "wallet-bindings-v1.2.2" // ... -checksum: "'"${XCSUM}"'"' -NOT_PINNED='let releaseTag = "wallet-bindings-v9.9.9" // ... -checksum: "deadbeef"' +FULLY_PINNED='let releaseTag = "wallet-bindings-v1.2.3" + checksum: "'"${XCSUM}"'"' +PARTIAL_DRIFT='let releaseTag = "wallet-bindings-v1.2.2" + checksum: "'"${XCSUM}"'"' +NOT_PINNED='let releaseTag = "wallet-bindings-v9.9.9" + checksum: "deadbeef"' # PR fixtures; baseRefName is main unless stated. echo '[]' > "${TMP}/pr.none" @@ -201,8 +201,8 @@ assert_no_mutations # 5b. Mirror drift: new tag but STALE checksum -> fail closed (the sed # for the checksum no-op'd; SPM consumers would resolve a stale artifact). OLD_XCSUM="1111111111111111111111111111111111111111111111111111111111111111" -STALE_CKSUM='let releaseTag = "wallet-bindings-v1.2.3" // ... -checksum: "'"${OLD_XCSUM}"'"' +STALE_CKSUM='let releaseTag = "wallet-bindings-v1.2.3" + checksum: "'"${OLD_XCSUM}"'"' set_fixtures 0 1 "${STALE_CKSUM}" pr.none run_case "mirror drift (tag new, checksum stale) fails" 1 assert_no_mutations @@ -432,9 +432,9 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 29d. Huge numeric prerelease identifiers (20 digits) compare as -# alphanumeric under the 18-digit cap: an origin pin of rc<20 digits> -# still outranks incoming rc.2 -> refused, no arithmetic wrap. +# 29d. Huge numeric prerelease identifiers compare by (digit length, +# bytes) — no arithmetic — so an origin pin of rc<20 digits> still +# outranks incoming rc.2 -> refused, no arithmetic wrap. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-2" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3-18446744073709551617"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -600,7 +600,8 @@ else fi # Static check: the TAG regex must be byte-identical in every copy -# (three occurrences in release.yml, one in the script under test). +# (three occurrences in release.yml, one in open-spm-pr.sh, one in +# guard-release-refresh.sh). TAG_REGEX='^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$' wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release.yml" || true)" sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" From 23dabe4aa22bbcb4f598df3a4abb4089c97bba23 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 19:34:56 +0100 Subject: [PATCH 19/53] ci: shellcheck-quiet the pin-order fixture escapes --- .github/workflows/ci.yml | 19 ++++++++++-- .github/workflows/release.yml | 20 ++++++++----- scripts/release/check-pin-order.sh | 19 ++++++++++-- scripts/release/open-spm-pr.sh | 5 ++-- scripts/release/pinlib.sh | 3 +- scripts/release/semver.sh | 3 +- scripts/release/test-open-spm-pr.sh | 46 ++++++++++++++++++++++++----- 7 files changed, 91 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29eadd7..7c06073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,10 +34,11 @@ jobs: - name: Refuse a downgrading pin env: BASE_REF: ${{ github.base_ref }} + HEAD_REF: ${{ github.head_ref }} run: | # Single comparison implementation (scripts/release/semver.sh), - # comment-stripped exactly-one extraction, annotation-safe - # echoes — shared with the release scripts. + # comment-stripped strict extraction, annotation-safe echoes — + # shared with the release scripts. if [[ ! "$BASE_REF" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then echo "::error::unexpected base branch" exit 1 @@ -46,7 +47,19 @@ jobs: echo "Package.swift untouched; nothing to check" exit 0 fi - scripts/release/check-pin-order.sh "$BASE_REF" + # Pin PRs must come from the reserved bot branch, which names + # the release it pins; the gate cross-checks the PR head's + # Package.swift against that tag (strict mode). + case "$HEAD_REF" in + pin-spm-checksum-*) + expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" + ;; + *) + echo "::error::pin PR must originate from a pin-spm-checksum-* branch" + exit 1 + ;; + esac + scripts/release/check-pin-order.sh "$BASE_REF" "$expected_tag" fmt: name: Format diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3c60322..0964b79 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -206,18 +206,22 @@ jobs: # Package.swift must fail the release rather than skip the pin. # Fixed strings, not EREs: build-metadata tags contain '+', # which an interpolated pattern would treat as a quantifier. - # Comments, leading whitespace, and trailing whitespace are - # stripped so the whole-line counts match the committed shape - # (the checksum assignment is indented 12 spaces). - pin_tag_lines="$(sed 's#//.*$##' Package.swift | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -cF -x -- "let releaseTag = \"$TAG\"" || true)" - pin_sum_lines="$(sed 's#//.*$##' Package.swift | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' | grep -cF -x -- "checksum: \"$xcsum\"" || true)" + # The shared normalizer (pinlib.sh) strips block/line comments + # and indentation, so the whole-line counts match the code view + # every other verification path uses. + # shellcheck disable=SC1091 # sourced next to this file + source scripts/release/pinlib.sh + normalized="$(strip_swift_comments "$(cat Package.swift)")" + pin_tag_lines="$(printf '%s\n' "$normalized" | grep -cF -x -- "let releaseTag = \"$TAG\"" || true)" + pin_sum_lines="$(printf '%s\n' "$normalized" | grep -cF -x -- "checksum: \"$xcsum\"" || true)" + checksum_lines="$(printf '%s\n' "$normalized" | grep -cE '^checksum: "' || true)" if [ "$pin_tag_lines" != "1" ] || [ "$pin_sum_lines" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 fi - # A second checksum line would silently receive the same pin; - # refuse if the file ever gains additional binary targets. - if [ "$(grep -c 'checksum:' Package.swift)" != "1" ]; then + # A second checksum assignment would silently receive the same + # pin; refuse if the file ever gains additional binary targets. + if [ "$checksum_lines" != "1" ]; then echo "::error::Package.swift carries more than one checksum line; refusing to pin" exit 1 fi diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index e43b6a4..7c1cfcf 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -16,19 +16,34 @@ source "${BASH_SOURCE[0]%/*}/pinlib.sh" source "${BASH_SOURCE[0]%/*}/semver.sh" BASE_BRANCH="${1:?base branch required}" +EXPECTED_TAG="${2:-}" if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ || [[ "${BASE_BRANCH}" == pin-spm-checksum-* ]]; then echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" exit 1 fi -incoming_matches="$(strip_swift_comments "$(cat Package.swift)" \ +normalized_in="$(strip_swift_comments "$(cat Package.swift)")" +# Strict mode when the expected tag is known (ci.yml derives it from +# the reserved bot branch name): the normalized code must contain +# exactly that assignment and NO other releaseTag- or checksum-bearing +# line, so comment/nesting text tricks fail closed. +if [ -n "${EXPECTED_TAG}" ]; then + expected_lines="$(printf '%s\n' "${normalized_in}" | grep -cF -x -- "let releaseTag = \"${EXPECTED_TAG}\"" || true)" + release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE 'releaseTag' || true)" + checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE 'checksum:' || true)" + if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] || [ "${checksum_lines}" != "1" ]; then + echo "::error::PR head does not carry exactly the expected pin assignment for ${EXPECTED_TAG} (ambiguous or missing)" + exit 1 + fi +fi +incoming_matches="$(printf '%s\n' "${normalized_in}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" if [ "${incoming_matches}" != "1" ]; then echo "::error::expected exactly one releaseTag assignment on the PR head, found ${incoming_matches}" exit 1 fi -incoming_tag="$(strip_swift_comments "$(cat Package.swift)" \ +incoming_tag="$(printf '%s\n' "${normalized_in}" \ | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" incoming_version="${incoming_tag#wallet-bindings-v}" if [[ ! "${incoming_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 8f2d6d9..c90f3ee 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -2,8 +2,9 @@ # LC_ALL=C pins collation for the semver string comparisons below. export LC_ALL=C -# Shared helpers, and the semver precedence comparator (single sources -# of truth, also used by check-pin-order.sh and guard-release-refresh.sh). +# Shared helpers (also used by check-pin-order.sh and +# guard-release-refresh.sh) and the semver precedence comparator (used +# by check-pin-order.sh). # shellcheck disable=SC1091 # sourced next to this file, linted directly source "${BASH_SOURCE[0]%/*}/pinlib.sh" # shellcheck disable=SC1091 # sourced next to this file, linted directly diff --git a/scripts/release/pinlib.sh b/scripts/release/pinlib.sh index 3892dc5..c49c701 100755 --- a/scripts/release/pinlib.sh +++ b/scripts/release/pinlib.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash # Shared helpers for the release pin scripts (sourced, not executed). -# Callers export LC_ALL=C for raw-byte comparisons. +# Self-contained: pins LC_ALL=C for raw-byte comparisons. +export LC_ALL=C esc() { # Strip control and non-ASCII bytes (pin tags are ASCII-only, so this diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh index 4d29f5c..f044ca2 100755 --- a/scripts/release/semver.sh +++ b/scripts/release/semver.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # Shared semver precedence comparator. Sourced by open-spm-pr.sh and # check-pin-order.sh so every pin-order verdict uses one implementation. -# Requires LC_ALL=C for the raw-byte identifier comparisons. +# Self-contained: pins LC_ALL=C for the raw-byte identifier comparisons. +export LC_ALL=C # semver_prerelease_cmp : identifier-wise compare of the # pre-release parts (without the leading '-'). A final release outranks diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 1fe0b57..09a2fb5 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -482,7 +482,7 @@ rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 33b. git show fails -> open-spm-pr.sh fails closed (no silent skip). +# 33. git show fails -> open-spm-pr.sh fails closed (no silent skip). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '1' > "${TMP}/show_fails" : > "${LOG}" @@ -496,7 +496,7 @@ assert_no_mutations printf '0' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 33c. Comment decoys claiming THIS tag+checksum while the real code pin +# 34. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the script refuse (fail closed). printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -507,7 +507,7 @@ rc=$? if [ "${rc}" = "1" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 33. Comment decoys claiming THIS tag+checksum while the real code pin +# 37. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the guard refuse (fail closed). printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -518,7 +518,7 @@ rc=$? if [ "${rc}" = "1" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 34. Guard: zero releaseTag assignments -> refuse. +# 40. Guard: zero releaseTag assignments -> refuse. printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -527,7 +527,7 @@ printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000 rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses zero assignments"; else bad "guard refuses zero assignments" "exit ${rc}"; fi -# 35. Guard: two releaseTag assignments -> refuse. +# 41. Guard: two releaseTag assignments -> refuse. printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -536,7 +536,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bind rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses duplicate assignments"; else bad "guard refuses duplicate assignments" "exit ${rc}"; fi -# 36. Guard: invalid checksum -> refuse. +# 42. Guard: invalid checksum -> refuse. printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -545,7 +545,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 rc=$? if [ "${rc}" = "1" ]; then ok "guard rejects invalid checksum"; else bad "guard rejects invalid checksum" "exit ${rc}"; fi -# 37. Guard: git show failure -> fail closed. +# 43. Guard: git show failure -> fail closed. printf '1' > "${TMP}/show_fails" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -579,6 +579,38 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" bash "${ORDER}" main >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses same version"; else bad "pin order refuses same version" "exit ${rc}"; fi + +# 38b. Reserved-namespace base branch -> fail closed. +# shellcheck disable=SC2016 # fixture line content is not expanded +printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" "pin-spm-checksum-1.2.3" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order rejects reserved namespace"; else bad "pin order rejects reserved namespace" "exit ${rc}"; fi + +# 38c. Ambiguous PR head (a second releaseTag line) -> strict mode +# refuses: the normalized head must carry exactly the expected +# assignment and no other releaseTag- or checksum-bearing line. +# shellcheck disable=SC2016 # fixture line content is not expanded +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\nlet releaseTag = "wallet-bindings-v1.2.3"\n' > "${STUBS}/repo/Package.swift" +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order refuses ambiguous PR head"; else bad "pin order refuses ambiguous PR head" "exit ${rc}"; fi + +# 38d. git show failure on the base -> fail closed. +printf '1' > "${TMP}/show_fails" +# shellcheck disable=SC2016 # fixture line content is not expanded +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else bad "pin order fails closed on git show error" "exit ${rc}"; fi +printf '0' > "${TMP}/show_fails" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" # 39. semver.sh unit checks (sourced directly). From 9d049e971ac3c6f2815291d1f3e0b1f3bcb523db Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 19:51:51 +0100 Subject: [PATCH 20/53] ci: shared pin counting, supersede stale pins, gate hardening --- .github/workflows/ci.yml | 11 +++ .github/workflows/release.yml | 7 +- scripts/release/check-pin-order.sh | 6 +- scripts/release/guard-release-refresh.sh | 9 ++- scripts/release/open-spm-pr.sh | 15 ++-- scripts/release/pinlib.sh | 17 ++++- scripts/release/test-open-spm-pr.sh | 95 +++++++++++++----------- 7 files changed, 104 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c06073..04e6923 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,17 @@ jobs: exit 1 ;; esac + # Branch names may contain '%': reject anything outside the + # tag charset before it reaches annotations or comparisons. + # NOTE: this pull_request gate covers human-opened pin PRs; a + # bot pin PR (opened with GITHUB_TOKEN) does not emit + # pull_request events, so it is enforced at creation time by + # the release workflow's rewind guard, which also supersedes + # older open pin PRs (no merge-order rewind). + if [[ ! "$expected_tag" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::derived tag does not match wallet-bindings-v" + exit 1 + fi scripts/release/check-pin-order.sh "$BASE_REF" "$expected_tag" fmt: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0964b79..ac29543 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -164,7 +164,7 @@ jobs: # from the repo at the tag and is not %-escaped here. echo "::error::tag version does not match bindings/Cargo.toml version" echo "tag version: ${VERSION}" - echo "crate version: ${declared}" + echo "crate version: ${declared}" | sed 's/::/[::]/g' exit 1 fi @@ -211,10 +211,7 @@ jobs: # every other verification path uses. # shellcheck disable=SC1091 # sourced next to this file source scripts/release/pinlib.sh - normalized="$(strip_swift_comments "$(cat Package.swift)")" - pin_tag_lines="$(printf '%s\n' "$normalized" | grep -cF -x -- "let releaseTag = \"$TAG\"" || true)" - pin_sum_lines="$(printf '%s\n' "$normalized" | grep -cF -x -- "checksum: \"$xcsum\"" || true)" - checksum_lines="$(printf '%s\n' "$normalized" | grep -cE '^checksum: "' || true)" + read -r pin_tag_lines pin_sum_lines checksum_lines <<< "$(count_pin_lines Package.swift "$TAG" "$xcsum")" if [ "$pin_tag_lines" != "1" ] || [ "$pin_sum_lines" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 7c1cfcf..baa480c 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -22,6 +22,10 @@ if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" exit 1 fi +if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::unexpected expected tag: $(esc "${EXPECTED_TAG}")" + exit 1 +fi normalized_in="$(strip_swift_comments "$(cat Package.swift)")" # Strict mode when the expected tag is known (ci.yml derives it from @@ -33,7 +37,7 @@ if [ -n "${EXPECTED_TAG}" ]; then release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE 'releaseTag' || true)" checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE 'checksum:' || true)" if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] || [ "${checksum_lines}" != "1" ]; then - echo "::error::PR head does not carry exactly the expected pin assignment for ${EXPECTED_TAG} (ambiguous or missing)" + echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous or missing)" exit 1 fi fi diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index e5ec8f6..9021f4f 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -56,9 +56,14 @@ fi # such as '+'). pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" -pin_sum="$(printf '%s\n' "${origin_code}" \ - | grep -E '^checksum: ' | grep -oE '[0-9a-f]{64}')" +pin_sum_raw="$(printf '%s\n' "${origin_code}" \ + | grep -E '^checksum: ' | head -1 | grep -oE '"[^"]*"' | tr -d '"' || true)" +pin_sum="$(printf '%s\n' "${pin_sum_raw}" | grep -oE '^[0-9a-f]{64}$' || true)" if [ "${pin_tag}" = "${TAG}" ]; then + if [ -z "${pin_sum}" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${pin_sum_raw}")" + exit 1 + fi if [ "${pin_sum}" = "${XCSUM}" ]; then echo "release ${TAG} is already pinned on ${DEFAULT_BRANCH}; asset refresh is a no-op" exit 0 diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index c90f3ee..79ee5db 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -116,11 +116,8 @@ git add Package.swift # Anchored, exactly-once verification with fixed strings (TAG may # contain ERE metacharacters such as '+'): strip comments and trailing # whitespace, then count whole-line matches. -expected_tag_line="let releaseTag = \"${TAG}\"" -expected_sum_line="checksum: \"${XCSUM}\"" -pin_tag_lines="$(strip_swift_comments "$(cat Package.swift)" | grep -cF -x -- "${expected_tag_line}" || true)" -pin_sum_lines="$(strip_swift_comments "$(cat Package.swift)" | grep -cF -x -- "${expected_sum_line}" || true)" -if [ "${pin_tag_lines}" != "1" ] || [ "${pin_sum_lines}" != "1" ]; then +read -r pin_tag_lines pin_sum_lines checksum_lines <<< "$(count_pin_lines Package.swift "${TAG}" "${XCSUM}")" +if [ "${pin_tag_lines}" != "1" ] || [ "${pin_sum_lines}" != "1" ] || [ "${checksum_lines}" != "1" ]; then echo "::error::Package.swift does not carry exactly one expected release tag and checksum assignment after substitution" exit 1 fi @@ -219,4 +216,12 @@ Checksum: \`${XCSUM}\` The GitHub release for this tag is published before this PR is opened. Merge to activate." + # Supersede older still-open pin PRs: at most one open pin PR may + # exist, so no merge order can rewind the pin to an older release. + for old_pr in $(gh pr list --state open --limit 100 \ + --json number,headRefName \ + --jq '.[] | select(.headRefName | startswith("pin-spm-checksum-") and . != "'"${BRANCH}"'") | .number'); do + gh pr close "${old_pr}" \ + --comment "Superseded for ${TAG}: an older pin must not merge after a newer one." || true + done fi diff --git a/scripts/release/pinlib.sh b/scripts/release/pinlib.sh index c49c701..ba6ec19 100755 --- a/scripts/release/pinlib.sh +++ b/scripts/release/pinlib.sh @@ -17,7 +17,10 @@ esc() { # (perl -0777 so multi-line comments collapse), then line comments, then # leading/trailing whitespace and blank lines — the emitted lines are # exactly the assignment lines, normalized to column 0. A decoy literal -# inside any comment is invisible afterwards. +# inside any comment is invisible afterwards. Known limitation: a '//'- +# sequence inside a Swift string literal is still treated as a comment +# (fail-closed: counts drop and callers refuse), so keep pin lines free +# of '//' inside string literals. strip_swift_comments() { printf '%s' "$1" \ | perl -0777 -pe 's{/\*.*?\*/}{}gs' \ @@ -26,3 +29,15 @@ strip_swift_comments() { | grep -v '^$' \ || true } + +# Count, in the normalized code view of : (a) whole-line matches +# of the expected releaseTag assignment, (b) whole-line matches of the +# expected checksum assignment, (c) total checksum assignment lines. +# Prints "a b c" — fixed strings throughout (TAG may contain '+'). +count_pin_lines() { # + local file="$1" tag="$2" sum="$3" + printf '%s\n' "$(strip_swift_comments "$(cat "$file")")" \ + | awk -v t="let releaseTag = \"${tag}\"" -v s="checksum: \"${sum}\"" \ + '{ if ($0 == t) a++; if ($0 == s) b++; if ($0 ~ /^checksum: "/) c++ } \ + END { printf "%d %d %d\n", a+0, b+0, c+0 }' +} diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 09a2fb5..9621dd1 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -198,7 +198,7 @@ set_fixtures 0 1 "${PARTIAL_DRIFT}" pr.none run_case "partial drift (checksum new, tag old) fails" 1 assert_no_mutations -# 5b. Mirror drift: new tag but STALE checksum -> fail closed (the sed +# 6. Mirror drift: new tag but STALE checksum -> fail closed (the sed # for the checksum no-op'd; SPM consumers would resolve a stale artifact). OLD_XCSUM="1111111111111111111111111111111111111111111111111111111111111111" STALE_CKSUM='let releaseTag = "wallet-bindings-v1.2.3" @@ -213,7 +213,7 @@ set_fixtures 0 1 "${FULLY_PINNED}" pr.none 0 run_case "already-merged pin exits 0" 0 assert_no_mutations -# 6. Open same-repo PR against main -> detected, no duplicate create. +# 7. Open same-repo PR against main -> detected, no duplicate create. set_fixtures 0 1 "${FULLY_PINNED}" pr.own run_case "own open PR detected" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -222,7 +222,7 @@ else ok "no duplicate create" fi -# 7. Open different-owner PR with colliding head branch -> create proceeds. +# 8. Open different-owner PR with colliding head branch -> create proceeds. set_fixtures 0 1 "${FULLY_PINNED}" pr.evillow run_case "different-owner PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -231,7 +231,7 @@ else bad "create despite different-owner PR" "${LOG_CONTENTS}" fi -# 8. Open fork PR with colliding head branch -> create proceeds. +# 9. Open fork PR with colliding head branch -> create proceeds. set_fixtures 0 1 "${FULLY_PINNED}" pr.fork run_case "fork PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -240,7 +240,7 @@ else bad "create despite fork PR" "${LOG_CONTENTS}" fi -# 9. Open same-owner PR against a non-default base -> create proceeds. +# 10. Open same-owner PR against a non-default base -> create proceeds. set_fixtures 0 1 "${FULLY_PINNED}" pr.wrongbase run_case "wrong-base PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -249,40 +249,40 @@ else bad "create despite wrong-base PR" "${LOG_CONTENTS}" fi -# 10. Malformed repository owner -> fail closed. +# 11. Malformed repository owner -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "invalid owner fails" 1 "bad..owner/rust-sdk" assert_no_mutations -# 11. Malformed DEFAULT_BRANCH -> fail closed before any fetch. +# 12. Malformed DEFAULT_BRANCH -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid default branch fails" 1 "mintlayer/rust-sdk" $'ma\tin' assert_no_mutations -# 12. Malformed XCSUM -> fail closed before any fetch. +# 13. Malformed XCSUM -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" assert_no_mutations -# 13. HEAD is not the tagged commit -> fail closed, no push. +# 14. HEAD is not the tagged commit -> fail closed, no push. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'othercommitsha' > "${TMP}/head_commit" run_case "HEAD differs from tag fails" 1 assert_no_mutations printf 'tagcommitsha' > "${TMP}/head_commit" -# 14. All-zero checksum -> fail closed before any fetch. +# 15. All-zero checksum -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "all-zero checksum fails" 1 "mintlayer/rust-sdk" main \ "0000000000000000000000000000000000000000000000000000000000000000" assert_no_mutations -# 15. VERSION that is not semver -> fail closed before any fetch. +# 16. VERSION that is not semver -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 assert_no_mutations -# 16. TAG not matching the release pattern -> fail closed before fetch. +# 17. TAG not matching the release pattern -> fail closed before fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid tag (no patch) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 "wallet-bindings-v1.2" assert_no_mutations @@ -290,12 +290,12 @@ set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid tag (wrong prefix) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2.3 "evil-wallet-bindings-v1.2.3" assert_no_mutations -# 17. Default branch inside the reserved namespace -> fail closed. +# 18. Default branch inside the reserved namespace -> fail closed. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "reserved-namespace default branch fails" 1 "mintlayer/rust-sdk" "pin-spm-checksum-1.2.3" assert_no_mutations -# 18. Shallow clone -> the unshallow fetch is used. +# 19. Shallow clone -> the unshallow fetch is used. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'true' > "${TMP}/is_shallow" run_case "shallow clone unshallows" 0 @@ -306,7 +306,7 @@ else fi printf 'false' > "${TMP}/is_shallow" -# 19. Complete clone -> plain fetch with the explicit full refspec. +# 20. Complete clone -> plain fetch with the explicit full refspec. set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "complete clone plain fetch" 0 if grep -q -- "fetch origin +refs/heads/main:refs/remotes/origin/main" <<< "${LOG_CONTENTS}"; then @@ -315,13 +315,13 @@ else bad "plain fetch carries the full refspec" "${LOG_CONTENTS}" fi -# 20. Default branch already pins a DIFFERENT release -> fail closed. +# 21. Default branch already pins a DIFFERENT release -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "stale tag against a newer pin fails" 1 assert_no_mutations -# 21. Forward release over an OLDER active pin -> allowed. +# 22. Forward release over an OLDER active pin -> allowed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" run_case "forward release over older pin proceeds" 0 @@ -332,47 +332,47 @@ else fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 22. Same-version active pin with differing content -> rewind guard. +# 23. Same-version active pin with differing content -> rewind guard. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" run_case "same-version conflicting pin fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 23. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. +# 24. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '128' > "${TMP}/ancestry" run_case "merge-base git error fails" 1 assert_no_mutations printf '0' > "${TMP}/ancestry" -# 24. Unparseable origin pin tag -> fail closed. +# 25. Unparseable origin pin tag -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-vx"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "unparseable origin pin tag fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 25. Active checksum with missing tag line -> fail closed (one-sided). +# 26. Active checksum with missing tag line -> fail closed (one-sided). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "one-sided active checksum fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 26. TAG/VERSION mismatch -> fail closed before any fetch. +# 27. TAG/VERSION mismatch -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "mismatched tag and version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 9.9.9 assert_no_mutations -# 27. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. +# 28. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "deadbeef"\n' > "${TMP}/origin_swift" run_case "mangled origin checksum fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 28. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. +# 29. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-rc.1" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -386,7 +386,7 @@ if [ "${rc}" = "1" ]; then ok "prerelease after final refused"; else bad "prerel assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 29. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. +# 30. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3-rc1"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" : > "${LOG}" @@ -402,8 +402,8 @@ else fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 29b. Build metadata is excluded from precedence: an origin pin of -# 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. +# 31. Build metadata is excluded from precedence: an origin pin of +# 32.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -432,7 +432,18 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 29d. Huge numeric prerelease identifiers compare by (digit length, +# 33. Guard: mangled checksum (65+ hex) on origin -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b9700"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "guard refuses 65-hex checksum"; else bad "guard refuses 65-hex checksum" "exit ${rc}"; fi +assert_no_mutations + +# 34. Huge numeric prerelease identifiers compare by (digit length, # bytes) — no arithmetic — so an origin pin of rc<20 digits> still # outranks incoming rc.2 -> refused, no arithmetic wrap. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-2" // ... @@ -449,7 +460,7 @@ if [ "${rc}" = "1" ]; then ok "huge numeric prerelease refused without wrap"; el assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 30. Guard script: same tag + differing checksum -> refuse. +# 35. Guard script: same tag + differing checksum -> refuse. GUARD="${SCRIPT_DIR}/guard-release-refresh.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -459,7 +470,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses mismatched rebuild"; else bad "guard refuses mismatched rebuild" "exit ${rc}"; fi -# 31. Guard script: same tag + identical checksum (with a header +# 36. Guard script: same tag + identical checksum (with a header # comment whose version literal differs) -> allow. set_fixtures 0 1 "${FULLY_PINNED}" pr.none # shellcheck disable=SC2016 # \n are printf escapes, no expansion @@ -472,7 +483,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "0" ]; then ok "guard allows identical rebuild"; else bad "guard allows identical rebuild" "exit ${rc}"; fi -# 32. Guard script: older pin on main (forward release) -> allow. +# 37. Guard script: older pin on main (forward release) -> allow. printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -482,7 +493,7 @@ rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 33. git show fails -> open-spm-pr.sh fails closed (no silent skip). +# 38. git show fails -> open-spm-pr.sh fails closed (no silent skip). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '1' > "${TMP}/show_fails" : > "${LOG}" @@ -496,7 +507,7 @@ assert_no_mutations printf '0' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 34. Comment decoys claiming THIS tag+checksum while the real code pin +# 39. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the script refuse (fail closed). printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -507,7 +518,7 @@ rc=$? if [ "${rc}" = "1" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 37. Comment decoys claiming THIS tag+checksum while the real code pin +# 40. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the guard refuse (fail closed). printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -518,7 +529,7 @@ rc=$? if [ "${rc}" = "1" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 40. Guard: zero releaseTag assignments -> refuse. +# 41. Guard: zero releaseTag assignments -> refuse. printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -527,7 +538,7 @@ printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000 rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses zero assignments"; else bad "guard refuses zero assignments" "exit ${rc}"; fi -# 41. Guard: two releaseTag assignments -> refuse. +# 42. Guard: two releaseTag assignments -> refuse. printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -536,7 +547,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bind rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses duplicate assignments"; else bad "guard refuses duplicate assignments" "exit ${rc}"; fi -# 42. Guard: invalid checksum -> refuse. +# 43. Guard: invalid checksum -> refuse. printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -545,7 +556,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 rc=$? if [ "${rc}" = "1" ]; then ok "guard rejects invalid checksum"; else bad "guard rejects invalid checksum" "exit ${rc}"; fi -# 43. Guard: git show failure -> fail closed. +# 44. Guard: git show failure -> fail closed. printf '1' > "${TMP}/show_fails" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -556,7 +567,7 @@ if [ "${rc}" = "1" ]; then ok "guard fails closed on git show failure"; else bad printf '0' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 38. Pin-order script: upgrade allows, downgrade refuses, same refuses. +# 45. Pin-order script: upgrade allows, downgrade refuses, same refuses. ORDER="${SCRIPT_DIR}/check-pin-order.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3+meta"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" @@ -580,7 +591,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses same version"; else bad "pin order refuses same version" "exit ${rc}"; fi -# 38b. Reserved-namespace base branch -> fail closed. +# 46. Reserved-namespace base branch -> fail closed. # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ @@ -601,7 +612,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses ambiguous PR head"; else bad "pin order refuses ambiguous PR head" "exit ${rc}"; fi -# 38d. git show failure on the base -> fail closed. +# 47. git show failure on the base -> fail closed. printf '1' > "${TMP}/show_fails" # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" @@ -613,7 +624,7 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else b printf '0' > "${TMP}/show_fails" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 39. semver.sh unit checks (sourced directly). +# 48. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" semver_cmp_check() { From 1ec0964d0803f8a5cba340bec5c25738273409f2 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 20:04:25 +0100 Subject: [PATCH 21/53] ci: shellcheck-quiet the swift interpolation fixture --- docs/mobile-bindings.md | 5 +- scripts/release/check-pin-order.sh | 28 +++++--- scripts/release/guard-release-refresh.sh | 2 +- scripts/release/open-spm-pr.sh | 81 +++++++++++++++++++++--- scripts/release/test-open-spm-pr.sh | 13 ++++ 5 files changed, 108 insertions(+), 21 deletions(-) diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 3957ace..068460b 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -173,7 +173,10 @@ tagged commit, attaches them with a `SHA256SUMS` manifest to the GitHub release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM -resolution for the release. Consumers never need a Rust toolchain. +resolution for the release. The `ci.yml` "Pin ordering" gate refuses any +`Package.swift` change that is not a strictly-newer pin, so other edits +to that file require release-team coordination. Consumers never need a +Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded in the repository `CHANGELOG.md`. diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index baa480c..da581ea 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -4,8 +4,11 @@ # pinned on the default branch (same-version repairs are manual: the # rewind guard in open-spm-pr.sh refuses to create them). # -# Usage: check-pin-order.sh (run from the repo root, in -# the PR checkout; LC_ALL=C is enforced internally). +# Usage: check-pin-order.sh [EXPECTED_TAG] +# Run from the repo root in the PR checkout; LC_ALL=C is enforced +# internally. With EXPECTED_TAG (derived by ci.yml from the reserved +# bot branch name), strict mode additionally requires the PR head to +# carry exactly that assignment and no other pin-bearing line. set -euo pipefail export LC_ALL=C @@ -27,17 +30,24 @@ if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9] exit 1 fi -normalized_in="$(strip_swift_comments "$(cat Package.swift)")" +normalized_in="$(strip_swift_comments "$(cat Package.swift 2>/dev/null)")" || { + echo "::error::cannot read Package.swift" + exit 1 +} # Strict mode when the expected tag is known (ci.yml derives it from # the reserved bot branch name): the normalized code must contain # exactly that assignment and NO other releaseTag- or checksum-bearing # line, so comment/nesting text tricks fail closed. if [ -n "${EXPECTED_TAG}" ]; then expected_lines="$(printf '%s\n' "${normalized_in}" | grep -cF -x -- "let releaseTag = \"${EXPECTED_TAG}\"" || true)" - release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE 'releaseTag' || true)" - checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE 'checksum:' || true)" - if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] || [ "${checksum_lines}" != "1" ]; then - echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous or missing)" + # Anchored counts: the URL line interpolates \(releaseTag), so a + # substring 'releaseTag' count would double-count the real shape. + release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^let releaseTag = ' || true)" + checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "' || true)" + checksum_valid="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" + if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] \ + || [ "${checksum_lines}" != "1" ] || [ "${checksum_valid}" != "1" ]; then + echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous, missing, or non-hex checksum)" exit 1 fi fi @@ -84,7 +94,7 @@ fi # Only a strictly newer release advances the pin; equal or lower # (rewind or same-version repair) is refused at merge time. if [ "${cmp}" -le 0 ]; then - echo "::error::pin PR would not advance the release (incoming ${incoming_tag}, current ${current_tag})" + echo "::error::pin PR would not advance the release (incoming $(esc "${incoming_tag}"), current $(esc "${current_tag}"))" exit 1 fi -echo "pin order ok (incoming ${incoming_tag}, current ${current_tag})" +echo "pin order ok (incoming $(esc "${incoming_tag}"), current $(esc "${current_tag}"))" diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 9021f4f..78c1b6b 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -65,7 +65,7 @@ if [ "${pin_tag}" = "${TAG}" ]; then exit 1 fi if [ "${pin_sum}" = "${XCSUM}" ]; then - echo "release ${TAG} is already pinned on ${DEFAULT_BRANCH}; asset refresh is a no-op" + echo "rebuilt artifacts match the merged pin; asset refresh proceeds safely" exit 0 fi echo "::error::rebuilt artifacts (checksum $(esc "${XCSUM}")) do not match the pin merged on $(esc "${DEFAULT_BRANCH}") ($(esc "${pin_sum}")); release assets left untouched - repair manually" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 79ee5db..a6c397e 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -31,6 +31,9 @@ XCSUM="${3:?XCSUM required}" DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" BRANCH="pin-spm-checksum-${VERSION}" +# The VERSION charset admits refname-invalid values ('..', trailing +# '.'): validate before any git operation fails late with a raw error. +git check-ref-format --branch "${BRANCH}" # Mirror the workflow's validation so direct/manual invocations get the # same fail-closed guarantees as the release run. @@ -198,9 +201,43 @@ existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ --json number,headRepositoryOwner,isCrossRepository,baseRefName \ --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" -# The branch is disposable bot state; force-push keeps re-runs working -# when the remote branch already exists. It happens after the existence -# decision so a spoofed PR never references the bot commit. +# Supersede strictly-older open pin PRs and refuse when a strictly +# NEWER release's pin PR is still open (merging it after this one would +# rewind the pin; the concurrency group serializes runs, not queue +# order). Runs on both the create and reuse paths. Close failures fail +# the run - a stale open pin PR is a rewind hazard. +superseded="" +while IFS=$'\t' read -r old_pr old_branch; do + [ -n "${old_pr}" ] || continue + [ "${old_branch}" = "${BRANCH}" ] && continue + old_version="${old_branch#pin-spm-checksum-}" + if [ "${old_version}" = "${VERSION}" ]; then continue; fi + cmp_old="$(semver_cmp "${VERSION}" "${old_version}")" + if [[ ! "${cmp_old}" =~ ^-?[012]$ ]]; then + echo "::error::could not compare ${VERSION} against open pin PR #${old_pr} (${old_version})" + exit 1 + fi + if [ "${cmp_old}" -le 0 ]; then + echo "::error::open pin PR #${old_pr} pins ${old_version} (>= ${VERSION}); close or merge it before releasing ${VERSION}" + exit 1 + fi + gh pr close "${old_pr}" \ + --comment "Superseded by #${existing_pr:-this run} for ${TAG}: an older pin must not merge after a newer one." + superseded="${superseded} #${old_pr}" +done << OLD_PRS +$(gh pr list --state open --paginate --limit 500 \ + --json number,headRefName \ + --jq '.[] | select(.headRefName | startswith("pin-spm-checksum-") and . != "'"${BRANCH}"'") | [.number, .headRefName] | @tsv') || { + echo "::error::failed to list open pin PRs for superseding" + exit 1 +} +OLD_PRS +[ -z "${superseded}" ] || echo "superseded older open pin PR(s):${superseded}" + +# The branch is disposable bot state; force-with-lease-like semantics +# are unnecessary because the list above is authoritative: the push +# happens after the existence decision so a spoofed PR never references +# the bot commit. git push --force origin "${BRANCH}" if [ -n "${existing_pr}" ]; then @@ -216,12 +253,36 @@ Checksum: \`${XCSUM}\` The GitHub release for this tag is published before this PR is opened. Merge to activate." - # Supersede older still-open pin PRs: at most one open pin PR may - # exist, so no merge order can rewind the pin to an older release. - for old_pr in $(gh pr list --state open --limit 100 \ + # Supersede strictly-older open pin PRs and refuse when a strictly + # NEWER release's pin PR is still open (merging it after this one + # would rewind the pin). Runs on both the create and reuse paths; + # close failures fail the run - a stale open pin PR is a rewind hazard. + old_prs="$(gh pr list --state open --paginate --limit 500 \ --json number,headRefName \ - --jq '.[] | select(.headRefName | startswith("pin-spm-checksum-") and . != "'"${BRANCH}"'") | .number'); do + --jq '.[] | select(.headRefName | startswith("pin-spm-checksum-") and . != "'"${BRANCH}"'") | [.number, .headRefName] | @tsv')" \ + || { echo "::error::failed to list open pin PRs for superseding"; exit 1; } + # Supersede strictly-older open pin PRs and refuse when a strictly + # NEWER release's pin PR is still open (merging it after this one + # would rewind the pin). Close failures fail the run. + while IFS=$'\t' read -r old_pr old_branch; do + [ -n "${old_pr}" ] || continue + [ "${old_branch}" = "${BRANCH}" ] && continue + old_version="${old_branch#pin-spm-checksum-}" + if [ "${old_version}" = "${VERSION}" ]; then continue; fi + cmp_old="$(semver_cmp "${VERSION}" "${old_version}")" + if [[ ! "${cmp_old}" =~ ^-?[012]$ ]]; then + echo "::error::could not compare ${VERSION} against open pin PR #${old_pr} (${old_version})" + exit 1 + fi + if [ "${cmp_old}" -le 0 ]; then + echo "::error::open pin PR #${old_pr} pins ${old_version} (>= ${VERSION}); close or merge it before releasing ${VERSION}" + exit 1 + fi gh pr close "${old_pr}" \ - --comment "Superseded for ${TAG}: an older pin must not merge after a newer one." || true - done -fi + --comment "Superseded by #${existing_pr:-this run} for ${TAG}: an older pin must not merge after a newer one." + superseded="${superseded} #${old_pr}" + done << OLD_PRS +${old_prs} +OLD_PRS + [ -z "${superseded}" ] || echo "superseded older open pin PR(s):${superseded}" +fi \ No newline at end of file diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 9621dd1..bdb78cc 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -624,6 +624,19 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else b printf '0' > "${TMP}/show_fails" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" +# 48a. Strict mode PASS path over the REAL root Package.swift shape: +# header comment, the download URL interpolating \(releaseTag) (which a +# substring 'releaseTag' count would double-count), releaseTag at +# column 0, checksum indented 12 spaces. +# shellcheck disable=SC2016 # \(releaseTag) is Swift interpolation, literal here +printf '// SPM entry point for iOS consumers. The binary target is attached to the\n// `wallet-bindings-vX.Y.Z` GitHub release; its checksum is updated by the\n// release workflow.\n\nimport PackageDescription\n\nlet releaseTag = "wallet-bindings-v1.3.0"\nlet releaseBaseUrl = "https://github.com/mintlayer/rust-sdk/releases/download/\(releaseTag)"\nlet package = Package(\n binaryTarget(\n checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${STUBS}/repo/Package.swift" +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "strict mode passes the real Package.swift shape"; else bad "strict mode passes the real Package.swift shape" "exit ${rc}"; fi + # 48. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" From 3a1d9d1df1c818729fd0f81b2f3fd3150bfede1d Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 20:28:15 +0100 Subject: [PATCH 22/53] ci: fix supersede jq empty-array row and stub parity --- scripts/release/open-spm-pr.sh | 50 +++++----------------- scripts/release/test-open-spm-pr.sh | 64 ++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 45 deletions(-) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index a6c397e..5c17d46 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -207,6 +207,13 @@ existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ # order). Runs on both the create and reuse paths. Close failures fail # the run - a stale open pin PR is a rewind hazard. superseded="" +# Same trust filters as the existing_pr lookup: fork PRs, same-owner +# cross-repo PRs, and PRs against a non-default base never constrain +# this run even when their branch names collide with the namespace. +old_prs="$(gh pr list --state open --paginate \ + --json number,headRefName,headRepositoryOwner,isCrossRepository,baseRefName \ + --jq ".[] | select(.headRefName | startswith(\"pin-spm-checksum-\") and .headRefName != \"${BRANCH}\" and .headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\") | [.number, .headRefName] | @tsv")" \ + || { echo "::error::failed to list open pin PRs for superseding"; exit 1; } while IFS=$'\t' read -r old_pr old_branch; do [ -n "${old_pr}" ] || continue [ "${old_branch}" = "${BRANCH}" ] && continue @@ -214,23 +221,18 @@ while IFS=$'\t' read -r old_pr old_branch; do if [ "${old_version}" = "${VERSION}" ]; then continue; fi cmp_old="$(semver_cmp "${VERSION}" "${old_version}")" if [[ ! "${cmp_old}" =~ ^-?[012]$ ]]; then - echo "::error::could not compare ${VERSION} against open pin PR #${old_pr} (${old_version})" + echo "::error::could not compare ${VERSION} against open pin PR #${old_pr} ($(esc "${old_version}"))" exit 1 fi if [ "${cmp_old}" -le 0 ]; then - echo "::error::open pin PR #${old_pr} pins ${old_version} (>= ${VERSION}); close or merge it before releasing ${VERSION}" + echo "::error::open pin PR #${old_pr} pins $(esc "${old_version}") (>= ${VERSION}); close or merge it before releasing ${VERSION}" exit 1 fi gh pr close "${old_pr}" \ --comment "Superseded by #${existing_pr:-this run} for ${TAG}: an older pin must not merge after a newer one." superseded="${superseded} #${old_pr}" done << OLD_PRS -$(gh pr list --state open --paginate --limit 500 \ - --json number,headRefName \ - --jq '.[] | select(.headRefName | startswith("pin-spm-checksum-") and . != "'"${BRANCH}"'") | [.number, .headRefName] | @tsv') || { - echo "::error::failed to list open pin PRs for superseding" - exit 1 -} +${old_prs} OLD_PRS [ -z "${superseded}" ] || echo "superseded older open pin PR(s):${superseded}" @@ -253,36 +255,4 @@ Checksum: \`${XCSUM}\` The GitHub release for this tag is published before this PR is opened. Merge to activate." - # Supersede strictly-older open pin PRs and refuse when a strictly - # NEWER release's pin PR is still open (merging it after this one - # would rewind the pin). Runs on both the create and reuse paths; - # close failures fail the run - a stale open pin PR is a rewind hazard. - old_prs="$(gh pr list --state open --paginate --limit 500 \ - --json number,headRefName \ - --jq '.[] | select(.headRefName | startswith("pin-spm-checksum-") and . != "'"${BRANCH}"'") | [.number, .headRefName] | @tsv')" \ - || { echo "::error::failed to list open pin PRs for superseding"; exit 1; } - # Supersede strictly-older open pin PRs and refuse when a strictly - # NEWER release's pin PR is still open (merging it after this one - # would rewind the pin). Close failures fail the run. - while IFS=$'\t' read -r old_pr old_branch; do - [ -n "${old_pr}" ] || continue - [ "${old_branch}" = "${BRANCH}" ] && continue - old_version="${old_branch#pin-spm-checksum-}" - if [ "${old_version}" = "${VERSION}" ]; then continue; fi - cmp_old="$(semver_cmp "${VERSION}" "${old_version}")" - if [[ ! "${cmp_old}" =~ ^-?[012]$ ]]; then - echo "::error::could not compare ${VERSION} against open pin PR #${old_pr} (${old_version})" - exit 1 - fi - if [ "${cmp_old}" -le 0 ]; then - echo "::error::open pin PR #${old_pr} pins ${old_version} (>= ${VERSION}); close or merge it before releasing ${VERSION}" - exit 1 - fi - gh pr close "${old_pr}" \ - --comment "Superseded by #${existing_pr:-this run} for ${TAG}: an older pin must not merge after a newer one." - superseded="${superseded} #${old_pr}" - done << OLD_PRS -${old_prs} -OLD_PRS - [ -z "${superseded}" ] || echo "superseded older open pin PR(s):${superseded}" fi \ No newline at end of file diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index bdb78cc..153c2b6 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -81,6 +81,20 @@ if [ "$1" = "pr" ] && [ "$2" = "list" ]; then prev="$a" done printf '%s' "${payload}" | jq -r "${prog}" + exit $? +fi +# pr close/create must reference a numeric PR (real gh rejects garbage). +if [ "$1" = "pr" ] && { [ "$2" = "close" ] || [ "$2" = "create" ]; }; then + for a in "$@"; do + if [[ "${a}" =~ ^[0-9]+$ ]]; then + exit 0 + fi + if [[ "${a}" == --head* || "${a}" == --base* || "${a}" == --title* || "${a}" == --body* ]]; then + exit 0 + fi + done + echo "gh: refusing non-numeric PR argument" >&2 + exit 1 fi exit 0 EOF @@ -96,10 +110,12 @@ NOT_PINNED='let releaseTag = "wallet-bindings-v9.9.9" # PR fixtures; baseRefName is main unless stated. echo '[]' > "${TMP}/pr.none" -echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.own" -echo '[{"number": 9, "headRepositoryOwner": {"login": "evil"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.evillow" -echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": true, "baseRefName": "main"}]' > "${TMP}/pr.fork" -echo '[{"number": 9, "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "develop"}]' > "${TMP}/pr.wrongbase" +echo '[{"number": 7, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.own" +echo '[{"number": 9, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwner": {"login": "evil"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.evillow" +echo '[{"number": 9, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": true, "baseRefName": "main"}]' > "${TMP}/pr.fork" +echo '[{"number": 9, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "develop"}]' > "${TMP}/pr.wrongbase" +echo '[{"number": 5, "headRefName": "pin-spm-checksum-0.0.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_older" +echo '[{"number": 6, "headRefName": "pin-spm-checksum-9.9.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_newer" # set_fixtures [default_diff] # default_diff: 0 = Package.swift identical to the default branch (pin merged). @@ -156,7 +172,16 @@ assert_no_mutations # 2. Ancestor + real diff -> success; push issued before create. set_fixtures 0 1 "${FULLY_PINNED}" pr.none -run_case "diff present creates PR" 0 +: > "${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=$? +echo "CASE2 rc=${rc} OUT=[$(cat "${OUT}")]" +LOG_CONTENTS="$(cat "${LOG}")" +echo "CASE2 LOG:"; printf '%s\n' "${LOG_CONTENTS}" | tail -5 +if [ "${rc}" = "0" ]; then ok "case2 exit 0"; else bad "case2 exit" "rc=${rc}"; fi if grep -q -- "push --force origin pin-spm-checksum-1.2.3" <<< "${LOG_CONTENTS}"; then ok "force-push issued" else @@ -637,6 +662,35 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "0" ]; then ok "strict mode passes the real Package.swift shape"; else bad "strict mode passes the real Package.swift shape" "exit ${rc}"; fi +# 48b. Supersede: an older stale pin PR is closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_older +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +: > "${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=$? +if [ "${rc}" = "0" ] && grep -q -- "pr close 5" "${LOG}"; then + ok "supersede closes the older stale pin PR" +else + bad "supersede closes the older stale pin PR" "exit ${rc}: $(cat "${OUT}")" +fi + +# 48c. Supersede: a newer open pin PR refuses the run. +cp "${TMP}/pr.stale_newer" "${TMP}/existing_pr" +: > "${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=$? +if [ "${rc}" = "1" ] && grep -q "9.9.9" <<< "$(cat "${OUT}")"; then + ok "supersede refuses a newer open pin PR" +else + bad "supersede refuses a newer open pin PR" "exit ${rc}: $(cat "${OUT}")" +fi + # 48. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" From 440fa32db859bb973c76ecd32b14f701be4bc600 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 20:30:41 +0100 Subject: [PATCH 23/53] ci: fix supersede jq scoping and list-failure handling --- scripts/release/open-spm-pr.sh | 2 +- scripts/release/test-open-spm-pr.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 5c17d46..2234ecf 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -212,7 +212,7 @@ superseded="" # this run even when their branch names collide with the namespace. old_prs="$(gh pr list --state open --paginate \ --json number,headRefName,headRepositoryOwner,isCrossRepository,baseRefName \ - --jq ".[] | select(.headRefName | startswith(\"pin-spm-checksum-\") and .headRefName != \"${BRANCH}\" and .headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\") | [.number, .headRefName] | @tsv")" \ + --jq ".[] | select((.headRefName | startswith(\"pin-spm-checksum-\")) and .headRefName != \"${BRANCH}\" and .headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\") | \"\(.number)\t\(.headRefName)\"")" \ || { echo "::error::failed to list open pin PRs for superseding"; exit 1; } while IFS=$'\t' read -r old_pr old_branch; do [ -n "${old_pr}" ] || continue diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 153c2b6..0a00ccd 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -240,7 +240,14 @@ assert_no_mutations # 7. Open same-repo PR against main -> detected, no duplicate create. set_fixtures 0 1 "${FULLY_PINNED}" pr.own -run_case "own open PR detected" 0 +: > "${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=$? +echo "DBG7 rc=${rc} OUT=[$(cat "${OUT}")]" +if [ "${rc}" = "0" ]; then ok "own open PR detected"; else bad "own open PR detected" "exit ${rc}"; fi if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then bad "no duplicate create" "${LOG_CONTENTS}" else From 5d6d73449650415e3f81e2f6da4ef87ab1be4449 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 20:44:08 +0100 Subject: [PATCH 24/53] ci: aligned pin-state model and decoy-proof extraction --- scripts/release/check-pin-order.sh | 5 +++-- scripts/release/open-spm-pr.sh | 27 +++++++++++++++++++++------ scripts/release/test-open-spm-pr.sh | 5 ++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index da581ea..2ce0749 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -30,10 +30,11 @@ if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9] exit 1 fi -normalized_in="$(strip_swift_comments "$(cat Package.swift 2>/dev/null)")" || { +if [ ! -r Package.swift ]; then echo "::error::cannot read Package.swift" exit 1 -} +fi +normalized_in="$(strip_swift_comments "$(cat Package.swift)")" # Strict mode when the expected tag is known (ci.yml derives it from # the reserved bot branch name): the normalized code must contain # exactly that assignment and NO other releaseTag- or checksum-bearing diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 2234ecf..4179906 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -164,14 +164,16 @@ origin_pin_active=0 if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ]; then origin_pin_active=1 fi -if [ "${origin_pin_active}" = "1" ]; then - # An active (non-placeholder) pin requires a parsable tag line; a - # missing/mangled tag line is itself a fail-closed state. +# The release marker must be parsable whenever it is present, active or +# deactivated: both gates rely on the version for ordering decisions. +if [ -n "${origin_pin_tag}" ]; then origin_version="${origin_pin_tag#v}" - if [ -z "${origin_pin_tag}" ] || [[ ! "${origin_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + if [[ ! "${origin_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" exit 1 fi +fi +if [ "${origin_pin_active}" = "1" ]; then cmp="$(semver_cmp "${VERSION}" "${origin_version}")" if [[ ! "${cmp}" =~ ^-?[012]$ ]]; then echo "::error::semver comparison failed for ${VERSION} against ${origin_version}" @@ -181,6 +183,14 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi +elif [ "$(printf '%s\n%s\n' "${origin_version:-0.0.0}" "${VERSION}" | sort -V | head -1)" = "${VERSION}" ] \ + && [ -n "${origin_version}" ]; then + # A deactivated (zeroed-checksum) pin whose release marker is + # newer-or-equal: main claims ${origin_version} with no active + # checksum. Pinning ${VERSION} here would leave the marker and the + # checksum in conflict; manual repair required. + echo "::error::origin/${DEFAULT_BRANCH} carries a deactivated pin for ${origin_version} (>= ${VERSION}); refusing to pin - repair the default branch manually" + exit 1 elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then # A checksum line exists but is not 64 lowercase hex: mangled pin. echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${origin_pin_sum_raw}")" @@ -199,7 +209,8 @@ git commit -m "chore: pin the SPM checksum to ${TAG}" # program; --paginate keeps the check independent of list windows. existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ --json number,headRepositoryOwner,isCrossRepository,baseRefName \ - --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" + --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" \ + || { echo "::error::failed to list existing pin PRs"; exit 1; } # Supersede strictly-older open pin PRs and refuse when a strictly # NEWER release's pin PR is still open (merging it after this one would @@ -219,6 +230,10 @@ while IFS=$'\t' read -r old_pr old_branch; do [ "${old_branch}" = "${BRANCH}" ] && continue old_version="${old_branch#pin-spm-checksum-}" if [ "${old_version}" = "${VERSION}" ]; then continue; fi + if [[ ! "${old_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::open pin PR #${old_pr} carries an unparseable version: $(esc "${old_version}")" + exit 1 + fi cmp_old="$(semver_cmp "${VERSION}" "${old_version}")" if [[ ! "${cmp_old}" =~ ^-?[012]$ ]]; then echo "::error::could not compare ${VERSION} against open pin PR #${old_pr} ($(esc "${old_version}"))" @@ -229,7 +244,7 @@ while IFS=$'\t' read -r old_pr old_branch; do exit 1 fi gh pr close "${old_pr}" \ - --comment "Superseded by #${existing_pr:-this run} for ${TAG}: an older pin must not merge after a newer one." + --comment "Superseded by the ${TAG} checksum-pin PR: an older pin must not merge after a newer one." superseded="${superseded} #${old_pr}" done << OLD_PRS ${old_prs} diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 0a00ccd..7888403 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -178,9 +178,7 @@ set_fixtures 0 1 "${FULLY_PINNED}" pr.none bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? -echo "CASE2 rc=${rc} OUT=[$(cat "${OUT}")]" LOG_CONTENTS="$(cat "${LOG}")" -echo "CASE2 LOG:"; printf '%s\n' "${LOG_CONTENTS}" | tail -5 if [ "${rc}" = "0" ]; then ok "case2 exit 0"; else bad "case2 exit" "rc=${rc}"; fi if grep -q -- "push --force origin pin-spm-checksum-1.2.3" <<< "${LOG_CONTENTS}"; then ok "force-push issued" @@ -246,7 +244,7 @@ set_fixtures 0 1 "${FULLY_PINNED}" pr.own bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? -echo "DBG7 rc=${rc} OUT=[$(cat "${OUT}")]" +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "own open PR detected"; else bad "own open PR detected" "exit ${rc}"; fi if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then bad "no duplicate create" "${LOG_CONTENTS}" @@ -534,6 +532,7 @@ printf '1' > "${TMP}/show_fails" bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ > "${OUT}" 2>&1 ) rc=$? +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "git show failure fails closed"; else bad "git show failure fails closed" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations printf '0' > "${TMP}/show_fails" From 8cc6eea2cb59af4d7ca7396891ab46dadca4fafc Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 21:03:15 +0100 Subject: [PATCH 25/53] ci: push-trigger pin-order gate and regex parity check --- .github/workflows/ci.yml | 11 +++-- docs/mobile-bindings.md | 9 +++- scripts/release/guard-release-refresh.sh | 18 ++++--- scripts/release/open-spm-pr.sh | 32 ++++++------ scripts/release/test-open-spm-pr.sh | 62 ++++++++++++++++++++++-- 5 files changed, 102 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04e6923..17ebd80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,12 @@ jobs: # touching Package.swift; branch protection can require it. pin-order: name: Pin ordering - if: github.event_name == 'pull_request' + # Covers human-opened pin PRs (pull_request) and manual/re-run pushes + # to the reserved namespace (push). Bot pin PRs opened with + # GITHUB_TOKEN do not emit either event; they are enforced at + # creation time by the release workflow's rewind guard, which also + # supersedes older open pin PRs. + if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/pin-spm-checksum-') runs-on: ubuntu-latest timeout-minutes: 15 env: @@ -33,8 +38,8 @@ jobs: persist-credentials: false - name: Refuse a downgrading pin env: - BASE_REF: ${{ github.base_ref }} - HEAD_REF: ${{ github.head_ref }} + BASE_REF: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.repository.default_branch }} + HEAD_REF: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} run: | # Single comparison implementation (scripts/release/semver.sh), # comment-stripped strict extraction, annotation-safe echoes — diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 068460b..78e9d25 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -174,8 +174,13 @@ release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM resolution for the release. The `ci.yml` "Pin ordering" gate refuses any -`Package.swift` change that is not a strictly-newer pin, so other edits -to that file require release-team coordination. Consumers never need a +`Package.swift` change that is not a strictly-newer pin from the +reserved `pin-spm-checksum-*` namespace, so other edits to that file +require release-team coordination. Recommended hardening: protect the +`pin-spm-checksum-*` branch namespace (restrict who may push it) so the +bot pin PR's head cannot be rewritten after the release workflow opens +it — bot pin PRs emit no pull_request CI events, so that protection is +the merge-time control for them. Consumers never need a Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 78c1b6b..16a59d9 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -55,15 +55,17 @@ fi # Fixed-string whole-line comparison (TAG may contain ERE metacharacters # such as '+'). pin_tag="$(printf '%s\n' "${origin_code}" \ - | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" -pin_sum_raw="$(printf '%s\n' "${origin_code}" \ - | grep -E '^checksum: ' | head -1 | grep -oE '"[^"]*"' | tr -d '"' || true)" -pin_sum="$(printf '%s\n' "${pin_sum_raw}" | grep -oE '^[0-9a-f]{64}$' || true)" + | grep -E '^let releaseTag = "wallet-bindings-v' | grep -oE 'wallet-bindings-v[^"]*')" +pin_sum="$(printf '%s\n' "${origin_code}" \ + | grep -E '^checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" +# A mangled releaseTag (e.g. bare 'wallet-bindings-v' with no version) +# must fail closed: clobbering assets on a main with a broken pin would +# desync SPM resolution exactly like a checksum mismatch would. +if [[ ! "${pin_tag}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${pin_tag}")" + exit 1 +fi if [ "${pin_tag}" = "${TAG}" ]; then - if [ -z "${pin_sum}" ]; then - echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${pin_sum_raw}")" - exit 1 - fi if [ "${pin_sum}" = "${XCSUM}" ]; then echo "rebuilt artifacts match the merged pin; asset refresh proceeds safely" exit 0 diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 4179906..d6f37ba 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -31,12 +31,10 @@ XCSUM="${3:?XCSUM required}" DEFAULT_BRANCH="${4:?DEFAULT_BRANCH required}" BRANCH="pin-spm-checksum-${VERSION}" -# The VERSION charset admits refname-invalid values ('..', trailing -# '.'): validate before any git operation fails late with a raw error. -git check-ref-format --branch "${BRANCH}" - # Mirror the workflow's validation so direct/manual invocations get the -# same fail-closed guarantees as the release run. +# same fail-closed guarantees as the release run. This runs before +# check-ref-format so git's raw multi-line stderr (which may contain +# unescaped, attacker-influenced bytes) can never reach the log. if [[ ! "${TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::tag does not match wallet-bindings-v" exit 1 @@ -45,6 +43,9 @@ if [[ ! "${VERSION}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-] echo "::error::version does not match " exit 1 fi + +git check-ref-format --branch "${BRANCH}" + if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]] || [ "${XCSUM//0/}" = "" ]; then echo "::error::checksum is not 64 lowercase hex characters (all-zero refused)" exit 1 @@ -161,17 +162,20 @@ origin_pin_sum_raw="$(printf '%s\n' "${origin_code}" \ origin_pin_sum="$(printf '%s\n' "${origin_pin_sum_raw}" \ | grep -oE '^[0-9a-f]{64}$' || true)" origin_pin_active=0 +origin_version="" if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ]; then origin_pin_active=1 fi -# The release marker must be parsable whenever it is present, active or -# deactivated: both gates rely on the version for ordering decisions. +# The release marker must be parsable whenever the assignment exists, +# active or deactivated: both gates rely on the version for ordering. +# An empty extraction (degenerate 'wallet-bindings-v' line) is itself +# unparseable. if [ -n "${origin_pin_tag}" ]; then origin_version="${origin_pin_tag#v}" - if [[ ! "${origin_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then - echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" - exit 1 - fi +fi +if [[ ! "${origin_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" + exit 1 fi if [ "${origin_pin_active}" = "1" ]; then cmp="$(semver_cmp "${VERSION}" "${origin_version}")" @@ -183,12 +187,12 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi -elif [ "$(printf '%s\n%s\n' "${origin_version:-0.0.0}" "${VERSION}" | sort -V | head -1)" = "${VERSION}" ] \ - && [ -n "${origin_version}" ]; then +elif [ "$(semver_cmp "${VERSION}" "${origin_version}")" -le 0 ]; then # A deactivated (zeroed-checksum) pin whose release marker is # newer-or-equal: main claims ${origin_version} with no active # checksum. Pinning ${VERSION} here would leave the marker and the - # checksum in conflict; manual repair required. + # checksum in conflict; manual repair required. semver_cmp keeps this + # aligned with the active-pin path at prerelease/build edges. echo "::error::origin/${DEFAULT_BRANCH} carries a deactivated pin for ${origin_version} (>= ${VERSION}); refusing to pin - repair the default branch manually" exit 1 elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 7888403..056d70b 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -697,6 +697,61 @@ else bad "supersede refuses a newer open pin PR" "exit ${rc}: $(cat "${OUT}")" fi +# 48b-2. Guard over a deactivated newer-or-equal marker: refresh allowed (rewind refusal enforced upstream by open-spm-pr.sh). +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v9.9.9" + checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated newer marker (enforced upstream)"; else bad "guard allows refresh over deactivated newer marker" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations + +# 48b-2b. Guard over a deactivated equal-version marker: refresh allowed (enforced upstream). +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3" + checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated equal marker (enforced upstream)"; else bad "guard allows refresh over deactivated equal marker" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations + +# 48b-2c. Guard: deactivated OLDER pin -> allow (forward release). +set_fixtures 0 1 'let releaseTag = "wallet-bindings-v0.1.0" + checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi + +# 48b-2d. Supersede: meta-suffix stale marker (>= precedence) -> refuse. +set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer +: > "${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 "close or merge it before releasing" <<< "$(cat "${OUT}")"; then + ok "supersede refuses meta-suffix stale pin" +else + bad "supersede refuses meta-suffix stale pin" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations +printf 'placeholder\n' > "${STUBS}/repo/Package.swift" + # 48. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" @@ -722,10 +777,11 @@ TAG_REGEX='^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za- wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release.yml" || true)" sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" gd="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/guard-release-refresh.sh" || true)" -if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "1" ]; then - ok "tag regex identical across all five copies" +cy="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/ci.yml" || true)" +if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "1" ]; then + ok "tag regex identical across all seven copies" else - bad "tag regex identical across all five copies" "release.yml=${wf}, script=${sc}, guard=${gd}" + bad "tag regex identical across all seven copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}" fi echo "passed: ${pass}, failed: ${fail}" From d44553d7ffd0106c136efc2c79b81ba659dc40e4 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 21:19:38 +0100 Subject: [PATCH 26/53] ci: trusted-base gate checkout and namespace push trigger --- .github/workflows/ci.yml | 27 +++++++++++++++------------ docs/mobile-bindings.md | 17 +++++++++-------- scripts/release/check-pin-order.sh | 20 +++++++++++++++----- scripts/release/open-spm-pr.sh | 2 +- scripts/release/test-open-spm-pr.sh | 14 +++++++------- 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17ebd80..d695e90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [main] + branches: [main, 'pin-spm-checksum-**'] paths-ignore: [".github/**"] pull_request: branches: [main] @@ -32,14 +32,18 @@ jobs: env: LC_ALL: C steps: + # Check out the BASE ref: the gate code and the current pin state + # come from the trusted branch, never from PR-supplied content. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: + ref: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref }} fetch-depth: 0 persist-credentials: false - name: Refuse a downgrading pin env: BASE_REF: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.repository.default_branch }} HEAD_REF: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} + HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} run: | # Single comparison implementation (scripts/release/semver.sh), # comment-stripped strict extraction, annotation-safe echoes — @@ -52,9 +56,13 @@ jobs: echo "Package.swift untouched; nothing to check" exit 0 fi - # Pin PRs must come from the reserved bot branch, which names - # the release it pins; the gate cross-checks the PR head's - # Package.swift against that tag (strict mode). + # The expected tag is derived from the reserved bot branch + # name (which names the release it pins) and cross-checked + # against the PR head's Package.swift (strict mode). NOTE: bot + # pin PRs opened with GITHUB_TOKEN do not emit pull_request + # events; they are enforced at creation time by the release + # workflow's rewind guard, which also supersedes older open + # pin PRs (no merge-order rewind). case "$HEAD_REF" in pin-spm-checksum-*) expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" @@ -64,18 +72,13 @@ jobs: exit 1 ;; esac - # Branch names may contain '%': reject anything outside the - # tag charset before it reaches annotations or comparisons. - # NOTE: this pull_request gate covers human-opened pin PRs; a - # bot pin PR (opened with GITHUB_TOKEN) does not emit - # pull_request events, so it is enforced at creation time by - # the release workflow's rewind guard, which also supersedes - # older open pin PRs (no merge-order rewind). if [[ ! "$expected_tag" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::derived tag does not match wallet-bindings-v" exit 1 fi - scripts/release/check-pin-order.sh "$BASE_REF" "$expected_tag" + # Gate code is the trusted base checkout; the PR head's + # Package.swift is consumed purely as data via its SHA. + scripts/release/check-pin-order.sh "$BASE_REF" "$expected_tag" "$HEAD_SHA" fmt: name: Format diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 78e9d25..b580e13 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -173,14 +173,15 @@ tagged commit, attaches them with a `SHA256SUMS` manifest to the GitHub release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM -resolution for the release. The `ci.yml` "Pin ordering" gate refuses any -`Package.swift` change that is not a strictly-newer pin from the -reserved `pin-spm-checksum-*` namespace, so other edits to that file -require release-team coordination. Recommended hardening: protect the -`pin-spm-checksum-*` branch namespace (restrict who may push it) so the -bot pin PR's head cannot be rewritten after the release workflow opens -it — bot pin PRs emit no pull_request CI events, so that protection is -the merge-time control for them. Consumers never need a +resolution for the release. The `ci.yml` "Pin ordering" gate runs on every pull_request or push +that touches `Package.swift`: the gate code is checked out from the +base branch (PR content cannot alter the enforcement logic), and a pin +PR that does not advance the pinned release is refused — so other edits +to `Package.swift` require release-team coordination. Recommended +hardening: protect the `pin-spm-checksum-*` branch namespace (restrict +who may push it) — bot pin PRs opened with the workflow token emit no +pull_request CI events, so namespace protection plus the creation-time +rewind guard are the controls for them. Consumers never need a Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 2ce0749..668778c 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -19,7 +19,8 @@ source "${BASH_SOURCE[0]%/*}/pinlib.sh" source "${BASH_SOURCE[0]%/*}/semver.sh" BASE_BRANCH="${1:?base branch required}" -EXPECTED_TAG="${2:-}" +EXPECTED_TAG="${2:?expected tag required}" +INCOMING_REF="${3:-}" if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ || [[ "${BASE_BRANCH}" == pin-spm-checksum-* ]]; then echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" @@ -30,11 +31,20 @@ if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9] exit 1 fi -if [ ! -r Package.swift ]; then - echo "::error::cannot read Package.swift" - exit 1 +# The incoming pin comes from the PR head SHA (workflow) or the working +# tree (legacy/harness) — always consumed as data by this trusted code. +if [ -n "${INCOMING_REF}" ]; then + normalized_in="$(strip_swift_comments "$(git show "${INCOMING_REF}:Package.swift" 2>/dev/null)")" || { + echo "::error::cannot read Package.swift from ${INCOMING_REF}" + exit 1 + } +else + if [ ! -r Package.swift ]; then + echo "::error::cannot read Package.swift" + exit 1 + fi + normalized_in="$(strip_swift_comments "$(cat Package.swift)")" fi -normalized_in="$(strip_swift_comments "$(cat Package.swift)")" # Strict mode when the expected tag is known (ci.yml derives it from # the reserved bot branch name): the normalized code must contain # exactly that assignment and NO other releaseTag- or checksum-bearing diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index d6f37ba..9526772 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -187,7 +187,7 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi -elif [ "$(semver_cmp "${VERSION}" "${origin_version}")" -le 0 ]; then +elif { cmp="$(semver_cmp "${VERSION}" "${origin_version}")"; [[ "${cmp}" =~ ^-?[012]$ ]]; } && [ "${cmp}" -le 0 ]; then # A deactivated (zeroed-checksum) pin whose release marker is # newer-or-equal: main claims ${origin_version} with no active # checksum. Pinning ${VERSION} here would leave the marker and the diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 056d70b..c1b29d0 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -432,7 +432,7 @@ else fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 31. Build metadata is excluded from precedence: an origin pin of +# 31. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. # 32.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... checksum: "'"${XCSUM}"'"' pr.none @@ -540,7 +540,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 # 39. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the script refuse (fail closed). -printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ bash "${UNDER_TEST}" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" "${XCSUM}" main \ @@ -551,7 +551,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 # 40. Comment decoys claiming THIS tag+checksum while the real code pin # differs -> comment stripping makes the guard refuse (fail closed). -printf '// checksum: "1111111111111111111111111111111111111111111111111111111111111111"\n// let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" main \ @@ -604,21 +604,21 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3+meta"\nchecksum: "cad323bf1d59c printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" main >/dev/null 2>&1 ) + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "0" ]; then ok "pin order allows upgrade"; else bad "pin order allows upgrade" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" main >/dev/null 2>&1 ) + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses downgrade"; else bad "pin order refuses downgrade" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" main >/dev/null 2>&1 ) + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses same version"; else bad "pin order refuses same version" "exit ${rc}"; fi @@ -649,7 +649,7 @@ printf '1' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" main >/dev/null 2>&1 ) + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else bad "pin order fails closed on git show error" "exit ${rc}"; fi printf '0' > "${TMP}/show_fails" From 67203c56a5ec0bdd83bf060c18bd7db5cb8899ed Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 21:19:51 +0100 Subject: [PATCH 27/53] ci: fix stale case comment --- scripts/release/test-open-spm-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index c1b29d0..a1d8c5f 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -433,7 +433,7 @@ fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" # 31. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. -# 32.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. +# 32. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" From 3e6412a57d7310a1126c80996e1364ac5ca912c3 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 21:33:38 +0100 Subject: [PATCH 28/53] ci: pin setup node to a real release commit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d695e90..a6454ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -186,7 +186,7 @@ jobs: persist-credentials: false - uses: dtolnay/rust-toolchain@ffaa7fb73f2b6e3c49bc425913220fa3d71c3ee5 # 1.92.0 - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 - - uses: actions/setup-node@60edb5dd545a736178b549f63364a802f016e4f3 # v4 + - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 with: node-version: 20 cache: npm From 0401bac543a63012d37540778ec3b75699d2aac7 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 21:48:28 +0100 Subject: [PATCH 29/53] ci: fetch the pr head for the pin gate and refresh guard origin --- .github/workflows/ci.yml | 28 +++++++++++++----- docs/mobile-bindings.md | 6 ++-- scripts/release/check-pin-order.sh | 13 +++++---- scripts/release/guard-release-refresh.sh | 7 +++++ scripts/release/test-open-spm-pr.sh | 37 +++++++++++++++++------- 5 files changed, 64 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6454ae..2ca147c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,8 +32,11 @@ jobs: env: LC_ALL: C steps: - # Check out the BASE ref: the gate code and the current pin state - # come from the trusted branch, never from PR-supplied content. + # On pull_request events the gate code and the current pin state + # come from the trusted base branch; PR content is only ever read + # as data. On push events the pushed branch's code runs, which is + # ordinary branch-CI privilege (read-only, no secrets) under the + # documented force-push risk of the reserved namespace. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref }} @@ -41,6 +44,8 @@ jobs: persist-credentials: false - name: Refuse a downgrading pin env: + EVENT_NAME: ${{ github.event_name }} + PR_NUMBER: ${{ github.event.pull_request.number }} BASE_REF: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.repository.default_branch }} HEAD_REF: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} @@ -52,10 +57,6 @@ jobs: echo "::error::unexpected base branch" exit 1 fi - if ! git diff --name-only "origin/${BASE_REF}...HEAD" | grep -q '^Package.swift$'; then - echo "Package.swift untouched; nothing to check" - exit 0 - fi # The expected tag is derived from the reserved bot branch # name (which names the release it pins) and cross-checked # against the PR head's Package.swift (strict mode). NOTE: bot @@ -68,14 +69,25 @@ jobs: expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" ;; *) - echo "::error::pin PR must originate from a pin-spm-checksum-* branch" - exit 1 + echo "not a pin branch; nothing to check" + exit 0 ;; esac if [[ ! "$expected_tag" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::derived tag does not match wallet-bindings-v" exit 1 fi + # The checkout is the base branch; pull the PR head commit so + # the diff below and check-pin-order.sh's data-only read of + # the head's Package.swift can see it (push events already + # have their SHA locally). + if [ "$EVENT_NAME" = "pull_request" ]; then + git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head" + fi + if ! git diff --name-only "origin/${BASE_REF}...${HEAD_SHA}" | grep -q '^Package.swift$'; then + echo "Package.swift untouched; nothing to check" + exit 0 + fi # Gate code is the trusted base checkout; the PR head's # Package.swift is consumed purely as data via its SHA. scripts/release/check-pin-order.sh "$BASE_REF" "$expected_tag" "$HEAD_SHA" diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index b580e13..6eb8318 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -174,8 +174,10 @@ release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM resolution for the release. The `ci.yml` "Pin ordering" gate runs on every pull_request or push -that touches `Package.swift`: the gate code is checked out from the -base branch (PR content cannot alter the enforcement logic), and a pin +that touches `Package.swift`. On pull_request events the gate code is +checked out from the base branch (PR content cannot alter the +enforcement logic); on push events the pushed branch's code runs with +ordinary branch-CI privilege. Either way, a pin PR that does not advance the pinned release is refused — so other edits to `Package.swift` require release-team coordination. Recommended hardening: protect the `pin-spm-checksum-*` branch namespace (restrict diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 668778c..54933f2 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -4,11 +4,12 @@ # pinned on the default branch (same-version repairs are manual: the # rewind guard in open-spm-pr.sh refuses to create them). # -# Usage: check-pin-order.sh [EXPECTED_TAG] +# Usage: check-pin-order.sh [INCOMING_REF] # Run from the repo root in the PR checkout; LC_ALL=C is enforced -# internally. With EXPECTED_TAG (derived by ci.yml from the reserved -# bot branch name), strict mode additionally requires the PR head to -# carry exactly that assignment and no other pin-bearing line. +# internally. EXPECTED_TAG (derived by ci.yml from the reserved bot +# branch name) is required: strict mode requires the incoming checkout +# (INCOMING_REF, else the working tree) to carry exactly that +# assignment and no other pin-bearing line. set -euo pipefail export LC_ALL=C @@ -26,7 +27,7 @@ if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" exit 1 fi -if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then +if [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::unexpected expected tag: $(esc "${EXPECTED_TAG}")" exit 1 fi @@ -35,7 +36,7 @@ fi # tree (legacy/harness) — always consumed as data by this trusted code. if [ -n "${INCOMING_REF}" ]; then normalized_in="$(strip_swift_comments "$(git show "${INCOMING_REF}:Package.swift" 2>/dev/null)")" || { - echo "::error::cannot read Package.swift from ${INCOMING_REF}" + echo "::error::cannot read Package.swift from $(esc "${INCOMING_REF}")" exit 1 } else diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 16a59d9..2c45bad 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -34,6 +34,13 @@ if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ exit 1 fi +# Refresh origin/ so the pin state reflects main as of now, +# not the checkout snapshot: a pin PR merged while this release run is +# in flight must be visible before any --clobber upload. Fatal on +# failure: without an up-to-date view the guard cannot decide. +git fetch origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}" \ + || { echo "::error::cannot refresh origin/${DEFAULT_BRANCH}"; exit 1; } + # Only real code lines constitute the pin: block comments, line # comments, and their decoy literals are all ignored (shared stripper). origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" \ diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index a1d8c5f..821b896 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -56,6 +56,9 @@ case "$1 $2" in "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "rev-parse --is-shallow-repository") cat "${CASE_DIR}/is_shallow" ;; + "fetch origin") + [ "$(cat "${CASE_DIR}/fetch_fails" 2>/dev/null || echo 0)" = "1" ] && exit 1 + exit 0 ;; "rev-parse HEAD") cat "${CASE_DIR}/head_commit" ;; "show origin/"*) if [ "$(cat "${CASE_DIR}/show_fails" 2>/dev/null || echo 0)" = "1" ]; then @@ -433,7 +436,6 @@ fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" # 31. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. -# 32. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -538,26 +540,39 @@ assert_no_mutations printf '0' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 39. Comment decoys claiming THIS tag+checksum while the real code pin -# differs -> comment stripping makes the script refuse (fail closed). -printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +# 39. Comment decoys inside an unterminated block comment; the real +# code pin (v1.0.0) follows the block. Correct stripping sees 1.2.3 > +# 1.0.0 and allows; a stripping regression leaks the decoys (mangled +# multi-pin state, or >= the incoming version) and refuses. +printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\n*/\nlet releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ - bash "${UNDER_TEST}" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" "${XCSUM}" main \ + bash "${UNDER_TEST}" wallet-bindings-v1.2.3 1.2.3 "${XCSUM}" main \ >/dev/null 2>&1 ) rc=$? -if [ "${rc}" = "1" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi +if [ "${rc}" = "0" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 40. Comment decoys claiming THIS tag+checksum while the real code pin -# differs -> comment stripping makes the guard refuse (fail closed). -printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" +# 40. Same decoy shape for the guard: real v1.0.0 pin follows the +# block, so the refresh (1.2.3 > 1.0.0) must be allowed. +printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\n*/\nlet releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "1111111111111111111111111111111111111111111111111111111111111111" main \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi + +# 40b. Guard: a failed origin refresh must fail closed (no clobber +# decision can be made against a stale pin view). +printf '1' > "${TMP}/fetch_fails" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ >/dev/null 2>&1 ) rc=$? -if [ "${rc}" = "1" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi +printf '0' > "${TMP}/fetch_fails" +if [ "${rc}" = "1" ]; then ok "guard origin refresh failure fails closed"; else bad "guard origin refresh failure fails closed" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" # 41. Guard: zero releaseTag assignments -> refuse. From 7d3cb2d1c788f15467a70a0be257d019dc9e2ae6 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 22:00:14 +0100 Subject: [PATCH 30/53] ci: fail the pin diff closed and test the ref read path --- .github/workflows/ci.yml | 11 +- .github/workflows/release.yml | 4 + docs/mobile-bindings.md | 20 ++-- scripts/release/check-pin-order.sh | 34 +++---- scripts/release/test-open-spm-pr.sh | 149 +++++++++++++++++----------- 5 files changed, 129 insertions(+), 89 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ca147c..831c2da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,16 @@ jobs: if [ "$EVENT_NAME" = "pull_request" ]; then git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head" fi - if ! git diff --name-only "origin/${BASE_REF}...${HEAD_SHA}" | grep -q '^Package.swift$'; then + # Fail closed on diff errors: an unreadable head (e.g. a + # force-push landing between event emission and the fetch) + # must not masquerade as "Package.swift untouched". The head + # fetch is anonymous, so private repositories fail closed + # here rather than silently skipping the gate. + if ! head_files="$(git diff --name-only "origin/${BASE_REF}...${HEAD_SHA}")"; then + echo "::error::cannot diff the incoming pin against origin/${BASE_REF}" + exit 1 + fi + if ! printf '%s\n' "${head_files}" | grep -q '^Package.swift$'; then echo "Package.swift untouched; nothing to check" exit 0 fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ac29543..e60ab06 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -257,6 +257,10 @@ jobs: # rebuild is not bit-reproducible, clobbering would desync the # published artifacts from the merged checksum. Fail closed # before any public mutation; forward releases are unaffected. + # Its origin refresh needs a git credential helper (the + # checkout persists none) or private repositories would fail + # every release here. + gh auth setup-git scripts/release/guard-release-refresh.sh "$TAG" "$XCSUM" "$DEFAULT_BRANCH" if gh release view "$TAG" >/dev/null 2>&1; then echo "release $TAG already exists; refreshing assets" diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 6eb8318..30d8569 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -173,15 +173,17 @@ tagged commit, attaches them with a `SHA256SUMS` manifest to the GitHub release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM -resolution for the release. The `ci.yml` "Pin ordering" gate runs on every pull_request or push -that touches `Package.swift`. On pull_request events the gate code is -checked out from the base branch (PR content cannot alter the -enforcement logic); on push events the pushed branch's code runs with -ordinary branch-CI privilege. Either way, a pin -PR that does not advance the pinned release is refused — so other edits -to `Package.swift` require release-team coordination. Recommended -hardening: protect the `pin-spm-checksum-*` branch namespace (restrict -who may push it) — bot pin PRs opened with the workflow token emit no +resolution for the release. The `ci.yml` "Pin ordering" gate enforces +release order on the `pin-spm-checksum-*` branch namespace: pull +requests or pushes whose head branch carries a checksum pin are +refused unless they advance the release currently pinned on the +default branch. On pull_request events the gate code is checked out +from the base branch (PR content cannot alter the enforcement logic); +on push events the pushed branch's code runs with ordinary branch-CI +privilege. Other (non-namespace) edits to `Package.swift` are NOT +order-checked by CI — they rely on review and branch protection on +the default branch. Recommended hardening: protect the +`pin-spm-checksum-*` branch namespace (restrict who may push it) — bot pin PRs opened with the workflow token emit no pull_request CI events, so namespace protection plus the creation-time rewind guard are the controls for them. Consumers never need a Rust toolchain. diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 54933f2..47cad28 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -46,27 +46,19 @@ else fi normalized_in="$(strip_swift_comments "$(cat Package.swift)")" fi -# Strict mode when the expected tag is known (ci.yml derives it from -# the reserved bot branch name): the normalized code must contain -# exactly that assignment and NO other releaseTag- or checksum-bearing -# line, so comment/nesting text tricks fail closed. -if [ -n "${EXPECTED_TAG}" ]; then - expected_lines="$(printf '%s\n' "${normalized_in}" | grep -cF -x -- "let releaseTag = \"${EXPECTED_TAG}\"" || true)" - # Anchored counts: the URL line interpolates \(releaseTag), so a - # substring 'releaseTag' count would double-count the real shape. - release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^let releaseTag = ' || true)" - checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "' || true)" - checksum_valid="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" - if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] \ - || [ "${checksum_lines}" != "1" ] || [ "${checksum_valid}" != "1" ]; then - echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous, missing, or non-hex checksum)" - exit 1 - fi -fi -incoming_matches="$(printf '%s\n' "${normalized_in}" \ - | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" -if [ "${incoming_matches}" != "1" ]; then - echo "::error::expected exactly one releaseTag assignment on the PR head, found ${incoming_matches}" +# Strict mode (EXPECTED_TAG is required; ci.yml derives it from the +# reserved bot branch name): the normalized code must contain exactly +# that assignment and NO other releaseTag- or checksum-bearing line, +# so comment/nesting text tricks fail closed. +expected_lines="$(printf '%s\n' "${normalized_in}" | grep -cF -x -- "let releaseTag = \"${EXPECTED_TAG}\"" || true)" +# Anchored counts: the URL line interpolates \(releaseTag), so a +# substring 'releaseTag' count would double-count the real shape. +release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^let releaseTag = ' || true)" +checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "' || true)" +checksum_valid="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" +if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] \ + || [ "${checksum_lines}" != "1" ] || [ "${checksum_valid}" != "1" ]; then + echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous, missing, or non-hex checksum)" exit 1 fi incoming_tag="$(printf '%s\n' "${normalized_in}" \ diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 821b896..0c3e879 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -56,7 +56,7 @@ case "$1 $2" in "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "rev-parse --is-shallow-repository") cat "${CASE_DIR}/is_shallow" ;; - "fetch origin") + "fetch origin" | "fetch --unshallow") [ "$(cat "${CASE_DIR}/fetch_fails" 2>/dev/null || echo 0)" = "1" ] && exit 1 exit 0 ;; "rev-parse HEAD") cat "${CASE_DIR}/head_commit" ;; @@ -65,6 +65,11 @@ case "$1 $2" in exit 1 fi cat "${CASE_DIR}/origin_swift" ;; + show\ *:*) + if [ "$(cat "${CASE_DIR}/incoming_show_fails" 2>/dev/null || echo 0)" = "1" ]; then + exit 1 + fi + cat "${CASE_DIR}/incoming_swift" ;; rev-parse\ refs/tags/*) cat "${CASE_DIR}/tag_commit" ;; "checkout -B") cp "${CASE_DIR}/package_swift" "$(dirname "$0")/repo/Package.swift" @@ -233,13 +238,13 @@ set_fixtures 0 1 "${STALE_CKSUM}" pr.none run_case "mirror drift (tag new, checksum stale) fails" 1 assert_no_mutations -# 5c. Pin already merged: Package.swift identical to the default branch +# 7. Pin already merged: Package.swift identical to the default branch # -> short-circuit success even though the checkout diff is non-empty. set_fixtures 0 1 "${FULLY_PINNED}" pr.none 0 run_case "already-merged pin exits 0" 0 assert_no_mutations -# 7. Open same-repo PR against main -> detected, no duplicate create. +# 8. Open same-repo PR against main -> detected, no duplicate create. set_fixtures 0 1 "${FULLY_PINNED}" pr.own : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -255,7 +260,7 @@ else ok "no duplicate create" fi -# 8. Open different-owner PR with colliding head branch -> create proceeds. +# 9. Open different-owner PR with colliding head branch -> create proceeds. set_fixtures 0 1 "${FULLY_PINNED}" pr.evillow run_case "different-owner PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -264,7 +269,7 @@ else bad "create despite different-owner PR" "${LOG_CONTENTS}" fi -# 9. Open fork PR with colliding head branch -> create proceeds. +# 10. Open fork PR with colliding head branch -> create proceeds. set_fixtures 0 1 "${FULLY_PINNED}" pr.fork run_case "fork PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -273,7 +278,7 @@ else bad "create despite fork PR" "${LOG_CONTENTS}" fi -# 10. Open same-owner PR against a non-default base -> create proceeds. +# 11. Open same-owner PR against a non-default base -> create proceeds. set_fixtures 0 1 "${FULLY_PINNED}" pr.wrongbase run_case "wrong-base PR ignored, create proceeds" 0 if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then @@ -282,40 +287,40 @@ else bad "create despite wrong-base PR" "${LOG_CONTENTS}" fi -# 11. Malformed repository owner -> fail closed. +# 12. Malformed repository owner -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "invalid owner fails" 1 "bad..owner/rust-sdk" assert_no_mutations -# 12. Malformed DEFAULT_BRANCH -> fail closed before any fetch. +# 13. Malformed DEFAULT_BRANCH -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid default branch fails" 1 "mintlayer/rust-sdk" $'ma\tin' assert_no_mutations -# 13. Malformed XCSUM -> fail closed before any fetch. +# 14. Malformed XCSUM -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid checksum fails" 1 "mintlayer/rust-sdk" main "xyz" assert_no_mutations -# 14. HEAD is not the tagged commit -> fail closed, no push. +# 15. HEAD is not the tagged commit -> fail closed, no push. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'othercommitsha' > "${TMP}/head_commit" run_case "HEAD differs from tag fails" 1 assert_no_mutations printf 'tagcommitsha' > "${TMP}/head_commit" -# 15. All-zero checksum -> fail closed before any fetch. +# 16. All-zero checksum -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "all-zero checksum fails" 1 "mintlayer/rust-sdk" main \ "0000000000000000000000000000000000000000000000000000000000000000" assert_no_mutations -# 16. VERSION that is not semver -> fail closed before any fetch. +# 17. VERSION that is not semver -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 assert_no_mutations -# 17. TAG not matching the release pattern -> fail closed before fetch. +# 18. TAG not matching the release pattern -> fail closed before fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid tag (no patch) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2 "wallet-bindings-v1.2" assert_no_mutations @@ -323,12 +328,12 @@ set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "invalid tag (wrong prefix) fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 1.2.3 "evil-wallet-bindings-v1.2.3" assert_no_mutations -# 18. Default branch inside the reserved namespace -> fail closed. +# 19. Default branch inside the reserved namespace -> fail closed. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "reserved-namespace default branch fails" 1 "mintlayer/rust-sdk" "pin-spm-checksum-1.2.3" assert_no_mutations -# 19. Shallow clone -> the unshallow fetch is used. +# 20. Shallow clone -> the unshallow fetch is used. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'true' > "${TMP}/is_shallow" run_case "shallow clone unshallows" 0 @@ -339,7 +344,7 @@ else fi printf 'false' > "${TMP}/is_shallow" -# 20. Complete clone -> plain fetch with the explicit full refspec. +# 21. Complete clone -> plain fetch with the explicit full refspec. set_fixtures 0 1 "${FULLY_PINNED}" pr.none run_case "complete clone plain fetch" 0 if grep -q -- "fetch origin +refs/heads/main:refs/remotes/origin/main" <<< "${LOG_CONTENTS}"; then @@ -348,13 +353,13 @@ else bad "plain fetch carries the full refspec" "${LOG_CONTENTS}" fi -# 21. Default branch already pins a DIFFERENT release -> fail closed. +# 22. Default branch already pins a DIFFERENT release -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "stale tag against a newer pin fails" 1 assert_no_mutations -# 22. Forward release over an OLDER active pin -> allowed. +# 23. Forward release over an OLDER active pin -> allowed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" run_case "forward release over older pin proceeds" 0 @@ -365,47 +370,47 @@ else fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 23. Same-version active pin with differing content -> rewind guard. +# 24. Same-version active pin with differing content -> rewind guard. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" run_case "same-version conflicting pin fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 24. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. +# 25. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '128' > "${TMP}/ancestry" run_case "merge-base git error fails" 1 assert_no_mutations printf '0' > "${TMP}/ancestry" -# 25. Unparseable origin pin tag -> fail closed. +# 26. Unparseable origin pin tag -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-vx"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "unparseable origin pin tag fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 26. Active checksum with missing tag line -> fail closed (one-sided). +# 27. Active checksum with missing tag line -> fail closed (one-sided). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "one-sided active checksum fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 27. TAG/VERSION mismatch -> fail closed before any fetch. +# 28. TAG/VERSION mismatch -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "mismatched tag and version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 9.9.9 assert_no_mutations -# 28. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. +# 29. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "deadbeef"\n' > "${TMP}/origin_swift" run_case "mangled origin checksum fails" 1 assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 29. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. +# 30. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-rc.1" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -419,7 +424,7 @@ if [ "${rc}" = "1" ]; then ok "prerelease after final refused"; else bad "prerel assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 30. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. +# 31. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3-rc1"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" : > "${LOG}" @@ -435,7 +440,7 @@ else fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 31. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. +# 32. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -449,7 +454,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "build-metadata equal precedence refused"; else bad "build-metadata equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 29c. Origin pin without metadata vs incoming with metadata: equal +# 33. Origin pin without metadata vs incoming with metadata: equal # precedence -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta" // ... checksum: "'"${XCSUM}"'"' pr.none @@ -464,7 +469,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 33. Guard: mangled checksum (65+ hex) on origin -> fail closed. +# 34. Guard: mangled checksum (65+ hex) on origin -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b9700"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -475,7 +480,7 @@ rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses 65-hex checksum"; else bad "guard refuses 65-hex checksum" "exit ${rc}"; fi assert_no_mutations -# 34. Huge numeric prerelease identifiers compare by (digit length, +# 35. Huge numeric prerelease identifiers compare by (digit length, # bytes) — no arithmetic — so an origin pin of rc<20 digits> still # outranks incoming rc.2 -> refused, no arithmetic wrap. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-2" // ... @@ -492,7 +497,7 @@ if [ "${rc}" = "1" ]; then ok "huge numeric prerelease refused without wrap"; el assert_no_mutations printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 35. Guard script: same tag + differing checksum -> refuse. +# 36. Guard script: same tag + differing checksum -> refuse. GUARD="${SCRIPT_DIR}/guard-release-refresh.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -502,7 +507,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses mismatched rebuild"; else bad "guard refuses mismatched rebuild" "exit ${rc}"; fi -# 36. Guard script: same tag + identical checksum (with a header +# 37. Guard script: same tag + identical checksum (with a header # comment whose version literal differs) -> allow. set_fixtures 0 1 "${FULLY_PINNED}" pr.none # shellcheck disable=SC2016 # \n are printf escapes, no expansion @@ -515,7 +520,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "0" ]; then ok "guard allows identical rebuild"; else bad "guard allows identical rebuild" "exit ${rc}"; fi -# 37. Guard script: older pin on main (forward release) -> allow. +# 38. Guard script: older pin on main (forward release) -> allow. printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -525,7 +530,7 @@ rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 38. git show fails -> open-spm-pr.sh fails closed (no silent skip). +# 39. git show fails -> open-spm-pr.sh fails closed (no silent skip). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '1' > "${TMP}/show_fails" : > "${LOG}" @@ -540,7 +545,7 @@ assert_no_mutations printf '0' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 39. Comment decoys inside an unterminated block comment; the real +# 40. Comment decoys inside an unterminated block comment; the real # code pin (v1.0.0) follows the block. Correct stripping sees 1.2.3 > # 1.0.0 and allows; a stripping regression leaks the decoys (mangled # multi-pin state, or >= the incoming version) and refuses. @@ -553,7 +558,7 @@ rc=$? if [ "${rc}" = "0" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 40. Same decoy shape for the guard: real v1.0.0 pin follows the +# 41. Same decoy shape for the guard: real v1.0.0 pin follows the # block, so the refresh (1.2.3 > 1.0.0) must be allowed. printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\n*/\nlet releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -563,7 +568,7 @@ printf '/*\nchecksum: "111111111111111111111111111111111111111111111111111111111 rc=$? if [ "${rc}" = "0" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi -# 40b. Guard: a failed origin refresh must fail closed (no clobber +# 42. Guard: a failed origin refresh must fail closed (no clobber # decision can be made against a stale pin view). printf '1' > "${TMP}/fetch_fails" ( cd "${STUBS}/repo" && \ @@ -575,7 +580,7 @@ printf '0' > "${TMP}/fetch_fails" if [ "${rc}" = "1" ]; then ok "guard origin refresh failure fails closed"; else bad "guard origin refresh failure fails closed" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 41. Guard: zero releaseTag assignments -> refuse. +# 43. Guard: zero releaseTag assignments -> refuse. printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -584,7 +589,7 @@ printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000 rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses zero assignments"; else bad "guard refuses zero assignments" "exit ${rc}"; fi -# 42. Guard: two releaseTag assignments -> refuse. +# 44. Guard: two releaseTag assignments -> refuse. printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -593,7 +598,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bind rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses duplicate assignments"; else bad "guard refuses duplicate assignments" "exit ${rc}"; fi -# 43. Guard: invalid checksum -> refuse. +# 45. Guard: invalid checksum -> refuse. printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -602,7 +607,7 @@ printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "000 rc=$? if [ "${rc}" = "1" ]; then ok "guard rejects invalid checksum"; else bad "guard rejects invalid checksum" "exit ${rc}"; fi -# 44. Guard: git show failure -> fail closed. +# 46. Guard: git show failure -> fail closed. printf '1' > "${TMP}/show_fails" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -613,7 +618,7 @@ if [ "${rc}" = "1" ]; then ok "guard fails closed on git show failure"; else bad printf '0' > "${TMP}/show_fails" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 45. Pin-order script: upgrade allows, downgrade refuses, same refuses. +# 47. Pin-order script: upgrade allows, downgrade refuses, same refuses. ORDER="${SCRIPT_DIR}/check-pin-order.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3+meta"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" @@ -626,31 +631,49 @@ if [ "${rc}" = "0" ]; then ok "pin order allows upgrade"; else bad "pin order al printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) + bash "${ORDER}" main "wallet-bindings-v0.9.0" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses downgrade"; else bad "pin order refuses downgrade" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) + bash "${ORDER}" main "wallet-bindings-v1.2.3" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses same version"; else bad "pin order refuses same version" "exit ${rc}"; fi -# 46. Reserved-namespace base branch -> fail closed. +# 48. Production form: the incoming pin read from an INCOMING_REF +# (the PR head SHA) rather than the working tree. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +printf 'placeholder\n' > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" 0123456789abcdef0123456789abcdef01234567 >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "pin order reads the incoming pin from a ref"; else bad "pin order reads the incoming pin from a ref" "exit ${rc}"; fi + +# 49. Same, but the ref read fails -> fail closed (esc'd annotation). +printf '1' > "${TMP}/incoming_show_fails" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" 0123456789abcdef0123456789abcdef01234567 >/dev/null 2>&1 ) +rc=$? +printf '0' > "${TMP}/incoming_show_fails" +if [ "${rc}" = "1" ]; then ok "pin order fails closed on an unreadable incoming ref"; else bad "pin order fails closed on an unreadable incoming ref" "exit ${rc}"; fi + +# 50. Reserved-namespace base branch -> fail closed. # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ - bash "${ORDER}" "pin-spm-checksum-1.2.3" >/dev/null 2>&1 ) + bash "${ORDER}" "pin-spm-checksum-1.2.3" "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "1" ]; then ok "pin order rejects reserved namespace"; else bad "pin order rejects reserved namespace" "exit ${rc}"; fi -# 38c. Ambiguous PR head (a second releaseTag line) -> strict mode +# 51. Ambiguous PR head (a second releaseTag line) -> strict mode # refuses: the normalized head must carry exactly the expected # assignment and no other releaseTag- or checksum-bearing line. -# shellcheck disable=SC2016 # fixture line content is not expanded -printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\nlet releaseTag = "wallet-bindings-v1.2.3"\n' > "${STUBS}/repo/Package.swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\nlet releaseTag = "wallet-bindings-v1.2.3"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -658,7 +681,17 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses ambiguous PR head"; else bad "pin order refuses ambiguous PR head" "exit ${rc}"; fi -# 47. git show failure on the base -> fail closed. +# 52. Single-defect counterpart: exactly the expected head but a +# non-hex checksum -> strict mode refuses. +# shellcheck disable=SC2016 # fixture line content is not expanded +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order refuses a non-hex checksum"; else bad "pin order refuses a non-hex checksum" "exit ${rc}"; fi + +# 53. git show failure on the base -> fail closed. printf '1' > "${TMP}/show_fails" # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" @@ -670,7 +703,7 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else b printf '0' > "${TMP}/show_fails" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 48a. Strict mode PASS path over the REAL root Package.swift shape: +# 54. Strict mode PASS path over the REAL root Package.swift shape: # header comment, the download URL interpolating \(releaseTag) (which a # substring 'releaseTag' count would double-count), releaseTag at # column 0, checksum indented 12 spaces. @@ -683,7 +716,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "0" ]; then ok "strict mode passes the real Package.swift shape"; else bad "strict mode passes the real Package.swift shape" "exit ${rc}"; fi -# 48b. Supersede: an older stale pin PR is closed. +# 55. Supersede: an older stale pin PR is closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_older printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" : > "${LOG}" @@ -698,7 +731,7 @@ else bad "supersede closes the older stale pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 48c. Supersede: a newer open pin PR refuses the run. +# 56. Supersede: a newer open pin PR refuses the run. cp "${TMP}/pr.stale_newer" "${TMP}/existing_pr" : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -712,7 +745,7 @@ else bad "supersede refuses a newer open pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 48b-2. Guard over a deactivated newer-or-equal marker: refresh allowed (rewind refusal enforced upstream by open-spm-pr.sh). +# 57. Guard over a deactivated newer-or-equal marker: refresh allowed (rewind refusal enforced upstream by open-spm-pr.sh). set_fixtures 0 1 'let releaseTag = "wallet-bindings-v9.9.9" checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none : > "${LOG}" @@ -725,7 +758,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated newer marker (enforced upstream)"; else bad "guard allows refresh over deactivated newer marker" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 48b-2b. Guard over a deactivated equal-version marker: refresh allowed (enforced upstream). +# 58. Guard over a deactivated equal-version marker: refresh allowed (enforced upstream). set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3" checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none : > "${LOG}" @@ -738,7 +771,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated equal marker (enforced upstream)"; else bad "guard allows refresh over deactivated equal marker" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 48b-2c. Guard: deactivated OLDER pin -> allow (forward release). +# 59. Guard: deactivated OLDER pin -> allow (forward release). set_fixtures 0 1 'let releaseTag = "wallet-bindings-v0.1.0" checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none : > "${LOG}" @@ -750,7 +783,7 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi -# 48b-2d. Supersede: meta-suffix stale marker (>= precedence) -> refuse. +# 60. Supersede: meta-suffix stale marker (>= precedence) -> refuse. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -767,7 +800,7 @@ fi assert_no_mutations printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 48. semver.sh unit checks (sourced directly). +# 61. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" semver_cmp_check() { From 1081c41431b955255f8f90738884ef1073da4624 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 22:15:50 +0100 Subject: [PATCH 31/53] ci: gate every package swift edit and verify the pinned release --- .github/workflows/ci.yml | 48 ++++++++--- docs/mobile-bindings.md | 22 ++--- scripts/release/check-pin-order.sh | 33 +++++-- scripts/release/open-spm-pr.sh | 2 + scripts/release/test-open-spm-pr.sh | 129 ++++++++++++++++++++++++---- 5 files changed, 187 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 831c2da..650a3f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,7 @@ jobs: BASE_REF: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.repository.default_branch }} HEAD_REF: ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + GH_TOKEN: ${{ github.token }} run: | # Single comparison implementation (scripts/release/semver.sh), # comment-stripped strict extraction, annotation-safe echoes — @@ -57,26 +58,53 @@ jobs: echo "::error::unexpected base branch" exit 1 fi - # The expected tag is derived from the reserved bot branch - # name (which names the release it pins) and cross-checked - # against the PR head's Package.swift (strict mode). NOTE: bot - # pin PRs opened with GITHUB_TOKEN do not emit pull_request - # events; they are enforced at creation time by the release - # workflow's rewind guard, which also supersedes older open - # pin PRs (no merge-order rewind). + # Any PR that edits Package.swift is order-checked, whatever + # its head branch is named; reserved-namespace heads + # additionally must pin exactly the release their branch name + # declares (strict mode). NOTE: bot pin PRs opened with + # GITHUB_TOKEN do not emit pull_request events; they are + # enforced at creation time by the release workflow's rewind + # guard, which also supersedes older open pin PRs (no + # merge-order rewind). case "$HEAD_REF" in pin-spm-checksum-*) expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" ;; *) - echo "not a pin branch; nothing to check" - exit 0 + expected_tag="" ;; esac - if [[ ! "$expected_tag" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + if [ -n "$expected_tag" ] && [[ ! "$expected_tag" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::derived tag does not match wallet-bindings-v" exit 1 fi + # Bind the incoming checksum to the release the pin names: + # SPM refuses on integrity mismatch at resolve time, so an + # unverifiable checksum would strand every consumer. The + # release must already exist (the release job publishes it + # before opening its pin PR) and its SHA256SUMS must list + # exactly the XCFramework zip hash the head pins. Fail closed + # on a missing or unreadable manifest. + # shellcheck disable=SC1091 # sourced from the trusted base checkout + source scripts/release/pinlib.sh + head_swift="$(git show "${HEAD_SHA}:Package.swift")" \ + || { echo "::error::cannot read Package.swift from the PR head"; exit 1; } + head_norm="$(strip_swift_comments "${head_swift}")" + head_tag="$(printf '%s\n' "${head_norm}" | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*' || true)" + head_checksum="$(printf '%s\n' "${head_norm}" | grep -E '^checksum: "' | grep -oE '[0-9a-f]{64}' || true)" + if [ "$(printf '%s\n' "${head_norm}" | grep -cE '^let releaseTag = ' || true)" != "1" ] \ + || [ "$(printf '%s\n' "${head_norm}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" != "1" ] \ + || [[ ! "${head_tag}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::PR head does not carry exactly one releaseTag and one hex checksum pin" + exit 1 + fi + sums="$(gh release download "${head_tag}" --pattern "SHA256SUMS" --output - 2>/dev/null)" \ + || { echo "::error::release is missing or carries no readable SHA256SUMS; refusing an unverifiable pin"; exit 1; } + published="$(printf '%s\n' "${sums}" | grep 'MintlayerWalletBindings.xcframework.zip' | awk '{print $1}' || true)" + if [ "${published}" != "${head_checksum}" ]; then + echo "::error::pinned checksum does not match the published SHA256SUMS for $(esc "${head_tag}")" + exit 1 + fi # The checkout is the base branch; pull the PR head commit so # the diff below and check-pin-order.sh's data-only read of # the head's Package.swift can see it (push events already diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 30d8569..0f967b3 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -173,16 +173,18 @@ tagged commit, attaches them with a `SHA256SUMS` manifest to the GitHub release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM -resolution for the release. The `ci.yml` "Pin ordering" gate enforces -release order on the `pin-spm-checksum-*` branch namespace: pull -requests or pushes whose head branch carries a checksum pin are -refused unless they advance the release currently pinned on the -default branch. On pull_request events the gate code is checked out -from the base branch (PR content cannot alter the enforcement logic); -on push events the pushed branch's code runs with ordinary branch-CI -privilege. Other (non-namespace) edits to `Package.swift` are NOT -order-checked by CI — they rely on review and branch protection on -the default branch. Recommended hardening: protect the +resolution for the release. The `ci.yml` "Pin ordering" gate applies +to every pull request or push that edits `Package.swift`, whatever +the head branch is named: the pinned checksum must match the +`SHA256SUMS` published for the release the pin names (an unverifiable +pin would strand every SPM consumer on a resolution failure), and the +pin must advance the release currently on the default branch — a +rewind or same-version repair is refused. Heads on the reserved +`pin-spm-checksum-*` namespace additionally must pin exactly the +release their branch name declares. On pull_request events the gate +code is checked out from the base branch (PR content cannot alter the +enforcement logic); on push events the pushed branch's code runs with +ordinary branch-CI privilege. Recommended hardening: protect the `pin-spm-checksum-*` branch namespace (restrict who may push it) — bot pin PRs opened with the workflow token emit no pull_request CI events, so namespace protection plus the creation-time rewind guard are the controls for them. Consumers never need a diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 47cad28..2ae1db7 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -4,12 +4,15 @@ # pinned on the default branch (same-version repairs are manual: the # rewind guard in open-spm-pr.sh refuses to create them). # -# Usage: check-pin-order.sh [INCOMING_REF] +# Usage: check-pin-order.sh [EXPECTED_TAG] [INCOMING_REF] # Run from the repo root in the PR checkout; LC_ALL=C is enforced -# internally. EXPECTED_TAG (derived by ci.yml from the reserved bot -# branch name) is required: strict mode requires the incoming checkout +# internally. With EXPECTED_TAG (derived by ci.yml from the reserved +# bot branch name), strict mode requires the incoming checkout # (INCOMING_REF, else the working tree) to carry exactly that -# assignment and no other pin-bearing line. +# assignment. With EXPECTED_TAG empty the script enforces pin +# structure and order only; the caller must then bind the incoming +# checksum to the release it names (ci.yml checks it against the +# release's published SHA256SUMS). set -euo pipefail export LC_ALL=C @@ -20,14 +23,14 @@ source "${BASH_SOURCE[0]%/*}/pinlib.sh" source "${BASH_SOURCE[0]%/*}/semver.sh" BASE_BRANCH="${1:?base branch required}" -EXPECTED_TAG="${2:?expected tag required}" +EXPECTED_TAG="${2-}" INCOMING_REF="${3:-}" if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ || [[ "${BASE_BRANCH}" == pin-spm-checksum-* ]]; then echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" exit 1 fi -if [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then +if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::unexpected expected tag: $(esc "${EXPECTED_TAG}")" exit 1 fi @@ -46,11 +49,17 @@ else fi normalized_in="$(strip_swift_comments "$(cat Package.swift)")" fi -# Strict mode (EXPECTED_TAG is required; ci.yml derives it from the +# Strict mode (EXPECTED_TAG non-empty; ci.yml derives it from the # reserved bot branch name): the normalized code must contain exactly # that assignment and NO other releaseTag- or checksum-bearing line, -# so comment/nesting text tricks fail closed. -expected_lines="$(printf '%s\n' "${normalized_in}" | grep -cF -x -- "let releaseTag = \"${EXPECTED_TAG}\"" || true)" +# so comment/nesting text tricks fail closed. Ordering-only mode +# (EXPECTED_TAG empty) skips the tag-equality count; the shared +# structural counts below still apply. +if [ -n "${EXPECTED_TAG}" ]; then + expected_lines="$(printf '%s\n' "${normalized_in}" | grep -cF -x -- "let releaseTag = \"${EXPECTED_TAG}\"" || true)" +else + expected_lines="1" +fi # Anchored counts: the URL line interpolates \(releaseTag), so a # substring 'releaseTag' count would double-count the real shape. release_tag_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^let releaseTag = ' || true)" @@ -69,6 +78,12 @@ if [[ ! "${incoming_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9 exit 1 fi +# Refresh origin/ so the comparison reflects the branch as of +# now, not the checkout snapshot: a pin PR merged while this gate is +# in flight must be visible before ordering is decided (a stale view +# could pass a rewind). Fatal on failure. +git fetch origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}" \ + || { echo "::error::cannot refresh origin/${BASE_BRANCH}"; exit 1; } origin_swift="$(git show "origin/${BASE_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${BASE_BRANCH}:Package.swift"; exit 1; } origin_code="$(strip_swift_comments "${origin_swift}")" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 9526772..b9acf12 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -233,6 +233,8 @@ while IFS=$'\t' read -r old_pr old_branch; do [ -n "${old_pr}" ] || continue [ "${old_branch}" = "${BRANCH}" ] && continue old_version="${old_branch#pin-spm-checksum-}" + # Defensive: the jq filter already excludes BRANCH itself, so a + # same-version row should be unreachable; skip rather than mis-handle. if [ "${old_version}" = "${VERSION}" ]; then continue; fi if [[ ! "${old_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::open pin PR #${old_pr} carries an unparseable version: $(esc "${old_version}")" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 0c3e879..28c1502 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -81,6 +81,15 @@ cat > "${STUBS}/gh" << 'EOF' #!/usr/bin/env bash echo "gh $*" >> "${LOG}" if [ "$1" = "pr" ] && [ "$2" = "list" ]; then + mode="$(cat "${CASE_DIR}/pr_list_fails" 2>/dev/null || echo "")" + case "${mode}" in + any) exit 1 ;; + existing) + for a in "$@"; do [ "${a}" = "--head" ] && exit 1; done ;; + supersede) + for a in "$@"; do [ "${a}" = "--head" ] && return_failed=1; done + [ "${return_failed:-}" = "1" ] || exit 1 ;; + esac payload="$(cat "${CASE_DIR}/existing_pr" 2>/dev/null || echo "[]")" prog="" prev="" @@ -144,6 +153,10 @@ set_fixtures() { } # assert_no_mutations: fail-closed cases must not push or open PRs. +reset_origin() { + printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +} + assert_no_mutations() { if grep -q "git push" <<< "${LOG_CONTENTS}" || grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then bad "no mutations on failure" "${LOG_CONTENTS}" @@ -368,14 +381,55 @@ if grep -q "gh pr create" <<< "${LOG_CONTENTS}"; then else bad "create proceeds over older pin" "${LOG_CONTENTS}" fi -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + +# 23b. gh pr list failure on the existing-pin lookup -> fail closed +# with no push and no PR opened. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'existing' > "${TMP}/pr_list_fails" +: > "${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 \ + >/dev/null 2>&1 ) +rc=$? +printf '' > "${TMP}/pr_list_fails" +LOG_CONTENTS="$(cat "${LOG}")" +PUSHED="$(grep -c "git push" <<< "${LOG_CONTENTS}" || true)" +CREATED="$(grep -c "pr create" <<< "${LOG_CONTENTS}" || true)" +if [ "${rc}" = "1" ] && [ "${PUSHED}" = "0" ] && [ "${CREATED}" = "0" ]; then + ok "existing-pin lookup failure fails closed" +else + bad "existing-pin lookup failure fails closed" "exit ${rc}, pushes=${PUSHED}, creates=${CREATED}" +fi +assert_no_mutations + +# 23c. gh pr list failure on the supersede lookup -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'supersede' > "${TMP}/pr_list_fails" +: > "${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 \ + >/dev/null 2>&1 ) +rc=$? +printf '' > "${TMP}/pr_list_fails" +LOG_CONTENTS="$(cat "${LOG}")" +PUSHED="$(grep -c "git push" <<< "${LOG_CONTENTS}" || true)" +CREATED="$(grep -c "pr create" <<< "${LOG_CONTENTS}" || true)" +if [ "${rc}" = "1" ] && [ "${PUSHED}" = "0" ] && [ "${CREATED}" = "0" ]; then + ok "supersede lookup failure fails closed" +else + bad "supersede lookup failure fails closed" "exit ${rc}, pushes=${PUSHED}, creates=${CREATED}" +fi +assert_no_mutations +reset_origin # 24. Same-version active pin with differing content -> rewind guard. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" run_case "same-version conflicting pin fails" 1 assert_no_mutations -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 25. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. set_fixtures 0 1 "${FULLY_PINNED}" pr.none @@ -389,14 +443,14 @@ set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-vx"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "unparseable origin pin tag fails" 1 assert_no_mutations -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 27. Active checksum with missing tag line -> fail closed (one-sided). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "one-sided active checksum fails" 1 assert_no_mutations -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 28. TAG/VERSION mismatch -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none @@ -408,7 +462,7 @@ set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "deadbeef"\n' > "${TMP}/origin_swift" run_case "mangled origin checksum fails" 1 assert_no_mutations -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 30. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-rc.1" // ... @@ -422,7 +476,7 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "prerelease after final refused"; else bad "prerelease after final refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 31. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. set_fixtures 0 1 "${FULLY_PINNED}" pr.none @@ -438,7 +492,7 @@ if [ "${rc}" = "0" ] && grep -q "gh pr create" "${LOG}"; then else bad "final over prerelease proceeds" "exit ${rc}: $(cat "${OUT}")" fi -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 32. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... @@ -495,7 +549,7 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "huge numeric prerelease refused without wrap"; else bad "huge numeric prerelease refused without wrap" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 36. Guard script: same tag + differing checksum -> refuse. GUARD="${SCRIPT_DIR}/guard-release-refresh.sh" @@ -528,7 +582,7 @@ printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0 >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 39. git show fails -> open-spm-pr.sh fails closed (no silent skip). set_fixtures 0 1 "${FULLY_PINNED}" pr.none @@ -543,7 +597,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "git show failure fails closed"; else bad "git show failure fails closed" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations printf '0' > "${TMP}/show_fails" -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 40. Comment decoys inside an unterminated block comment; the real # code pin (v1.0.0) follows the block. Correct stripping sees 1.2.3 > @@ -556,7 +610,7 @@ printf '/*\nchecksum: "111111111111111111111111111111111111111111111111111111111 >/dev/null 2>&1 ) rc=$? if [ "${rc}" = "0" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 41. Same decoy shape for the guard: real v1.0.0 pin follows the # block, so the refresh (1.2.3 > 1.0.0) must be allowed. @@ -578,7 +632,7 @@ printf '1' > "${TMP}/fetch_fails" rc=$? printf '0' > "${TMP}/fetch_fails" if [ "${rc}" = "1" ]; then ok "guard origin refresh failure fails closed"; else bad "guard origin refresh failure fails closed" "exit ${rc}"; fi -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 43. Guard: zero releaseTag assignments -> refuse. printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" @@ -599,7 +653,7 @@ rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses duplicate assignments"; else bad "guard refuses duplicate assignments" "exit ${rc}"; fi # 45. Guard: invalid checksum -> refuse. -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "nothex" main \ @@ -616,7 +670,7 @@ printf '1' > "${TMP}/show_fails" rc=$? if [ "${rc}" = "1" ]; then ok "guard fails closed on git show failure"; else bad "guard fails closed on git show failure" "exit ${rc}"; fi printf '0' > "${TMP}/show_fails" -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin # 47. Pin-order script: upgrade allows, downgrade refuses, same refuses. ORDER="${SCRIPT_DIR}/check-pin-order.sh" @@ -661,6 +715,44 @@ rc=$? printf '0' > "${TMP}/incoming_show_fails" if [ "${rc}" = "1" ]; then ok "pin order fails closed on an unreadable incoming ref"; else bad "pin order fails closed on an unreadable incoming ref" "exit ${rc}"; fi +# Ordering-only mode (empty EXPECTED_TAG): non-namespace Package.swift +# edits are order-checked without a tag-equality requirement. The +# caller (ci.yml) binds the checksum to the published release. +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "ordering mode allows a forward pin"; else bad "ordering mode allows a forward pin" "exit ${rc}"; fi + +printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "ordering mode refuses a rewind"; else bad "ordering mode refuses a rewind" "exit ${rc}"; fi + +# The gate's origin refresh is fatal: a failed fetch must not decide +# against a stale pin view. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +printf '1' > "${TMP}/fetch_fails" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) +rc=$? +printf '0' > "${TMP}/fetch_fails" +if [ "${rc}" = "1" ]; then ok "pin order origin refresh failure fails closed"; else bad "pin order origin refresh failure fails closed" "exit ${rc}"; fi + +# A base branch carrying two pin assignments is a mangled state. +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\nlet releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "wallet-bindings-v1.3.0" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "1" ]; then ok "pin order refuses an ambiguous base pin"; else bad "pin order refuses an ambiguous base pin" "exit ${rc}"; fi +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" + # 50. Reserved-namespace base branch -> fail closed. # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" @@ -718,7 +810,7 @@ if [ "${rc}" = "0" ]; then ok "strict mode passes the real Package.swift shape"; # 55. Supersede: an older stale pin PR is closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_older -printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +reset_origin : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -826,10 +918,11 @@ wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release. sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" gd="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/guard-release-refresh.sh" || true)" cy="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/ci.yml" || true)" -if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "1" ]; then - ok "tag regex identical across all seven copies" +cpo="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/check-pin-order.sh" || true)" +if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "2" ] && [ "${cpo}" = "1" ]; then + ok "tag regex identical across all nine copies" else - bad "tag regex identical across all seven copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}" + bad "tag regex identical across all nine copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}, pin-order=${cpo}" fi echo "passed: ${pass}, failed: ${fail}" From ceefb150cdd11d63111af6f7bdf05dad980753e1 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Fri, 13 Nov 2026 22:27:48 +0100 Subject: [PATCH 32/53] ci: test the pin gate as a script and order checks by applicability --- .github/workflows/ci.yml | 83 ++----------------- .github/workflows/release.yml | 2 +- CHANGELOG.md | 2 + scripts/release/check-pin-order.sh | 27 ++++++- scripts/release/pin-order-gate.sh | 99 +++++++++++++++++++++++ scripts/release/test-open-spm-pr.sh | 120 ++++++++++++++++++++++++---- 6 files changed, 237 insertions(+), 96 deletions(-) create mode 100755 scripts/release/pin-order-gate.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 650a3f5..d6f35b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,83 +51,12 @@ jobs: HEAD_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} GH_TOKEN: ${{ github.token }} run: | - # Single comparison implementation (scripts/release/semver.sh), - # comment-stripped strict extraction, annotation-safe echoes — - # shared with the release scripts. - if [[ ! "$BASE_REF" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then - echo "::error::unexpected base branch" - exit 1 - fi - # Any PR that edits Package.swift is order-checked, whatever - # its head branch is named; reserved-namespace heads - # additionally must pin exactly the release their branch name - # declares (strict mode). NOTE: bot pin PRs opened with - # GITHUB_TOKEN do not emit pull_request events; they are - # enforced at creation time by the release workflow's rewind - # guard, which also supersedes older open pin PRs (no - # merge-order rewind). - case "$HEAD_REF" in - pin-spm-checksum-*) - expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" - ;; - *) - expected_tag="" - ;; - esac - if [ -n "$expected_tag" ] && [[ ! "$expected_tag" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then - echo "::error::derived tag does not match wallet-bindings-v" - exit 1 - fi - # Bind the incoming checksum to the release the pin names: - # SPM refuses on integrity mismatch at resolve time, so an - # unverifiable checksum would strand every consumer. The - # release must already exist (the release job publishes it - # before opening its pin PR) and its SHA256SUMS must list - # exactly the XCFramework zip hash the head pins. Fail closed - # on a missing or unreadable manifest. - # shellcheck disable=SC1091 # sourced from the trusted base checkout - source scripts/release/pinlib.sh - head_swift="$(git show "${HEAD_SHA}:Package.swift")" \ - || { echo "::error::cannot read Package.swift from the PR head"; exit 1; } - head_norm="$(strip_swift_comments "${head_swift}")" - head_tag="$(printf '%s\n' "${head_norm}" | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*' || true)" - head_checksum="$(printf '%s\n' "${head_norm}" | grep -E '^checksum: "' | grep -oE '[0-9a-f]{64}' || true)" - if [ "$(printf '%s\n' "${head_norm}" | grep -cE '^let releaseTag = ' || true)" != "1" ] \ - || [ "$(printf '%s\n' "${head_norm}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" != "1" ] \ - || [[ ! "${head_tag}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then - echo "::error::PR head does not carry exactly one releaseTag and one hex checksum pin" - exit 1 - fi - sums="$(gh release download "${head_tag}" --pattern "SHA256SUMS" --output - 2>/dev/null)" \ - || { echo "::error::release is missing or carries no readable SHA256SUMS; refusing an unverifiable pin"; exit 1; } - published="$(printf '%s\n' "${sums}" | grep 'MintlayerWalletBindings.xcframework.zip' | awk '{print $1}' || true)" - if [ "${published}" != "${head_checksum}" ]; then - echo "::error::pinned checksum does not match the published SHA256SUMS for $(esc "${head_tag}")" - exit 1 - fi - # The checkout is the base branch; pull the PR head commit so - # the diff below and check-pin-order.sh's data-only read of - # the head's Package.swift can see it (push events already - # have their SHA locally). - if [ "$EVENT_NAME" = "pull_request" ]; then - git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head" - fi - # Fail closed on diff errors: an unreadable head (e.g. a - # force-push landing between event emission and the fetch) - # must not masquerade as "Package.swift untouched". The head - # fetch is anonymous, so private repositories fail closed - # here rather than silently skipping the gate. - if ! head_files="$(git diff --name-only "origin/${BASE_REF}...${HEAD_SHA}")"; then - echo "::error::cannot diff the incoming pin against origin/${BASE_REF}" - exit 1 - fi - if ! printf '%s\n' "${head_files}" | grep -q '^Package.swift$'; then - echo "Package.swift untouched; nothing to check" - exit 0 - fi - # Gate code is the trusted base checkout; the PR head's - # Package.swift is consumed purely as data via its SHA. - scripts/release/check-pin-order.sh "$BASE_REF" "$expected_tag" "$HEAD_SHA" + # Diff-gated applicability, checksum-to-release binding, and + # ordering enforcement all live in one tested script (the + # stub harness covers it); reserved-namespace heads get + # strict tag equality, every other Package.swift edit gets + # ordering-only enforcement. + scripts/release/pin-order-gate.sh fmt: name: Format diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e60ab06..8a49474 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -209,7 +209,7 @@ jobs: # The shared normalizer (pinlib.sh) strips block/line comments # and indentation, so the whole-line counts match the code view # every other verification path uses. - # shellcheck disable=SC1091 # sourced next to this file + # shellcheck disable=SC1091 # sourced from the repo root working directory source scripts/release/pinlib.sh read -r pin_tag_lines pin_sum_lines checksum_lines <<< "$(count_pin_lines Package.swift "$TAG" "$xcsum")" if [ "$pin_tag_lines" != "1" ] || [ "$pin_sum_lines" != "1" ]; then diff --git a/CHANGELOG.md b/CHANGELOG.md index 285a928..4353dc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] +- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every `Package.swift` edit — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. + ### Added - bindings: new `mintlayer-wallet-bindings` crate exposing the Mintlayer diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 2ae1db7..14d64d7 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -13,6 +13,12 @@ # structure and order only; the caller must then bind the incoming # checksum to the release it names (ci.yml checks it against the # release's published SHA256SUMS). +# +# Residual merge-time race: this gate decides against origin/ as +# of its own run. A pin PR merging AFTER the gate passes but BEFORE a +# rewind PR merges is invisible here; operators must enable "require +# branches to be up to date before merging" for this required check on +# the default branch to close that window. set -euo pipefail export LC_ALL=C @@ -67,11 +73,19 @@ checksum_lines="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "' || checksum_valid="$(printf '%s\n' "${normalized_in}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" if [ "${expected_lines}" != "1" ] || [ "${release_tag_lines}" != "1" ] \ || [ "${checksum_lines}" != "1" ] || [ "${checksum_valid}" != "1" ]; then - echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous, missing, or non-hex checksum)" + if [ -n "${EXPECTED_TAG}" ]; then + echo "::error::PR head does not carry exactly the expected pin assignment for $(esc "${EXPECTED_TAG}") (ambiguous, missing, or non-hex checksum)" + else + echo "::error::PR head must carry exactly one releaseTag assignment and one hex checksum pin" + fi exit 1 fi incoming_tag="$(printf '%s\n' "${normalized_in}" \ - | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" + | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*' || true)" +if [ -z "${incoming_tag}" ]; then + echo "::error::PR head carries no parseable wallet-bindings tag" + exit 1 +fi incoming_version="${incoming_tag#wallet-bindings-v}" if [[ ! "${incoming_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::unparseable incoming pin version: $(esc "${incoming_version}")" @@ -87,9 +101,18 @@ git fetch origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}" origin_swift="$(git show "origin/${BASE_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${BASE_BRANCH}:Package.swift"; exit 1; } origin_code="$(strip_swift_comments "${origin_swift}")" +# The same prefix count every sibling script uses, plus the anchored +# count: a prefix-matching but mangled pin line on the base (stray +# suffix, double space) would otherwise read as "no pin" and let a +# rewind pass. +current_prefix="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = ' || true)" current_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" if [ "${current_matches}" = "0" ]; then + if [ "${current_prefix}" != "0" ]; then + echo "::error::origin/${BASE_BRANCH} carries ${current_prefix} mangled pin line(s) and no well-formed one; refusing (repair manually)" + exit 1 + fi echo "no pin on ${BASE_BRANCH}; any pin order is acceptable" exit 0 fi diff --git a/scripts/release/pin-order-gate.sh b/scripts/release/pin-order-gate.sh new file mode 100755 index 0000000..d435433 --- /dev/null +++ b/scripts/release/pin-order-gate.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# CI-side pin-order gate (invoked by .github/workflows/ci.yml). +# +# Applicability is diff-driven: every pull request or push whose diff +# touches Package.swift is checked; anything else exits 0 ("nothing to +# check") without touching the network. For an applicable diff: +# 1. The head's single releaseTag + hex checksum pin is extracted +# with the shared stripper (pinlib.sh). +# 2. The checksum is bound to the release the pin names: the +# release's published SHA256SUMS must list exactly that hash for +# the XCFramework zip (SPM verifies at resolve time, so an +# unverifiable pin would strand every consumer). +# 3. Ordering is delegated to check-pin-order.sh: reserved-namespace +# heads (pin-spm-checksum-*) must pin exactly the release their +# branch name declares; any other head is order-checked without a +# tag-equality requirement. +# +# Environment (set by ci.yml): BASE_REF, HEAD_SHA, HEAD_REF, +# EVENT_NAME, PR_NUMBER, GH_TOKEN. LC_ALL=C is enforced internally. +set -euo pipefail +export LC_ALL=C + +# Shared helpers (esc, comment stripping). +# shellcheck disable=SC1091 # sourced next to this file, linted directly +source "${BASH_SOURCE[0]%/*}/pinlib.sh" + +BASE_REF="${BASE_REF:?base branch required}" +HEAD_SHA="${HEAD_SHA:?head sha required}" +HEAD_REF="${HEAD_REF:?head ref required}" +EVENT_NAME="${EVENT_NAME:-}" +PR_NUMBER="${PR_NUMBER:-}" + +if [[ ! "${BASE_REF}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ + || [[ "${BASE_REF}" == pin-spm-checksum-* ]]; then + echo "::error::unexpected base branch: $(esc "${BASE_REF}")" + exit 1 +fi + +# The checkout is the base branch; pull the PR head commit so the diff +# and the data-only read of the head's Package.swift can see it (push +# events already have their SHA locally). Anonymous on public repos; +# private repositories fail closed below rather than skipping. +if [ "${EVENT_NAME}" = "pull_request" ]; then + git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head" +fi + +# Fail closed on diff errors: an unreadable head (e.g. a force-push +# landing between event emission and the fetch) must not masquerade as +# "Package.swift untouched". +if ! head_files="$(git diff --name-only "origin/${BASE_REF}...${HEAD_SHA}")"; then + echo "::error::cannot diff the incoming pin against origin/${BASE_REF}" + exit 1 +fi +if ! printf '%s\n' "${head_files}" | grep -q '^Package.swift$'; then + echo "Package.swift untouched; nothing to check" + exit 0 +fi + +# Strict tag equality only for the reserved bot namespace; other +# heads are order-checked without a tag-equality requirement. +case "${HEAD_REF}" in + pin-spm-checksum-*) + expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" + if [[ ! "${expected_tag}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::derived tag does not match wallet-bindings-v: $(esc "${expected_tag}")" + exit 1 + fi + ;; + *) + expected_tag="" + ;; +esac + +# The head's Package.swift is consumed purely as data via its SHA. +head_swift="$(git show "${HEAD_SHA}:Package.swift" 2>/dev/null)" \ + || { echo "::error::cannot read Package.swift from the PR head"; exit 1; } +head_norm="$(strip_swift_comments "${head_swift}")" +# Anchored counts: the URL line interpolates \(releaseTag), so a +# substring 'releaseTag' count would double-count the real shape. +head_tag="$(printf '%s\n' "${head_norm}" | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*' || true)" +head_checksum="$(printf '%s\n' "${head_norm}" | grep -E '^checksum: "' | grep -oE '[0-9a-f]{64}' || true)" +if [ "$(printf '%s\n' "${head_norm}" | grep -cE '^let releaseTag = ' || true)" != "1" ] \ + || [ "$(printf '%s\n' "${head_norm}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" != "1" ] \ + || [[ ! "${head_tag}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::PR head does not carry exactly one releaseTag and one hex checksum pin" + exit 1 +fi + +# Bind the checksum to the published release; fail closed on a +# missing or unreadable manifest. +sums="$(gh release download "${head_tag}" --pattern "SHA256SUMS" --output - 2>/dev/null)" \ + || { echo "::error::release $(esc "${head_tag}") is missing or carries no readable SHA256SUMS; refusing an unverifiable pin"; exit 1; } +published="$(printf '%s\n' "${sums}" | grep 'MintlayerWalletBindings.xcframework.zip' | awk '{print $1}' || true)" +if [ "${published}" != "${head_checksum}" ]; then + echo "::error::pinned checksum does not match the published SHA256SUMS for $(esc "${head_tag}")" + exit 1 +fi + +exec "${BASH_SOURCE[0]%/*}/check-pin-order.sh" "${BASE_REF}" "${expected_tag}" "${HEAD_SHA}" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 28c1502..264a0fe 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1,16 +1,21 @@ #!/usr/bin/env bash -# Unit tests for scripts/release/open-spm-pr.sh and -# scripts/release/guard-release-refresh.sh using stub git/gh on PATH. -# Covers: tag-ancestry guard (shallow-aware fetch both ways, git-error -# disambiguation), HEAD==tag guard, both substitution verifications (pin -# fully present / either half drifted / absent), already-merged, -# pre-pinned and reverted-main short-circuits, semver rewind guard -# (forward allowed, stale/same-version refused, one-sided and mangled -# origin pins refused), owner/cross-repo/base-branch PR detection, -# force-push ordering and its absence on failure paths, -# owner/branch/checksum/tag/version validation, and the byte-identical -# TAG regex across all copies. Run by lint.yml and locally before -# releases. +# Unit tests for scripts/release/open-spm-pr.sh, +# scripts/release/guard-release-refresh.sh, scripts/release/pin-order-gate.sh, +# and scripts/release/check-pin-order.sh, run entirely against stub +# git/gh binaries (no network, no repository mutation). +# +# Covered, among the rest of the suite: idempotent create/reuse of the +# checksum-pin PR with superseding of older pins and refusal on newer +# ones; rewind guards (semver precedence, build metadata excluded, +# deactivated-pin markers, mangled states); comment stripping +# (line/block, decoys, indent-tolerant); strict and ordering modes of +# the merge gate including the INCOMING_REF read and its failure paths; +# the gate script's diff-gated applicability, SHA256SUMS checksum +# binding, and strict-tag derivation; fatal origin refreshes +# (guard + gate); gh pr list failures failing closed with no push and +# no PR opened; semver.sh comparator units; fixture reset and +# no-mutation assertions. +# Runs without -e: failures are counted per case, not fatal. set -uo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -56,9 +61,12 @@ case "$1 $2" in "diff --cached") [ "$(cat "${CASE_DIR}/staged_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "diff --quiet") [ "$(cat "${CASE_DIR}/default_diff" 2>/dev/null || echo 1)" = "0" ] && exit 0 || exit 1 ;; "rev-parse --is-shallow-repository") cat "${CASE_DIR}/is_shallow" ;; - "fetch origin" | "fetch --unshallow") + "fetch origin" | "fetch --unshallow" | "fetch --no-tags") [ "$(cat "${CASE_DIR}/fetch_fails" 2>/dev/null || echo 0)" = "1" ] && exit 1 exit 0 ;; + "diff --name-only") + [ "$(cat "${CASE_DIR}/head_touched" 2>/dev/null || echo 0)" = "1" ] && echo "Package.swift" + exit 0 ;; "rev-parse HEAD") cat "${CASE_DIR}/head_commit" ;; "show origin/"*) if [ "$(cat "${CASE_DIR}/show_fails" 2>/dev/null || echo 0)" = "1" ]; then @@ -80,6 +88,11 @@ EOF cat > "${STUBS}/gh" << 'EOF' #!/usr/bin/env bash echo "gh $*" >> "${LOG}" +if [ "$1" = "release" ] && [ "$2" = "download" ]; then + [ "$(cat "${CASE_DIR}/release_download_fails" 2>/dev/null || echo 0)" = "1" ] && exit 1 + cat "${CASE_DIR}/release_sums" + exit 0 +fi if [ "$1" = "pr" ] && [ "$2" = "list" ]; then mode="$(cat "${CASE_DIR}/pr_list_fails" 2>/dev/null || echo "")" case "${mode}" in @@ -753,6 +766,80 @@ rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses an ambiguous base pin"; else bad "pin order refuses an ambiguous base pin" "exit ${rc}"; fi printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +# GATE. The ci.yml gate script: diff-gated applicability, checksum +# binding against the release's SHA256SUMS, then ordering. +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +GATE="${SCRIPT_DIR}/pin-order-gate.sh" +printf 'SHA256SUMS for the release\n%s MintlayerWalletBindings.xcframework.zip\n' "${XCSUM}" > "${TMP}/release_sums" +printf '0' > "${TMP}/release_download_fails" + +# Untouched Package.swift -> skip without reading anything. +printf '0' > "${TMP}/head_touched" +run_gate() { + ( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + BASE_REF="main" HEAD_SHA="0123456789abcdef0123456789abcdef01234567" \ + HEAD_REF="$1" EVENT_NAME="pull_request" PR_NUMBER="7" \ + bash "${GATE}" > "${OUT}" 2>&1 ) + rc=$? +} +run_gate "feature" +if [ "${rc}" = "0" ] && grep -q "untouched" "${OUT}"; then + ok "gate skips a PR that does not touch Package.swift" +else + bad "gate skips a PR that does not touch Package.swift" "exit ${rc}: $(cat "${OUT}")" +fi + +# Touched + forward pin bound to the published sums -> allow. +printf '1' > "${TMP}/head_touched" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +run_gate "feature" +if [ "${rc}" = "0" ]; then ok "gate allows a bound forward pin"; else bad "gate allows a bound forward pin" "exit ${rc}: $(cat "${OUT}")"; fi + +# Checksum not matching the published SHA256SUMS -> refuse. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/incoming_swift" +run_gate "feature" +if [ "${rc}" = "1" ] && grep -q "does not match the published" "${OUT}"; then + ok "gate refuses an unbound checksum" +else + bad "gate refuses an unbound checksum" "exit ${rc}: $(cat "${OUT}")" +fi + +# Unreadable release manifest -> fail closed. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +printf '1' > "${TMP}/release_download_fails" +run_gate "feature" +printf '0' > "${TMP}/release_download_fails" +if [ "${rc}" = "1" ] && grep -q "unverifiable pin" "${OUT}"; then + ok "gate fails closed on a missing release manifest" +else + bad "gate fails closed on a missing release manifest" "exit ${rc}: $(cat "${OUT}")" +fi + +# Mangled head (two releaseTag lines) -> refuse. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\nlet releaseTag = "wallet-bindings-v1.2.3"\n' "${XCSUM}" > "${TMP}/incoming_swift" +run_gate "feature" +if [ "${rc}" = "1" ] && grep -q "exactly one releaseTag" "${OUT}"; then + ok "gate refuses a mangled head" +else + bad "gate refuses a mangled head" "exit ${rc}: $(cat "${OUT}")" +fi + +# Reserved namespace: strict tag equality against the branch name. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +run_gate "pin-spm-checksum-1.3.0" +if [ "${rc}" = "0" ]; then ok "gate strict mode accepts the declared release"; else bad "gate strict mode accepts the declared release" "exit ${rc}: $(cat "${OUT}")"; fi + +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +run_gate "pin-spm-checksum-1.3.0" +if [ "${rc}" = "1" ] && grep -q "does not carry exactly the expected pin assignment" "${OUT}"; then + ok "gate strict mode refuses a tag mismatch" +else + bad "gate strict mode refuses a tag mismatch" "exit ${rc}: $(cat "${OUT}")" +fi +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" + # 50. Reserved-namespace base branch -> fail closed. # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" @@ -795,7 +882,7 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else b printf '0' > "${TMP}/show_fails" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 54. Strict mode PASS path over the REAL root Package.swift shape: +# 54. Strict mode PASS path over a representative root Package.swift shape: # header comment, the download URL interpolating \(releaseTag) (which a # substring 'releaseTag' count would double-count), releaseTag at # column 0, checksum indented 12 spaces. @@ -918,11 +1005,12 @@ wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release. sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" gd="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/guard-release-refresh.sh" || true)" cy="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/ci.yml" || true)" +gate="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/pin-order-gate.sh" || true)" cpo="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/check-pin-order.sh" || true)" -if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "2" ] && [ "${cpo}" = "1" ]; then +if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "0" ] && [ "${gate}" = "2" ] && [ "${cpo}" = "1" ]; then ok "tag regex identical across all nine copies" else - bad "tag regex identical across all nine copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}, pin-order=${cpo}" + bad "tag regex identical across all nine copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}, gate=${gate}, pin-order=${cpo}" fi echo "passed: ${pass}, failed: ${fail}" From e427602418e4c995a1d31a9e54e01bc4efe01ed0 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 15:29:43 +0100 Subject: [PATCH 33/53] ci: keep the pin gate reachable and harden the release staging --- .github/workflows/ci.yml | 2 -- .github/workflows/release.yml | 11 +++++++- CHANGELOG.md | 4 +-- scripts/release/guard-release-refresh.sh | 5 +++- scripts/release/open-spm-pr.sh | 8 +++--- scripts/release/test-open-spm-pr.sh | 32 ++++++++++++++++++++---- 6 files changed, 47 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6f35b0..e0832cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,8 @@ name: CI on: push: branches: [main, 'pin-spm-checksum-**'] - paths-ignore: [".github/**"] pull_request: branches: [main] - paths-ignore: [".github/**"] # The crate jobs never need more than read access. permissions: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8a49474..a5cc003 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -80,7 +80,15 @@ jobs: - name: Stage AAR with versioned name run: | + # Same strict tag shape the release job enforces later: a + # slash-bearing or malformed tag would stage the AAR outside + # the dist glob and fail the run confusingly. Fail here + # instead. VERSION="${GITHUB_REF_NAME#wallet-bindings-v}" + if [[ ! "${GITHUB_REF_NAME}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then + echo "::error::tag does not match wallet-bindings-v: ${GITHUB_REF_NAME}" + exit 1 + fi mkdir -p dist cp bindings/kotlin/build/outputs/aar/*-release.aar \ "dist/mintlayer-wallet-bindings-${VERSION}.aar" @@ -240,7 +248,8 @@ jobs: `org.mintlayer.wallet.bindings` - `MintlayerWalletBindings.xcframework.zip` — iOS framework (arm64 device, arm64 simulator); consumed by the root - `Package.swift` (checksum pinned to this release) + `Package.swift` (checksum pinned to this release once its + checksum-pin pull request merges) - `SHA256SUMS` — SHA-256 checksums for every artifact - `MintlayerWalletBindings.swift` — generated Swift wrapper (also in-repo at `SwiftSources/`) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4353dc0..d19c9c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,10 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] -- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every `Package.swift` edit — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. - ### Added +- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every `Package.swift` edit — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. + - bindings: new `mintlayer-wallet-bindings` crate exposing the Mintlayer wallet primitives to Kotlin and Swift via UniFFI, mirroring the full wasm-bindings surface: mnemonic → default account extended private key, diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 2c45bad..087323d 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -52,7 +52,10 @@ if [ -z "${origin_code}" ]; then fi # Exactly one releaseTag and one checksum assignment must exist (any -# version); anything else is a mangled pin state -> fail closed. +# version); counts are shape-agnostic here — a hex-invalid checksum on +# a DIFFERENT tag still refreshes (main is already broken for its own +# pin; the strict hex checks live in open-spm-pr.sh and the ci.yml +# gate), same-tag refreshes with a mangled checksum fail below. tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v' || true)" checksum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" if [ "${tag_assignments}" != "1" ] || [ "${checksum_assignments}" != "1" ]; then diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index b9acf12..b7f2b97 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -187,6 +187,10 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi +elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then + # A checksum line exists but is not 64 lowercase hex: mangled pin. + echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${origin_pin_sum_raw}")" + exit 1 elif { cmp="$(semver_cmp "${VERSION}" "${origin_version}")"; [[ "${cmp}" =~ ^-?[012]$ ]]; } && [ "${cmp}" -le 0 ]; then # A deactivated (zeroed-checksum) pin whose release marker is # newer-or-equal: main claims ${origin_version} with no active @@ -195,10 +199,6 @@ elif { cmp="$(semver_cmp "${VERSION}" "${origin_version}")"; [[ "${cmp}" =~ ^-?[ # aligned with the active-pin path at prerelease/build edges. echo "::error::origin/${DEFAULT_BRANCH} carries a deactivated pin for ${origin_version} (>= ${VERSION}); refusing to pin - repair the default branch manually" exit 1 -elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then - # A checksum line exists but is not 64 lowercase hex: mangled pin. - echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${origin_pin_sum_raw}")" - exit 1 elif [ -z "${origin_pin_sum_raw}" ] && [ -n "${origin_pin_tag}" ]; then # A tag line without any checksum line: mangled pin. echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 264a0fe..2b8e60a 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -837,6 +837,26 @@ if [ "${rc}" = "1" ] && grep -q "does not carry exactly the expected pin assignm else bad "gate strict mode refuses a tag mismatch" "exit ${rc}: $(cat "${OUT}")" fi + +# A reserved-namespace branch whose suffix is not a semver -> refuse +# at the derivation check. +run_gate "pin-spm-checksum-oops" +if [ "${rc}" = "1" ] && grep -q "does not match wallet-bindings-v" "${OUT}"; then + ok "gate refuses an unparseable namespace branch name" +else + bad "gate refuses an unparseable namespace branch name" "exit ${rc}: $(cat "${OUT}")" +fi + +# An unreadable head commit -> fail closed at the gate itself. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +printf '1' > "${TMP}/incoming_show_fails" +run_gate "feature" +printf '0' > "${TMP}/incoming_show_fails" +if [ "${rc}" = "1" ] && grep -q "cannot read Package.swift from the PR head" "${OUT}"; then + ok "gate fails closed on an unreadable head" +else + bad "gate fails closed on an unreadable head" "exit ${rc}: $(cat "${OUT}")" +fi printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" @@ -998,8 +1018,10 @@ else fi # Static check: the TAG regex must be byte-identical in every copy -# (three occurrences in release.yml, one in open-spm-pr.sh, one in -# guard-release-refresh.sh). +# Byte-identical TAG regex everywhere it appears: four occurrences in +# release.yml, one in open-spm-pr.sh, two in guard-release-refresh.sh, +# two in pin-order-gate.sh, one in check-pin-order.sh, and an explicit +# zero expectation for ci.yml (the gate moved into the tested script). TAG_REGEX='^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$' wf="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/release.yml" || true)" sc="$(grep -cF -- "${TAG_REGEX}" "${UNDER_TEST}" || true)" @@ -1007,10 +1029,10 @@ gd="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/guard-release-refresh.sh" || tru cy="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/../../.github/workflows/ci.yml" || true)" gate="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/pin-order-gate.sh" || true)" cpo="$(grep -cF -- "${TAG_REGEX}" "${SCRIPT_DIR}/check-pin-order.sh" || true)" -if [ "${wf}" = "3" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "0" ] && [ "${gate}" = "2" ] && [ "${cpo}" = "1" ]; then - ok "tag regex identical across all nine copies" +if [ "${wf}" = "4" ] && [ "${sc}" = "1" ] && [ "${gd}" = "2" ] && [ "${cy}" = "0" ] && [ "${gate}" = "2" ] && [ "${cpo}" = "1" ]; then + ok "tag regex identical across all ten copies" else - bad "tag regex identical across all nine copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}, gate=${gate}, pin-order=${cpo}" + bad "tag regex identical across all ten copies" "release.yml=${wf}, script=${sc}, guard=${gd}, ci=${cy}, gate=${gate}, pin-order=${cpo}" fi echo "passed: ${pass}, failed: ${fail}" From 6607c4ac4bb64e35ab64ce8812b94ac0bbfd0cd4 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 15:43:50 +0100 Subject: [PATCH 34/53] ci: tolerate the legacy pin branch and correct release finality --- .github/workflows/release.yml | 6 ++++-- docs/mobile-bindings.md | 9 ++++++--- scripts/release/open-spm-pr.sh | 3 +++ scripts/release/pin-order-gate.sh | 8 ++++++-- scripts/release/test-open-spm-pr.sh | 8 ++++++-- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5cc003..cce8e7d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -280,9 +280,11 @@ jobs: dist/swift-sources/MintlayerWalletBindings.swift else # Pre-release versions must not claim the GitHub "Latest" - # badge; only final releases do. + # badge; only final releases do. Build metadata (+) does + # not affect semver finality, so only the pre-release + # hyphen disqualifies. latest_flag="--latest" - case "$VERSION" in *-*|*+*) latest_flag="--latest=false" ;; esac + case "$VERSION" in *-*) latest_flag="--latest=false" ;; esac gh release create "$TAG" \ dist/mintlayer-wallet-bindings-*.aar \ dist/MintlayerWalletBindings.xcframework.zip \ diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 0f967b3..20156f9 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -185,9 +185,12 @@ release their branch name declares. On pull_request events the gate code is checked out from the base branch (PR content cannot alter the enforcement logic); on push events the pushed branch's code runs with ordinary branch-CI privilege. Recommended hardening: protect the -`pin-spm-checksum-*` branch namespace (restrict who may push it) — bot pin PRs opened with the workflow token emit no -pull_request CI events, so namespace protection plus the creation-time -rewind guard are the controls for them. Consumers never need a +`pin-spm-checksum-*` branch namespace (restrict who may push it) — +bot pin PRs opened with the workflow token emit no pull_request CI +events, so namespace protection plus the creation-time rewind guard +are the controls for them. A pre-automation legacy branch +(`pin-spm-checksum-v0.1.0`) can be deleted once this flow merges; +both the gate and the supersede loop tolerate its `v` suffix. Consumers never need a Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index b7f2b97..f2c171b 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -233,6 +233,9 @@ while IFS=$'\t' read -r old_pr old_branch; do [ -n "${old_pr}" ] || continue [ "${old_branch}" = "${BRANCH}" ] && continue old_version="${old_branch#pin-spm-checksum-}" + # A pre-automation branch carried a bare v (pin-spm-checksum-v0.1.0); + # tolerate the suffix so a stale legacy PR cannot hard-block releases. + old_version="${old_version#v}" # Defensive: the jq filter already excludes BRANCH itself, so a # same-version row should be unreachable; skip rather than mis-handle. if [ "${old_version}" = "${VERSION}" ]; then continue; fi diff --git a/scripts/release/pin-order-gate.sh b/scripts/release/pin-order-gate.sh index d435433..d65bc78 100755 --- a/scripts/release/pin-order-gate.sh +++ b/scripts/release/pin-order-gate.sh @@ -41,7 +41,8 @@ fi # events already have their SHA locally). Anonymous on public repos; # private repositories fail closed below rather than skipping. if [ "${EVENT_NAME}" = "pull_request" ]; then - git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head" + git fetch --no-tags origin "+refs/pull/${PR_NUMBER}/head" \ + || { echo "::error::cannot fetch the PR head"; exit 1; } fi # Fail closed on diff errors: an unreadable head (e.g. a force-push @@ -60,7 +61,10 @@ fi # heads are order-checked without a tag-equality requirement. case "${HEAD_REF}" in pin-spm-checksum-*) - expected_tag="wallet-bindings-v${HEAD_REF#pin-spm-checksum-}" + # A pre-automation branch carried a bare v in the suffix; strip it + # so legacy branches still derive the correct expected tag. + gate_suffix="${HEAD_REF#pin-spm-checksum-}" + expected_tag="wallet-bindings-v${gate_suffix#v}" if [[ ! "${expected_tag}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::derived tag does not match wallet-bindings-v: $(esc "${expected_tag}")" exit 1 diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 2b8e60a..b3adb1d 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -36,13 +36,16 @@ fail=0 ok() { pass=$((pass + 1)); echo "ok - $1"; } # Sanitize log output: the script under test and stub args are # PR-controlled on pull_request runs, so neutralize workflow-command -# forgery and control characters before echoing. +# forgery, control characters, DEL, and non-ASCII bytes before echoing. sanitize() { # PR-controlled output: replace every '::' so no workflow command can # survive, per line. LF/CR are intentionally preserved — deleting them # could splice two benign fragments into a new command — and each # resulting line is safe because '::' no longer occurs in it. - printf '%s' "$1" | tr -d '\000-\010\011\013\014\016-\037' | sed 's/::/[::]/g' + # DEL and non-ASCII bytes are deleted outright (esc() in pinlib.sh + # does the same); LF/CR are preserved — deleting them could splice + # two benign fragments into a new command. + printf '%s' "$1" | tr -d '\000-\010\011\013\014\016-\037\177\200-\377' | sed 's/::/[::]/g' } bad() { fail=$((fail + 1)); echo "NOT OK - $1: $(sanitize "$2")"; } @@ -146,6 +149,7 @@ echo '[{"number": 9, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwn echo '[{"number": 9, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "develop"}]' > "${TMP}/pr.wrongbase" echo '[{"number": 5, "headRefName": "pin-spm-checksum-0.0.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_older" echo '[{"number": 6, "headRefName": "pin-spm-checksum-9.9.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_newer" +echo '[{"number": 12, "headRefName": "pin-spm-checksum-1.2.3+meta", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_meta" # set_fixtures [default_diff] # default_diff: 0 = Package.swift identical to the default branch (pin merged). From 5f65a5fbf36df4f130dfd818b62a6a3f4e46cbc4 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 15:58:44 +0100 Subject: [PATCH 35/53] ci: align gate wording with the trigger surface --- CHANGELOG.md | 2 +- docs/mobile-bindings.md | 3 ++- scripts/release/test-open-spm-pr.sh | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d19c9c7..dcd9bb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added -- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every `Package.swift` edit — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. +- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every pull request (and reserved-namespace push) that edits `Package.swift` — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. - bindings: new `mintlayer-wallet-bindings` crate exposing the Mintlayer wallet primitives to Kotlin and Swift via UniFFI, mirroring the full diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 20156f9..ac9b16f 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -174,7 +174,8 @@ release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM resolution for the release. The `ci.yml` "Pin ordering" gate applies -to every pull request or push that edits `Package.swift`, whatever +to every pull request and to every push of the reserved +`pin-spm-checksum-*` branches that edits `Package.swift`, whatever the head branch is named: the pinned checksum must match the `SHA256SUMS` published for the release the pin names (an unverifiable pin would strand every SPM consumer on a resolution failure), and the diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index b3adb1d..61375e1 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -543,11 +543,13 @@ assert_no_mutations # 34. Guard: mangled checksum (65+ hex) on origin -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b9700"\n' > "${TMP}/origin_swift" +: > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ >/dev/null 2>&1 ) rc=$? +LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "guard refuses 65-hex checksum"; else bad "guard refuses 65-hex checksum" "exit ${rc}"; fi assert_no_mutations From 81897005b2e9a5689d69db0f6c5413146ff051e3 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 16:11:06 +0100 Subject: [PATCH 36/53] ci: guard the deactivated pin compare and test both supersede paths --- scripts/release/open-spm-pr.sh | 31 ++++++++++++++++++----------- scripts/release/semver.sh | 8 +++++--- scripts/release/test-open-spm-pr.sh | 23 +++++++++++++++++++-- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index f2c171b..32a7b54 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -191,18 +191,25 @@ elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then # A checksum line exists but is not 64 lowercase hex: mangled pin. echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${origin_pin_sum_raw}")" exit 1 -elif { cmp="$(semver_cmp "${VERSION}" "${origin_version}")"; [[ "${cmp}" =~ ^-?[012]$ ]]; } && [ "${cmp}" -le 0 ]; then - # A deactivated (zeroed-checksum) pin whose release marker is - # newer-or-equal: main claims ${origin_version} with no active - # checksum. Pinning ${VERSION} here would leave the marker and the - # checksum in conflict; manual repair required. semver_cmp keeps this - # aligned with the active-pin path at prerelease/build edges. - echo "::error::origin/${DEFAULT_BRANCH} carries a deactivated pin for ${origin_version} (>= ${VERSION}); refusing to pin - repair the default branch manually" - exit 1 -elif [ -z "${origin_pin_sum_raw}" ] && [ -n "${origin_pin_tag}" ]; then - # A tag line without any checksum line: mangled pin. - echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" - exit 1 +elif [ -n "${origin_pin_tag}" ]; then + # Not active, not checksum-mangled: either a deactivated + # (zeroed-checksum) pin or a tag line without any checksum line. + # Both refuse; the deactivated path orders with the comparator + # validated out-of-band, so a malformed result refuses instead of + # slipping past the guard. + if [ -z "${origin_pin_sum_raw}" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" + exit 1 + fi + cmp="$(semver_cmp "${VERSION}" "${origin_version}")" + if [[ ! "${cmp}" =~ ^-?[012]$ ]]; then + echo "::error::semver comparison failed for ${VERSION} against ${origin_version}" + exit 1 + fi + if [ "${cmp}" -le 0 ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries a deactivated pin for ${origin_version} (>= ${VERSION}); refusing to pin - repair the default branch manually" + exit 1 + fi fi git commit -m "chore: pin the SPM checksum to ${TAG}" diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh index f044ca2..fff29ea 100755 --- a/scripts/release/semver.sh +++ b/scripts/release/semver.sh @@ -22,9 +22,11 @@ semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 if [ -z "${x}" ]; then echo -1; return; fi if [ -z "${y}" ]; then echo 1; return; fi # Numeric identifiers are lower than alphanumeric ones. Two numeric - # identifiers compare by digit length then bytes (semver forbids - # leading zeros, so this equals numeric order for any length — no - # arithmetic, no overflow). + # identifiers compare by digit length then bytes (no arithmetic, no + # overflow). The caller regexes admit leading zeros, which semver + # forbids; with this comparator '01' < '1' deterministically, while + # the numeric-triple path treats 10#'01' == 10#'1' as equal — a + # documented deviation between the two sites, not a bug. if [[ "${x}" =~ ^[0-9]+$ ]] && [[ "${y}" =~ ^[0-9]+$ ]]; then if [ "${#x}" -ne "${#y}" ]; then [ "${#x}" -lt "${#y}" ] && { echo -1; return; } diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 61375e1..05e4744 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -988,8 +988,10 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi -# 60. Supersede: meta-suffix stale marker (>= precedence) -> refuse. -set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer +# 60. Supersede: build-metadata suffix on the open pin branch compares +# EQUAL (metadata excluded from precedence) -> refuse like any >= +# marker. +set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_meta : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -1003,6 +1005,23 @@ else bad "supersede refuses meta-suffix stale pin" "exit ${rc}: $(cat "${OUT}")" fi assert_no_mutations + +# 61. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> +# refuse. +set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer +: > "${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 "close or merge it before releasing" <<< "$(cat "${OUT}")"; then + ok "supersede refuses a newer open pin PR" +else + bad "supersede refuses a newer open pin PR" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations printf 'placeholder\n' > "${STUBS}/repo/Package.swift" # 61. semver.sh unit checks (sourced directly). From 96789b521ab29b0c21833351aecb90f909c1ed65 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 16:24:42 +0100 Subject: [PATCH 37/53] ci: escape the staged tag annotation and cover deactivated refusals --- .github/workflows/release.yml | 5 +++- docs/mobile-bindings.md | 5 ++-- scripts/release/pin-order-gate.sh | 4 ++- scripts/release/semver.sh | 2 +- scripts/release/test-open-spm-pr.sh | 45 ++++++++++++++++++++++++----- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cce8e7d..55dfeb3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -86,7 +86,10 @@ jobs: # instead. VERSION="${GITHUB_REF_NAME#wallet-bindings-v}" if [[ ! "${GITHUB_REF_NAME}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then - echo "::error::tag does not match wallet-bindings-v: ${GITHUB_REF_NAME}" + # %-escape and strip control bytes so a crafted tag name + # cannot spoof annotation content. + safe_tag="$(printf '%s' "${GITHUB_REF_NAME}" | tr -d '\000-\037\177' | sed 's/%/%25/g')" + echo "::error::tag does not match wallet-bindings-v: ${safe_tag}" exit 1 fi mkdir -p dist diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index ac9b16f..8c20f5f 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -191,8 +191,9 @@ bot pin PRs opened with the workflow token emit no pull_request CI events, so namespace protection plus the creation-time rewind guard are the controls for them. A pre-automation legacy branch (`pin-spm-checksum-v0.1.0`) can be deleted once this flow merges; -both the gate and the supersede loop tolerate its `v` suffix. Consumers never need a -Rust toolchain. +both the gate and the supersede loop tolerate its `v` suffix. + +Consumers never need a Rust toolchain. The major/minor/patch policy: bump the major version for FFI surface breaks, minor for additive exports, patch for fixes; entries are recorded in the repository `CHANGELOG.md`. diff --git a/scripts/release/pin-order-gate.sh b/scripts/release/pin-order-gate.sh index d65bc78..64f9e92 100755 --- a/scripts/release/pin-order-gate.sh +++ b/scripts/release/pin-order-gate.sh @@ -3,7 +3,9 @@ # # Applicability is diff-driven: every pull request or push whose diff # touches Package.swift is checked; anything else exits 0 ("nothing to -# check") without touching the network. For an applicable diff: +# check"). On pull_request events the PR-head fetch below necessarily +# precedes the diff, so "no network beyond that fetch" is the accurate +# claim for skipped diffs. For an applicable diff: # 1. The head's single releaseTag + hex checksum pin is extracted # with the shared stripper (pinlib.sh). # 2. The checksum is bound to the release the pin names: the diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh index fff29ea..889c326 100755 --- a/scripts/release/semver.sh +++ b/scripts/release/semver.sh @@ -24,7 +24,7 @@ semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 # Numeric identifiers are lower than alphanumeric ones. Two numeric # identifiers compare by digit length then bytes (no arithmetic, no # overflow). The caller regexes admit leading zeros, which semver - # forbids; with this comparator '01' < '1' deterministically, while + # forbids; with this comparator '01' > '1' deterministically, while # the numeric-triple path treats 10#'01' == 10#'1' as equal — a # documented deviation between the two sites, not a bug. if [[ "${x}" =~ ^[0-9]+$ ]] && [[ "${y}" =~ ^[0-9]+$ ]]; then diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 05e4744..8ff8ba7 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -39,12 +39,9 @@ ok() { pass=$((pass + 1)); echo "ok - $1"; } # forgery, control characters, DEL, and non-ASCII bytes before echoing. sanitize() { # PR-controlled output: replace every '::' so no workflow command can - # survive, per line. LF/CR are intentionally preserved — deleting them - # could splice two benign fragments into a new command — and each - # resulting line is safe because '::' no longer occurs in it. - # DEL and non-ASCII bytes are deleted outright (esc() in pinlib.sh - # does the same); LF/CR are preserved — deleting them could splice - # two benign fragments into a new command. + # survive, per line. DEL and non-ASCII bytes are deleted outright + # (esc() in pinlib.sh does the same); LF/CR are preserved — deleting + # them could splice two benign fragments into a new command. printf '%s' "$1" | tr -d '\000-\010\011\013\014\016-\037\177\200-\377' | sed 's/::/[::]/g' } bad() { fail=$((fail + 1)); echo "NOT OK - $1: $(sanitize "$2")"; } @@ -988,6 +985,40 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi +# 59b. Deactivated pin (zeroed checksum) whose marker is newer-or-equal +# -> refuse with the out-of-band comparator validation. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" +: > "${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 "carries a deactivated pin" <<< "$(cat "${OUT}")"; then + ok "deactivated newer-or-equal marker refused" +else + bad "deactivated newer-or-equal marker refused" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + +# 59c. A releaseTag line without any checksum line -> refuse as +# mangled. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v9.9.9"\n' > "${TMP}/origin_swift" +( 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}")" +# The upstream counts guard refuses this shape first (1 tag, 0 +# checksums); the inner tag-without-checksum branch below it is +# unreachable for this fixture and stays as defense in depth. +if [ "${rc}" = "1" ] && grep -q "0 checksum assignments" <<< "$(cat "${OUT}")"; then ok "tag-without-checksum origin refused"; else bad "tag-without-checksum origin refused" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations + # 60. Supersede: build-metadata suffix on the open pin branch compares # EQUAL (metadata excluded from precedence) -> refuse like any >= # marker. @@ -1024,7 +1055,7 @@ fi assert_no_mutations printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 61. semver.sh unit checks (sourced directly). +# 62. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" semver_cmp_check() { From ab24861b6904b740624f08b4438e7177a6c8f3f6 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 16:38:16 +0100 Subject: [PATCH 38/53] ci: cover base pin states and the gate push path --- .github/workflows/release.yml | 2 +- CHANGELOG.md | 1 - scripts/release/test-open-spm-pr.sh | 69 +++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55dfeb3..3b40825 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -88,7 +88,7 @@ jobs: if [[ ! "${GITHUB_REF_NAME}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then # %-escape and strip control bytes so a crafted tag name # cannot spoof annotation content. - safe_tag="$(printf '%s' "${GITHUB_REF_NAME}" | tr -d '\000-\037\177' | sed 's/%/%25/g')" + safe_tag="$(printf '%s' "${GITHUB_REF_NAME}" | tr -d '\000-\037\177\200-\377' | sed 's/%/%25/g')" echo "::error::tag does not match wallet-bindings-v: ${safe_tag}" exit 1 fi diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd9bb0..369fe14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,6 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added - Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every pull request (and reserved-namespace push) that edits `Package.swift` — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. - - bindings: new `mintlayer-wallet-bindings` crate exposing the Mintlayer wallet primitives to Kotlin and Swift via UniFFI, mirroring the full wasm-bindings surface: mnemonic → default account extended private key, diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 8ff8ba7..04afd7e 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -734,6 +734,25 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on an unreadable incoming # Ordering-only mode (empty EXPECTED_TAG): non-namespace Package.swift # edits are order-checked without a tag-equality requirement. The # caller (ci.yml) binds the checksum to the published release. + +# 45f-2. Base branch with no pin at all -> early-accept. +printf 'checksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" >/dev/null 2>&1 ) +rc=$? +if [ "${rc}" = "0" ]; then ok "pin order accepts any pin over an unpinned base"; else bad "pin order accepts any pin over an unpinned base" "exit ${rc}"; fi + +# 45f-3. A prefix-matching but malformed base pin line (stray suffix) -> +# refuse: the base is not "unpinned". +printf 'let releaseTag = "wallet-bindings-v1.0.0"x\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ] && grep -q "mangled pin line" <<< "$(cat "${OUT}")"; then ok "pin order refuses a prefix-mangled base pin"; else bad "pin order refuses a prefix-mangled base pin" "exit ${rc}: $(cat "${OUT}")"; fi printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ @@ -786,6 +805,16 @@ run_gate() { bash "${GATE}" > "${OUT}" 2>&1 ) rc=$? } +# Push-event variant: no PR-head fetch branch; the pushed SHA is +# already local. +run_gate_push() { + ( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + BASE_REF="main" HEAD_SHA="0123456789abcdef0123456789abcdef01234567" \ + HEAD_REF="$1" EVENT_NAME="push" PR_NUMBER="" \ + bash "${GATE}" > "${OUT}" 2>&1 ) + rc=$? +} run_gate "feature" if [ "${rc}" = "0" ] && grep -q "untouched" "${OUT}"; then ok "gate skips a PR that does not touch Package.swift" @@ -828,6 +857,21 @@ else bad "gate refuses a mangled head" "exit ${rc}: $(cat "${OUT}")" fi +# Push event: same binding and ordering without the PR-head fetch. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +printf '1' > "${TMP}/head_touched" +run_gate_push "feature" +if [ "${rc}" = "0" ]; then ok "gate push event allows a bound forward pin"; else bad "gate push event allows a bound forward pin" "exit ${rc}: $(cat "${OUT}")"; fi + +printf '0' > "${TMP}/head_touched" +run_gate_push "feature" +if [ "${rc}" = "0" ] && grep -q "untouched" "${OUT}"; then + ok "gate push event skips an untouched Package.swift" +else + bad "gate push event skips an untouched Package.swift" "exit ${rc}: $(cat "${OUT}")" +fi +printf '1' > "${TMP}/head_touched" + # Reserved namespace: strict tag equality against the branch name. printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" run_gate "pin-spm-checksum-1.3.0" @@ -985,6 +1029,31 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi +# 58b. Guard: unparseable origin pin tag (no version) -> fail closed. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +: > "${LOG}" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "1" ] && grep -q "unparseable pin tag" <<< "$(cat "${OUT}")"; then ok "guard refuses an unparseable origin pin tag"; else bad "guard refuses an unparseable origin pin tag" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations + +# 58c. Guard: an all-comments origin carries no code lines -> fail +# closed. +printf '// nothing but comments here\n/* still comments */\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "${XCSUM}" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "1" ] && grep -q "carries no code lines" <<< "$(cat "${OUT}")"; then ok "guard refuses a comment-only origin"; else bad "guard refuses a comment-only origin" "exit ${rc}: $(cat "${OUT}")"; fi +assert_no_mutations + # 59b. Deactivated pin (zeroed checksum) whose marker is newer-or-equal # -> refuse with the out-of-band comparator validation. set_fixtures 0 1 "${FULLY_PINNED}" pr.none From 317c277f749101bde8e5697518449417e8d7d8df Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 16:50:23 +0100 Subject: [PATCH 39/53] ci: refuse broken-prefix base pins and scope release finality --- .github/workflows/release.yml | 5 ++++- CHANGELOG.md | 2 +- docs/mobile-bindings.md | 6 +++--- scripts/release/check-pin-order.sh | 14 +++++++------- scripts/release/test-open-spm-pr.sh | 10 ++++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b40825..5dfe43f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -287,7 +287,10 @@ jobs: # not affect semver finality, so only the pre-release # hyphen disqualifies. latest_flag="--latest" - case "$VERSION" in *-*) latest_flag="--latest=false" ;; esac + # Test only the pre-metadata part: a hyphen inside build + # metadata (+build-2) does not make the release a + # pre-release. + case "${VERSION%%+*}" in *-*) latest_flag="--latest=false" ;; esac gh release create "$TAG" \ dist/mintlayer-wallet-bindings-*.aar \ dist/MintlayerWalletBindings.xcframework.zip \ diff --git a/CHANGELOG.md b/CHANGELOG.md index 369fe14..dda1fee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added -- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every pull request (and reserved-namespace push) that edits `Package.swift` — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. +- Merge-time enforcement for SPM pins: a ci.yml "Pin ordering" gate checks every pull request targeting the default branch (and reserved-namespace push) that edits `Package.swift` — the pinned checksum must match the release's published `SHA256SUMS`, the pin must advance the release on the default branch, and reserved-namespace heads must pin exactly their declared release. - bindings: new `mintlayer-wallet-bindings` crate exposing the Mintlayer wallet primitives to Kotlin and Swift via UniFFI, mirroring the full wasm-bindings surface: mnemonic → default account extended private key, diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 8c20f5f..4f280db 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -174,9 +174,9 @@ release, and then opens a pull request that pins the SPM checksum in the root `Package.swift` to the released artifact. The release exists before the pin PR is opened; a maintainer merges that pin PR to activate SPM resolution for the release. The `ci.yml` "Pin ordering" gate applies -to every pull request and to every push of the reserved -`pin-spm-checksum-*` branches that edits `Package.swift`, whatever -the head branch is named: the pinned checksum must match the +to every pull request targeting the default branch and to every push +of the reserved `pin-spm-checksum-*` branches that edits +`Package.swift`, whatever the head branch is named: the pinned checksum must match the `SHA256SUMS` published for the release the pin names (an unverifiable pin would strand every SPM consumer on a resolution failure), and the pin must advance the release currently on the default branch — a diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 14d64d7..06887f2 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -101,16 +101,16 @@ git fetch origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}" origin_swift="$(git show "origin/${BASE_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${BASE_BRANCH}:Package.swift"; exit 1; } origin_code="$(strip_swift_comments "${origin_swift}")" -# The same prefix count every sibling script uses, plus the anchored -# count: a prefix-matching but mangled pin line on the base (stray -# suffix, double space) would otherwise read as "no pin" and let a -# rewind pass. -current_prefix="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = ' || true)" +# Mangle detection is not prefix-anchored: ANY releaseTag-bearing code +# line on the base that is not the canonical assignment (broken prefix, +# stray suffix, doubled spaces) must refuse — otherwise a corrupted +# base would read as "no pin" and let a rewind pass. +current_bearing="$(printf '%s\n' "${origin_code}" | grep -c 'releaseTag' || true)" current_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" if [ "${current_matches}" = "0" ]; then - if [ "${current_prefix}" != "0" ]; then - echo "::error::origin/${BASE_BRANCH} carries ${current_prefix} mangled pin line(s) and no well-formed one; refusing (repair manually)" + if [ "${current_bearing}" != "0" ]; then + echo "::error::origin/${BASE_BRANCH} carries ${current_bearing} mangled pin line(s) and no well-formed one; refusing (repair manually)" exit 1 fi echo "no pin on ${BASE_BRANCH}; any pin order is acceptable" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 04afd7e..05a02e3 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -753,6 +753,16 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" bash "${ORDER}" main "" > "${OUT}" 2>&1 ) rc=$? if [ "${rc}" = "1" ] && grep -q "mangled pin line" <<< "$(cat "${OUT}")"; then ok "pin order refuses a prefix-mangled base pin"; else bad "pin order refuses a prefix-mangled base pin" "exit ${rc}: $(cat "${OUT}")"; fi + +# Broken-prefix variant: a double space before '=' breaks the anchored +# prefix itself — detection must not be prefix-anchored. +printf 'let releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ] && grep -q "mangled pin line" <<< "$(cat "${OUT}")"; then ok "pin order refuses a broken-prefix base pin"; else bad "pin order refuses a broken-prefix base pin" "exit ${rc}: $(cat "${OUT}")"; fi printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ From bc24c003615c47f92146326d7337d4101742df0b Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 17:05:35 +0100 Subject: [PATCH 40/53] ci: make the pin gate refuse every mangled base shape --- scripts/release/check-pin-order.sh | 27 ++++++++++------- scripts/release/test-open-spm-pr.sh | 45 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 06887f2..793a2cd 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -44,10 +44,11 @@ fi # The incoming pin comes from the PR head SHA (workflow) or the working # tree (legacy/harness) — always consumed as data by this trusted code. if [ -n "${INCOMING_REF}" ]; then - normalized_in="$(strip_swift_comments "$(git show "${INCOMING_REF}:Package.swift" 2>/dev/null)")" || { - echo "::error::cannot read Package.swift from $(esc "${INCOMING_REF}")" - exit 1 - } + # Capture the show first: strip_swift_comments always exits 0, so + # piping straight into it would mask a failed read. + incoming_swift="$(git show "${INCOMING_REF}:Package.swift" 2>/dev/null)" \ + || { echo "::error::cannot read Package.swift from $(esc "${INCOMING_REF}")"; exit 1; } + normalized_in="$(strip_swift_comments "${incoming_swift}")" else if [ ! -r Package.swift ]; then echo "::error::cannot read Package.swift" @@ -101,11 +102,15 @@ git fetch origin "+refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}" origin_swift="$(git show "origin/${BASE_BRANCH}:Package.swift" 2>/dev/null)" \ || { echo "::error::cannot read origin/${BASE_BRANCH}:Package.swift"; exit 1; } origin_code="$(strip_swift_comments "${origin_swift}")" -# Mangle detection is not prefix-anchored: ANY releaseTag-bearing code -# line on the base that is not the canonical assignment (broken prefix, -# stray suffix, doubled spaces) must refuse — otherwise a corrupted -# base would read as "no pin" and let a rewind pass. -current_bearing="$(printf '%s\n' "${origin_code}" | grep -c 'releaseTag' || true)" +if [ -z "${origin_code}" ]; then + echo "::error::origin/${BASE_BRANCH}:Package.swift carries no code lines; refusing (repair manually)" + exit 1 +fi +# Mangle detection is not prefix-anchored: the base must carry exactly +# one canonical assignment and nothing else pin-shaped. 'let +# releaseTag' occurrence counting works here because the download-URL +# line loses its \(releaseTag) interpolation to comment stripping. +current_bearing="$(printf '%s\n' "${origin_code}" | { grep -o 'let releaseTag' || true; } | wc -l | tr -d ' ')" current_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" if [ "${current_matches}" = "0" ]; then @@ -116,8 +121,8 @@ if [ "${current_matches}" = "0" ]; then echo "no pin on ${BASE_BRANCH}; any pin order is acceptable" exit 0 fi -if [ "${current_matches}" != "1" ]; then - echo "::error::expected at most one releaseTag assignment on ${BASE_BRANCH}, found ${current_matches}" +if [ "${current_matches}" != "1" ] || [ "${current_bearing}" != "${current_matches}" ]; then + echo "::error::expected exactly one canonical releaseTag assignment on ${BASE_BRANCH}, found ${current_matches} canonical and ${current_bearing} pin-bearing occurrence(s); refusing (repair manually)" exit 1 fi current_tag="$(printf '%s\n' "${origin_code}" \ diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 05a02e3..43184bb 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -147,6 +147,7 @@ echo '[{"number": 9, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwn echo '[{"number": 5, "headRefName": "pin-spm-checksum-0.0.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_older" echo '[{"number": 6, "headRefName": "pin-spm-checksum-9.9.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_newer" echo '[{"number": 12, "headRefName": "pin-spm-checksum-1.2.3+meta", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_meta" +echo '[{"number": 13, "headRefName": "pin-spm-checksum-v0.1.1", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/pr.stale_legacy" # set_fixtures [default_diff] # default_diff: 0 = Package.swift identical to the default branch (pin merged). @@ -754,6 +755,28 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "1" ] && grep -q "mangled pin line" <<< "$(cat "${OUT}")"; then ok "pin order refuses a prefix-mangled base pin"; else bad "pin order refuses a prefix-mangled base pin" "exit ${rc}: $(cat "${OUT}")"; fi +# Mixed state: one canonical assignment plus an extra pin-bearing line +# that is not anchored (releaseTagX) -> refuse (extras beyond the +# canonical assignment are mangled state, even with a well-formed pin +# present). +printf 'let releaseTag = "wallet-bindings-v1.0.0"\nlet releaseTagX = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ] && grep -q "pin-bearing occurrence" <<< "$(cat "${OUT}")"; then ok "pin order refuses extra pin-bearing lines beside the canonical one"; else bad "pin order refuses extra pin-bearing lines beside the canonical one" "exit ${rc}: $(cat "${OUT}")"; fi + +# Comment-only base -> refuse (mirrors the guard; an unpinned verdict +# here would make any pin mergeable over a corrupted base). +printf '// nothing but comments\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ] && grep -q "carries no code lines" <<< "$(cat "${OUT}")"; then ok "pin order refuses a comment-only base"; else bad "pin order refuses a comment-only base" "exit ${rc}: $(cat "${OUT}")"; fi + # Broken-prefix variant: a double space before '=' breaks the anchored # prefix itself — detection must not be prefix-anchored. printf 'let releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" @@ -895,6 +918,12 @@ else bad "gate strict mode refuses a tag mismatch" "exit ${rc}: $(cat "${OUT}")" fi +# Legacy v-suffix branch names (pre-automation) derive the correct +# expected tag: pin-spm-checksum-v1.3.0 -> wallet-bindings-v1.3.0. +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" +run_gate "pin-spm-checksum-v1.3.0" +if [ "${rc}" = "0" ]; then ok "gate tolerates a legacy v-suffix branch name"; else bad "gate tolerates a legacy v-suffix branch name" "exit ${rc}: $(cat "${OUT}")"; fi + # A reserved-namespace branch whose suffix is not a semver -> refuse # at the derivation check. run_gate "pin-spm-checksum-oops" @@ -1116,6 +1145,22 @@ else fi assert_no_mutations +# 60b. Supersede: a legacy v-suffix stale branch (pin-spm-checksum- +# v0.1.1 -> version 0.1.1 < 1.2.3) is closed like any older pin. +set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_legacy +: > "${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 -- "pr close 13" "${LOG}"; then + ok "supersede closes a legacy v-suffix stale pin PR" +else + bad "supersede closes a legacy v-suffix stale pin PR" "exit ${rc}: $(cat "${OUT}")" +fi + # 61. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> # refuse. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer From 0c1aef20152a2c48e83d3e43e96df449a6685431 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 17:17:13 +0100 Subject: [PATCH 41/53] ci: correct the pin count rationale in the gate --- docs/mobile-bindings.md | 9 +++++---- scripts/release/check-pin-order.sh | 8 +++++--- scripts/release/test-open-spm-pr.sh | 1 - 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/mobile-bindings.md b/docs/mobile-bindings.md index 4f280db..173a3eb 100644 --- a/docs/mobile-bindings.md +++ b/docs/mobile-bindings.md @@ -176,10 +176,11 @@ the pin PR is opened; a maintainer merges that pin PR to activate SPM resolution for the release. The `ci.yml` "Pin ordering" gate applies to every pull request targeting the default branch and to every push of the reserved `pin-spm-checksum-*` branches that edits -`Package.swift`, whatever the head branch is named: the pinned checksum must match the -`SHA256SUMS` published for the release the pin names (an unverifiable -pin would strand every SPM consumer on a resolution failure), and the -pin must advance the release currently on the default branch — a +`Package.swift`, whatever the head branch is named: the pinned +checksum must match the `SHA256SUMS` published for the release the +pin names (an unverifiable pin would strand every SPM consumer on a +resolution failure), and the pin must advance the release currently +on the default branch — a rewind or same-version repair is refused. Heads on the reserved `pin-spm-checksum-*` namespace additionally must pin exactly the release their branch name declares. On pull_request events the gate diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 793a2cd..218e54c 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -107,9 +107,11 @@ if [ -z "${origin_code}" ]; then exit 1 fi # Mangle detection is not prefix-anchored: the base must carry exactly -# one canonical assignment and nothing else pin-shaped. 'let -# releaseTag' occurrence counting works here because the download-URL -# line loses its \(releaseTag) interpolation to comment stripping. +# one canonical assignment and nothing else pin-shaped. Counting the +# substring 'let releaseTag' is safe because the download-URL line +# never contains it (its \(releaseTag) interpolation is Swift string +# interpolation inside a string literal and survives stripping; the +# line reads 'let releaseBaseUrl = ...'). current_bearing="$(printf '%s\n' "${origin_code}" | { grep -o 'let releaseTag' || true; } | wc -l | tr -d ' ')" current_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 43184bb..190e724 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1197,7 +1197,6 @@ else bad "semver comparator unit checks" "unexpected comparator output" fi -# Static check: the TAG regex must be byte-identical in every copy # Byte-identical TAG regex everywhere it appears: four occurrences in # release.yml, one in open-spm-pr.sh, two in guard-release-refresh.sh, # two in pin-order-gate.sh, one in check-pin-order.sh, and an explicit From b9b43f4df9de4ea8c9b9584ca5211b4d545d97e4 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 17:30:26 +0100 Subject: [PATCH 42/53] ci: recheck open pin prs after the release branch push --- scripts/release/open-spm-pr.sh | 10 ++ scripts/release/test-open-spm-pr.sh | 168 ++++++++++++++++++++-------- 2 files changed, 130 insertions(+), 48 deletions(-) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 32a7b54..3ff2fe5 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -273,6 +273,16 @@ OLD_PRS # the bot commit. git push --force origin "${BRANCH}" +# Re-run the open-PR lookup: the PR found before the supersede loop may +# have been merged by a maintainer while this run was in flight. In +# that window an "updated its head branch" verdict would end the run +# green with NO open pin PR for the release, so the post-push state is +# authoritative for the reuse-vs-create decision. +existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ + --json number,headRepositoryOwner,isCrossRepository,baseRefName \ + --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" \ + || { echo "::error::failed to re-list existing pin PRs after the push"; exit 1; } + if [ -n "${existing_pr}" ]; then echo "checksum-pin PR already exists (#${existing_pr}); updated its head branch" else diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 190e724..c51ad5e 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -94,6 +94,15 @@ if [ "$1" = "release" ] && [ "$2" = "download" ]; then exit 0 fi if [ "$1" = "pr" ] && [ "$2" = "list" ]; then + # Post-push re-lookup simulation: the second list returns empty when + # the knob is set (the pre-push PR merged in flight). + printf 'x\n' >> "${CASE_DIR}/pr_list_calls" 2>/dev/null || true + if [ "$(cat "${CASE_DIR}/second_pr_list_empty" 2>/dev/null || echo 0)" = "1" ] \ + && [ "$(wc -l < "${CASE_DIR}/pr_list_calls" 2>/dev/null || echo 1)" -ge 2 ]; then + # Jq-processed empty: the pre-push PR merged, no open pin PRs left. + printf '' + exit 0 + fi mode="$(cat "${CASE_DIR}/pr_list_fails" 2>/dev/null || echo "")" case "${mode}" in any) exit 1 ;; @@ -113,6 +122,10 @@ if [ "$1" = "pr" ] && [ "$2" = "list" ]; then printf '%s' "${payload}" | jq -r "${prog}" exit $? fi +if [ "$1" = "pr" ] && [ "$2" = "close" ] && [ "$(cat "${CASE_DIR}/pr_close_fails" 2>/dev/null || echo 0)" = "1" ]; then + echo "gh: pr close failed" >&2 + exit 1 +fi # pr close/create must reference a numeric PR (real gh rejects garbage). if [ "$1" = "pr" ] && { [ "$2" = "close" ] || [ "$2" = "create" ]; }; then for a in "$@"; do @@ -397,7 +410,7 @@ else bad "create proceeds over older pin" "${LOG_CONTENTS}" fi -# 23b. gh pr list failure on the existing-pin lookup -> fail closed +# 24. gh pr list failure on the existing-pin lookup -> fail closed # with no push and no PR opened. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'existing' > "${TMP}/pr_list_fails" @@ -418,7 +431,7 @@ else fi assert_no_mutations -# 23c. gh pr list failure on the supersede lookup -> fail closed. +# 25. gh pr list failure on the supersede lookup -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'supersede' > "${TMP}/pr_list_fails" : > "${LOG}" @@ -439,47 +452,47 @@ fi assert_no_mutations reset_origin -# 24. Same-version active pin with differing content -> rewind guard. +# 26. Same-version active pin with differing content -> rewind guard. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" run_case "same-version conflicting pin fails" 1 assert_no_mutations reset_origin -# 25. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. +# 27. merge-base git error (rc > 1) -> fail closed, distinct from rc 1. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '128' > "${TMP}/ancestry" run_case "merge-base git error fails" 1 assert_no_mutations printf '0' > "${TMP}/ancestry" -# 26. Unparseable origin pin tag -> fail closed. +# 28. Unparseable origin pin tag -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-vx"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "unparseable origin pin tag fails" 1 assert_no_mutations reset_origin -# 27. Active checksum with missing tag line -> fail closed (one-sided). +# 29. Active checksum with missing tag line -> fail closed (one-sided). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" run_case "one-sided active checksum fails" 1 assert_no_mutations reset_origin -# 28. TAG/VERSION mismatch -> fail closed before any fetch. +# 30. TAG/VERSION mismatch -> fail closed before any fetch. set_fixtures 0 1 "${NOT_PINNED}" pr.none run_case "mismatched tag and version fails" 1 "mintlayer/rust-sdk" main "${XCSUM}" 9.9.9 assert_no_mutations -# 29. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. +# 31. Mangled checksum line (valid tag, non-hex checksum) -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "deadbeef"\n' > "${TMP}/origin_swift" run_case "mangled origin checksum fails" 1 assert_no_mutations reset_origin -# 30. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. +# 32. Prerelease over final (1.2.3-rc.1 after 1.2.3) -> rewind, refused. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-rc.1" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -493,7 +506,7 @@ if [ "${rc}" = "1" ]; then ok "prerelease after final refused"; else bad "prerel assert_no_mutations reset_origin -# 31. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. +# 33. Final over prerelease (1.2.3 after 1.2.3-rc1) -> allowed forward. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3-rc1"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" : > "${LOG}" @@ -509,7 +522,7 @@ else fi reset_origin -# 32. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. +# 34. Origin pin 1.2.3+meta.b vs incoming 1.2.3+meta.a compares EQUAL -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta.a" // ... checksum: "'"${XCSUM}"'"' pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3+meta.b"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" @@ -523,7 +536,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "build-metadata equal precedence refused"; else bad "build-metadata equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 33. Origin pin without metadata vs incoming with metadata: equal +# 35. Origin pin without metadata vs incoming with metadata: equal # precedence -> refuse. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3+meta" // ... checksum: "'"${XCSUM}"'"' pr.none @@ -538,7 +551,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "metadata-suffix equal precedence refused"; else bad "metadata-suffix equal precedence refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 34. Guard: mangled checksum (65+ hex) on origin -> fail closed. +# 36. Guard: mangled checksum (65+ hex) on origin -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b9700"\n' > "${TMP}/origin_swift" : > "${LOG}" @@ -551,7 +564,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ]; then ok "guard refuses 65-hex checksum"; else bad "guard refuses 65-hex checksum" "exit ${rc}"; fi assert_no_mutations -# 35. Huge numeric prerelease identifiers compare by (digit length, +# 37. Huge numeric prerelease identifiers compare by (digit length, # bytes) — no arithmetic — so an origin pin of rc<20 digits> still # outranks incoming rc.2 -> refused, no arithmetic wrap. set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3-2" // ... @@ -568,7 +581,7 @@ if [ "${rc}" = "1" ]; then ok "huge numeric prerelease refused without wrap"; el assert_no_mutations reset_origin -# 36. Guard script: same tag + differing checksum -> refuse. +# 38. Guard script: same tag + differing checksum -> refuse. GUARD="${SCRIPT_DIR}/guard-release-refresh.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -578,7 +591,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses mismatched rebuild"; else bad "guard refuses mismatched rebuild" "exit ${rc}"; fi -# 37. Guard script: same tag + identical checksum (with a header +# 39. Guard script: same tag + identical checksum (with a header # comment whose version literal differs) -> allow. set_fixtures 0 1 "${FULLY_PINNED}" pr.none # shellcheck disable=SC2016 # \n are printf escapes, no expansion @@ -591,7 +604,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "0" ]; then ok "guard allows identical rebuild"; else bad "guard allows identical rebuild" "exit ${rc}"; fi -# 38. Guard script: older pin on main (forward release) -> allow. +# 40. Guard script: older pin on main (forward release) -> allow. printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -601,7 +614,7 @@ rc=$? if [ "${rc}" = "0" ]; then ok "guard allows forward release"; else bad "guard allows forward release" "exit ${rc}"; fi reset_origin -# 39. git show fails -> open-spm-pr.sh fails closed (no silent skip). +# 41. git show fails -> open-spm-pr.sh fails closed (no silent skip). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '1' > "${TMP}/show_fails" : > "${LOG}" @@ -616,7 +629,7 @@ assert_no_mutations printf '0' > "${TMP}/show_fails" reset_origin -# 40. Comment decoys inside an unterminated block comment; the real +# 42. Comment decoys inside an unterminated block comment; the real # code pin (v1.0.0) follows the block. Correct stripping sees 1.2.3 > # 1.0.0 and allows; a stripping regression leaks the decoys (mangled # multi-pin state, or >= the incoming version) and refuses. @@ -629,7 +642,7 @@ rc=$? if [ "${rc}" = "0" ]; then ok "script ignores comment decoys"; else bad "script ignores comment decoys" "exit ${rc}"; fi reset_origin -# 41. Same decoy shape for the guard: real v1.0.0 pin follows the +# 43. Same decoy shape for the guard: real v1.0.0 pin follows the # block, so the refresh (1.2.3 > 1.0.0) must be allowed. printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\n*/\nlet releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -639,7 +652,7 @@ printf '/*\nchecksum: "111111111111111111111111111111111111111111111111111111111 rc=$? if [ "${rc}" = "0" ]; then ok "guard ignores comment decoys"; else bad "guard ignores comment decoys" "exit ${rc}"; fi -# 42. Guard: a failed origin refresh must fail closed (no clobber +# 44. Guard: a failed origin refresh must fail closed (no clobber # decision can be made against a stale pin view). printf '1' > "${TMP}/fetch_fails" ( cd "${STUBS}/repo" && \ @@ -651,7 +664,7 @@ printf '0' > "${TMP}/fetch_fails" if [ "${rc}" = "1" ]; then ok "guard origin refresh failure fails closed"; else bad "guard origin refresh failure fails closed" "exit ${rc}"; fi reset_origin -# 43. Guard: zero releaseTag assignments -> refuse. +# 45. Guard: zero releaseTag assignments -> refuse. printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -660,7 +673,7 @@ printf 'checksum: "0000000000000000000000000000000000000000000000000000000000000 rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses zero assignments"; else bad "guard refuses zero assignments" "exit ${rc}"; fi -# 44. Guard: two releaseTag assignments -> refuse. +# 46. Guard: two releaseTag assignments -> refuse. printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -669,7 +682,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bind rc=$? if [ "${rc}" = "1" ]; then ok "guard refuses duplicate assignments"; else bad "guard refuses duplicate assignments" "exit ${rc}"; fi -# 45. Guard: invalid checksum -> refuse. +# 47. Guard: invalid checksum -> refuse. reset_origin ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -678,7 +691,7 @@ reset_origin rc=$? if [ "${rc}" = "1" ]; then ok "guard rejects invalid checksum"; else bad "guard rejects invalid checksum" "exit ${rc}"; fi -# 46. Guard: git show failure -> fail closed. +# 48. Guard: git show failure -> fail closed. printf '1' > "${TMP}/show_fails" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -689,7 +702,7 @@ if [ "${rc}" = "1" ]; then ok "guard fails closed on git show failure"; else bad printf '0' > "${TMP}/show_fails" reset_origin -# 47. Pin-order script: upgrade allows, downgrade refuses, same refuses. +# 49. Pin-order script: upgrade allows, downgrade refuses, same refuses. ORDER="${SCRIPT_DIR}/check-pin-order.sh" printf 'let releaseTag = "wallet-bindings-v1.2.3+meta"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" @@ -713,7 +726,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses same version"; else bad "pin order refuses same version" "exit ${rc}"; fi -# 48. Production form: the incoming pin read from an INCOMING_REF +# 50. Production form: the incoming pin read from an INCOMING_REF # (the PR head SHA) rather than the working tree. printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" @@ -723,7 +736,7 @@ printf 'placeholder\n' > "${STUBS}/repo/Package.swift" rc=$? if [ "${rc}" = "0" ]; then ok "pin order reads the incoming pin from a ref"; else bad "pin order reads the incoming pin from a ref" "exit ${rc}"; fi -# 49. Same, but the ref read fails -> fail closed (esc'd annotation). +# 51. Same, but the ref read fails -> fail closed (esc'd annotation). printf '1' > "${TMP}/incoming_show_fails" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -736,7 +749,7 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on an unreadable incoming # edits are order-checked without a tag-equality requirement. The # caller (ci.yml) binds the checksum to the published release. -# 45f-2. Base branch with no pin at all -> early-accept. +# 52. Base branch with no pin at all -> early-accept. printf 'checksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ @@ -745,7 +758,7 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "0" ]; then ok "pin order accepts any pin over an unpinned base"; else bad "pin order accepts any pin over an unpinned base" "exit ${rc}"; fi -# 45f-3. A prefix-matching but malformed base pin line (stray suffix) -> +# 53. A prefix-matching but malformed base pin line (stray suffix) -> # refuse: the base is not "unpinned". printf 'let releaseTag = "wallet-bindings-v1.0.0"x\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" @@ -946,7 +959,7 @@ fi printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" printf 'let releaseTag = "wallet-bindings-v0.0.0" // placeholder\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" -# 50. Reserved-namespace base branch -> fail closed. +# 54. Reserved-namespace base branch -> fail closed. # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" ( cd "${STUBS}/repo" && \ @@ -955,7 +968,7 @@ printf 'let releaseTag = "wallet-bindings-v0.9.0"\nchecksum: "${XCSUM}"\n' > "${ rc=$? if [ "${rc}" = "1" ]; then ok "pin order rejects reserved namespace"; else bad "pin order rejects reserved namespace" "exit ${rc}"; fi -# 51. Ambiguous PR head (a second releaseTag line) -> strict mode +# 55. Ambiguous PR head (a second releaseTag line) -> strict mode # refuses: the normalized head must carry exactly the expected # assignment and no other releaseTag- or checksum-bearing line. printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\nlet releaseTag = "wallet-bindings-v1.2.3"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" @@ -966,7 +979,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses ambiguous PR head"; else bad "pin order refuses ambiguous PR head" "exit ${rc}"; fi -# 52. Single-defect counterpart: exactly the expected head but a +# 56. Single-defect counterpart: exactly the expected head but a # non-hex checksum -> strict mode refuses. # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" @@ -976,7 +989,7 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${ rc=$? if [ "${rc}" = "1" ]; then ok "pin order refuses a non-hex checksum"; else bad "pin order refuses a non-hex checksum" "exit ${rc}"; fi -# 53. git show failure on the base -> fail closed. +# 57. git show failure on the base -> fail closed. printf '1' > "${TMP}/show_fails" # shellcheck disable=SC2016 # fixture line content is not expanded printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "${XCSUM}"\n' > "${STUBS}/repo/Package.swift" @@ -988,7 +1001,7 @@ if [ "${rc}" = "1" ]; then ok "pin order fails closed on git show error"; else b printf '0' > "${TMP}/show_fails" printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 54. Strict mode PASS path over a representative root Package.swift shape: +# 58. Strict mode PASS path over a representative root Package.swift shape: # header comment, the download URL interpolating \(releaseTag) (which a # substring 'releaseTag' count would double-count), releaseTag at # column 0, checksum indented 12 spaces. @@ -1001,7 +1014,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "aaf7197f472c01483e rc=$? if [ "${rc}" = "0" ]; then ok "strict mode passes the real Package.swift shape"; else bad "strict mode passes the real Package.swift shape" "exit ${rc}"; fi -# 55. Supersede: an older stale pin PR is closed. +# 59. Supersede: an older stale pin PR is closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_older reset_origin : > "${LOG}" @@ -1016,7 +1029,7 @@ else bad "supersede closes the older stale pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 56. Supersede: a newer open pin PR refuses the run. +# 60. Supersede: a newer open pin PR refuses the run. cp "${TMP}/pr.stale_newer" "${TMP}/existing_pr" : > "${LOG}" ( cd "${STUBS}/repo" && \ @@ -1030,7 +1043,7 @@ else bad "supersede refuses a newer open pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 57. Guard over a deactivated newer-or-equal marker: refresh allowed (rewind refusal enforced upstream by open-spm-pr.sh). +# 61. Guard over a deactivated newer-or-equal marker: refresh allowed (rewind refusal enforced upstream by open-spm-pr.sh). set_fixtures 0 1 'let releaseTag = "wallet-bindings-v9.9.9" checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none : > "${LOG}" @@ -1043,7 +1056,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated newer marker (enforced upstream)"; else bad "guard allows refresh over deactivated newer marker" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 58. Guard over a deactivated equal-version marker: refresh allowed (enforced upstream). +# 62. Guard over a deactivated equal-version marker: refresh allowed (enforced upstream). set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3" checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none : > "${LOG}" @@ -1056,7 +1069,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated equal marker (enforced upstream)"; else bad "guard allows refresh over deactivated equal marker" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 59. Guard: deactivated OLDER pin -> allow (forward release). +# 63. Guard: deactivated OLDER pin -> allow (forward release). set_fixtures 0 1 'let releaseTag = "wallet-bindings-v0.1.0" checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none : > "${LOG}" @@ -1068,7 +1081,7 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi -# 58b. Guard: unparseable origin pin tag (no version) -> fail closed. +# 64. Guard: unparseable origin pin tag (no version) -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" : > "${LOG}" @@ -1081,7 +1094,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ] && grep -q "unparseable pin tag" <<< "$(cat "${OUT}")"; then ok "guard refuses an unparseable origin pin tag"; else bad "guard refuses an unparseable origin pin tag" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 58c. Guard: an all-comments origin carries no code lines -> fail +# 65. Guard: an all-comments origin carries no code lines -> fail # closed. printf '// nothing but comments here\n/* still comments */\n' > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ @@ -1093,7 +1106,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ] && grep -q "carries no code lines" <<< "$(cat "${OUT}")"; then ok "guard refuses a comment-only origin"; else bad "guard refuses a comment-only origin" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 59b. Deactivated pin (zeroed checksum) whose marker is newer-or-equal +# 66. Deactivated pin (zeroed checksum) whose marker is newer-or-equal # -> refuse with the out-of-band comparator validation. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" @@ -1111,7 +1124,7 @@ else fi assert_no_mutations -# 59c. A releaseTag line without any checksum line -> refuse as +# 67. A releaseTag line without any checksum line -> refuse as # mangled. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v9.9.9"\n' > "${TMP}/origin_swift" @@ -1127,7 +1140,7 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ] && grep -q "0 checksum assignments" <<< "$(cat "${OUT}")"; then ok "tag-without-checksum origin refused"; else bad "tag-without-checksum origin refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 60. Supersede: build-metadata suffix on the open pin branch compares +# 68. Supersede: build-metadata suffix on the open pin branch compares # EQUAL (metadata excluded from precedence) -> refuse like any >= # marker. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_meta @@ -1145,7 +1158,7 @@ else fi assert_no_mutations -# 60b. Supersede: a legacy v-suffix stale branch (pin-spm-checksum- +# 69. Supersede: a legacy v-suffix stale branch (pin-spm-checksum- # v0.1.1 -> version 0.1.1 < 1.2.3) is closed like any older pin. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_legacy : > "${LOG}" @@ -1161,7 +1174,66 @@ else bad "supersede closes a legacy v-suffix stale pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 61. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> +# 70. Reuse-path supersede: an open same-head PR (pr.own) plus a +# stale-older open PR (number 5) -> pr close 5 happens on the reuse +# path and the run ends with "updated its head branch". +set_fixtures 0 1 "${FULLY_PINNED}" pr.own +printf '[{"number": 7, "headRefName": "pin-spm-checksum-1.2.3", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}, {"number": 5, "headRefName": "pin-spm-checksum-0.0.9", "headRepositoryOwner": {"login": "mintlayer"}, "isCrossRepository": false, "baseRefName": "main"}]' > "${TMP}/existing_pr" +: > "${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}")" +CLOSE_LINE="$(grep -n -- "pr close 5" "${LOG}" | head -1 | cut -d: -f1 || true)" +if [ "${rc}" = "0" ] && [ -n "${CLOSE_LINE}" ] && grep -q "updated its head branch" <<< "$(cat "${OUT}")"; then + ok "reuse-path supersede closes the older PR before the update" +else + bad "reuse-path supersede closes the older PR before the update" "exit ${rc}, close=${CLOSE_LINE}, out=$(cat "${OUT}")" +fi + +# 71. A failing gh pr close fails the run before any push. +set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_older +printf '1' > "${TMP}/pr_close_fails" +: > "${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 \ + >/dev/null 2>&1 ) +rc=$? +printf '0' > "${TMP}/pr_close_fails" +LOG_CONTENTS="$(cat "${LOG}")" +PUSHED="$(grep -c "git push" <<< "${LOG_CONTENTS}" || true)" +if [ "${rc}" = "1" ] && [ "${PUSHED}" = "0" ]; then + ok "supersede close failure fails closed" +else + bad "supersede close failure fails closed" "exit ${rc}, pushes=${PUSHED}" +fi +assert_no_mutations + +# 72. Post-push re-lookup: when the pre-push PR merged in flight (the +# second list returns empty), the run falls through to gh pr create +# instead of claiming it updated a merged PR's head. +set_fixtures 0 1 "${FULLY_PINNED}" pr.own +printf '1' > "${TMP}/second_pr_list_empty" +rm -f "${TMP}/pr_list_calls" +: > "${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=$? +printf '0' > "${TMP}/second_pr_list_empty" +rm -f "${TMP}/pr_list_calls" +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "0" ] && grep -q "gh pr create" "${LOG}" && ! grep -q "updated its head branch" "${LOG}"; then + ok "post-push empty re-lookup falls through to create" +else + bad "post-push empty re-lookup falls through to create" "exit ${rc}: $(cat "${OUT}")" +fi + +# 73. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> # refuse. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer : > "${LOG}" @@ -1179,7 +1251,7 @@ fi assert_no_mutations printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 62. semver.sh unit checks (sourced directly). +# 74. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" semver_cmp_check() { From a617829032832966e48ff86962d0a5672c1b566d Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 17:40:06 +0100 Subject: [PATCH 43/53] ci: document trigger assumptions and pin state preflight --- .github/workflows/ci.yml | 5 +++++ scripts/release/open-spm-pr.sh | 12 +++++++++-- scripts/release/test-open-spm-pr.sh | 31 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0832cb..7cd48e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,10 @@ name: CI +# Workflow triggers cannot use expressions: these branch filters +# hardcode "main" as the default branch. The gate and the release +# scripts derive the default branch dynamically, but a default-branch +# RENAME must also update these two filter lines or PR-side gating +# silently stops running. on: push: branches: [main, 'pin-spm-checksum-**'] diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 3ff2fe5..290a3a0 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -213,12 +213,17 @@ elif [ -n "${origin_pin_tag}" ]; then fi git commit -m "chore: pin the SPM checksum to ${TAG}" +# Preflight canary: fail fast when the PR-state lookups are broken +# before anything is mutated. The value itself is discarded (hence the +# deliberate shellcheck disable below) — the reuse-vs-create decision +# is made by the post-push re-lookup. # Only an OPEN pull request against the default branch from this # repository's own branch counts. Fork PRs, same-owner cross-repo PRs, # and PRs targeting a non-default base must not suppress the genuine bot # PR. The owner name is validated before it is interpolated into the jq # program; --paginate keeps the check independent of list windows. -existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ +# shellcheck disable=SC2034 # canary: value intentionally discarded +preflight_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ --json number,headRepositoryOwner,isCrossRepository,baseRefName \ --jq "[.[] | select(.headRepositoryOwner.login == \"${owner}\" and .isCrossRepository == false and .baseRefName == \"${DEFAULT_BRANCH}\")][0].number // empty")" \ || { echo "::error::failed to list existing pin PRs"; exit 1; } @@ -227,7 +232,10 @@ existing_pr="$(gh pr list --head "${BRANCH}" --state open --paginate \ # NEWER release's pin PR is still open (merging it after this one would # rewind the pin; the concurrency group serializes runs, not queue # order). Runs on both the create and reuse paths. Close failures fail -# the run - a stale open pin PR is a rewind hazard. +# the run - a stale open pin PR is a rewind hazard. Operator note: +# closes happen BEFORE the push, so a push failure leaves a transient +# zero-open-pin-PR window; the direction is safe (main stays pinned to +# the older release) and the next run is idempotent. superseded="" # Same trust filters as the existing_pr lookup: fork PRs, same-owner # cross-repo PRs, and PRs against a non-default base never constrain diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index c51ad5e..5c10342 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -97,6 +97,17 @@ if [ "$1" = "pr" ] && [ "$2" = "list" ]; then # Post-push re-lookup simulation: the second list returns empty when # the knob is set (the pre-push PR merged in flight). printf 'x\n' >> "${CASE_DIR}/pr_list_calls" 2>/dev/null || true + # relookup_fails: fail ONLY the post-push re-lookup (the second + # --head list), leaving the pre-flight canary green. + if [ "$3" = "--head" ] || [ "$4" = "--head" ]; then + n_heads="$(cat "${CASE_DIR}/head_list_calls" 2>/dev/null || echo 0)" + n_heads=$((n_heads + 1)) + printf '%s' "${n_heads}" > "${CASE_DIR}/head_list_calls" + if [ "$(cat "${CASE_DIR}/relookup_fails" 2>/dev/null || echo 0)" = "1" ] && [ "${n_heads}" -ge 2 ]; then + echo "gh: re-lookup failed" >&2 + exit 1 + fi + fi if [ "$(cat "${CASE_DIR}/second_pr_list_empty" 2>/dev/null || echo 0)" = "1" ] \ && [ "$(wc -l < "${CASE_DIR}/pr_list_calls" 2>/dev/null || echo 1)" -ge 2 ]; then # Jq-processed empty: the pre-push PR merged, no open pin PRs left. @@ -1233,6 +1244,26 @@ else bad "post-push empty re-lookup falls through to create" "exit ${rc}: $(cat "${OUT}")" fi +# 73. A failing post-push re-lookup fails the run (the pre-flight +# canary stays green; the branch was already pushed). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf '1' > "${TMP}/relookup_fails" +rm -f "${TMP}/head_list_calls" +: > "${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=$? +printf '0' > "${TMP}/relookup_fails" +rm -f "${TMP}/head_list_calls" +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "1" ] && grep -q "re-list existing pin PRs after the push" <<< "$(cat "${OUT}")"; then + ok "post-push re-lookup failure fails closed" +else + bad "post-push re-lookup failure fails closed" "exit ${rc}: $(cat "${OUT}")" +fi + # 73. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> # refuse. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer From c9bb324e316dc524b461070229e560b8b6923d2b Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 17:50:47 +0100 Subject: [PATCH 44/53] ci: align release base checks with the merge gate --- scripts/release/open-spm-pr.sh | 17 +++++++--- scripts/release/test-open-spm-pr.sh | 52 ++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 290a3a0..04a8d2a 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -150,13 +150,20 @@ origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" origin_code="$(strip_swift_comments "${origin_swift}")" tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v' || true)" sum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" -if [ "${tag_assignments}" != "1" ] || [ "${sum_assignments}" != "1" ]; then - echo "::error::origin/${DEFAULT_BRANCH} carries ${tag_assignments} releaseTag and ${sum_assignments} checksum assignments; expected exactly one of each" +# Pin-bearing occurrence count, mirroring the merge gate: extras beside +# the canonical assignment (broken prefix, releaseTagX variants) would +# open a pin PR the gate is guaranteed to reject. The download-URL line +# never contains the substring 'let releaseTag'. +tag_bearing="$(printf '%s\n' "${origin_code}" | { grep -o 'let releaseTag' || true; } | wc -l | tr -d ' ')" +if [ "${tag_assignments}" != "1" ] || [ "${sum_assignments}" != "1" ] || [ "${tag_bearing}" != "1" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries ${tag_assignments} canonical releaseTag assignments, ${tag_bearing} pin-bearing line(s) and ${sum_assignments} checksum assignments; expected exactly one canonical of each" exit 1 fi +# Same extraction/validation the merge gate uses: the whole tag token, +# then the full version regex — a hand-mangled 'wallet-bindings-vv1.2.3' +# must refuse here exactly like it refuses at merge time. origin_pin_tag="$(printf '%s\n' "${origin_code}" \ - | grep -oE 'let releaseTag = "wallet-bindings-v[^"]*"' \ - | grep -oE 'v[0-9][^"]*' || true)" + | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" origin_pin_sum_raw="$(printf '%s\n' "${origin_code}" \ | grep -E '^checksum: "' | head -1 | grep -oE '"[^"]*"' | tr -d '"' || true)" origin_pin_sum="$(printf '%s\n' "${origin_pin_sum_raw}" \ @@ -171,7 +178,7 @@ fi # An empty extraction (degenerate 'wallet-bindings-v' line) is itself # unparseable. if [ -n "${origin_pin_tag}" ]; then - origin_version="${origin_pin_tag#v}" + origin_version="${origin_pin_tag#wallet-bindings-v}" fi if [[ ! "${origin_version}" =~ ^[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::origin/${DEFAULT_BRANCH} carries an unparseable pin tag: $(esc "${origin_pin_tag}")" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 5c10342..3a0fed4 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1151,7 +1151,43 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "1" ] && grep -q "0 checksum assignments" <<< "$(cat "${OUT}")"; then ok "tag-without-checksum origin refused"; else bad "tag-without-checksum origin refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 68. Supersede: build-metadata suffix on the open pin branch compares +# 68. A hand-mangled base tag (wallet-bindings-vv1.2.3) must refuse +# exactly like the merge gate refuses it (extraction now uses the whole +# tag token plus the full version regex). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-vv1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +: > "${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 "unparseable pin tag" <<< "$(cat "${OUT}")"; then + ok "release refuses a hand-mangled base tag" +else + bad "release refuses a hand-mangled base tag" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + +# 69. An extra pin-bearing line beside the canonical assignment (no +# matter its anchor) refuses at release time too, mirroring the gate. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTagX = "wallet-bindings-v0.1.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +( 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 "pin-bearing line" <<< "$(cat "${OUT}")"; then + ok "release refuses extra pin-bearing base lines" +else + bad "release refuses extra pin-bearing base lines" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + +# 70. Supersede: build-metadata suffix on the open pin branch compares # EQUAL (metadata excluded from precedence) -> refuse like any >= # marker. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_meta @@ -1169,7 +1205,7 @@ else fi assert_no_mutations -# 69. Supersede: a legacy v-suffix stale branch (pin-spm-checksum- +# 71. Supersede: a legacy v-suffix stale branch (pin-spm-checksum- # v0.1.1 -> version 0.1.1 < 1.2.3) is closed like any older pin. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_legacy : > "${LOG}" @@ -1185,7 +1221,7 @@ else bad "supersede closes a legacy v-suffix stale pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 70. Reuse-path supersede: an open same-head PR (pr.own) plus a +# 72. Reuse-path supersede: an open same-head PR (pr.own) plus a # stale-older open PR (number 5) -> pr close 5 happens on the reuse # path and the run ends with "updated its head branch". set_fixtures 0 1 "${FULLY_PINNED}" pr.own @@ -1204,7 +1240,7 @@ else bad "reuse-path supersede closes the older PR before the update" "exit ${rc}, close=${CLOSE_LINE}, out=$(cat "${OUT}")" fi -# 71. A failing gh pr close fails the run before any push. +# 73. A failing gh pr close fails the run before any push. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_older printf '1' > "${TMP}/pr_close_fails" : > "${LOG}" @@ -1223,7 +1259,7 @@ else fi assert_no_mutations -# 72. Post-push re-lookup: when the pre-push PR merged in flight (the +# 74. Post-push re-lookup: when the pre-push PR merged in flight (the # second list returns empty), the run falls through to gh pr create # instead of claiming it updated a merged PR's head. set_fixtures 0 1 "${FULLY_PINNED}" pr.own @@ -1244,7 +1280,7 @@ else bad "post-push empty re-lookup falls through to create" "exit ${rc}: $(cat "${OUT}")" fi -# 73. A failing post-push re-lookup fails the run (the pre-flight +# 75. A failing post-push re-lookup fails the run (the pre-flight # canary stays green; the branch was already pushed). set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf '1' > "${TMP}/relookup_fails" @@ -1264,7 +1300,7 @@ else bad "post-push re-lookup failure fails closed" "exit ${rc}: $(cat "${OUT}")" fi -# 73. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> +# 76. Supersede: plain newer stale marker (9.9.9, cmp_old = -1) -> # refuse. set_fixtures 0 1 "${FULLY_PINNED}" pr.stale_newer : > "${LOG}" @@ -1282,7 +1318,7 @@ fi assert_no_mutations printf 'placeholder\n' > "${STUBS}/repo/Package.swift" -# 74. semver.sh unit checks (sourced directly). +# 77. semver.sh unit checks (sourced directly). # shellcheck source=/dev/null semver_tests="${SCRIPT_DIR}/semver.sh" semver_cmp_check() { From 0a32ba42836d21a7114ba7aa6bcdb8ea5d3d8555 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 18:01:04 +0100 Subject: [PATCH 45/53] ci: use whole line anchors in the release base counts --- .github/workflows/release.yml | 2 +- scripts/release/open-spm-pr.sh | 6 +++++- scripts/release/test-open-spm-pr.sh | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5dfe43f..66cec32 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -235,7 +235,7 @@ jobs: fi # Neutralize every '::' so no crafted Package.swift line can # forge workflow commands (leading or mid-line) in this log. - grep -E "releaseTag|checksum" Package.swift | sed 's/::/[::]/g' + grep -E "releaseTag|checksum" Package.swift | tr -d '\000-\037\177\200-\377' | sed 's/::/[::]/g' echo "XCSUM=$xcsum" >> "$GITHUB_ENV" - name: Create the GitHub release diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 04a8d2a..d6e33eb 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -148,7 +148,11 @@ origin_swift="$(git show "origin/${DEFAULT_BRANCH}:Package.swift" 2>/dev/null)" # Only real code lines constitute the pin: block comments, line # comments, and their decoy literals are all ignored. origin_code="$(strip_swift_comments "${origin_swift}")" -tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v' || true)" +# Canonical count uses the same whole-line anchor as the merge gate, +# so trailing garbage on the canonical line itself (e.g. a stray 'x' +# after the closing quote) refuses here exactly like it refuses at +# merge time. +tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" sum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" # Pin-bearing occurrence count, mirroring the merge gate: extras beside # the canonical assignment (broken prefix, releaseTagX variants) would diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 3a0fed4..59abf02 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -109,7 +109,7 @@ if [ "$1" = "pr" ] && [ "$2" = "list" ]; then fi fi if [ "$(cat "${CASE_DIR}/second_pr_list_empty" 2>/dev/null || echo 0)" = "1" ] \ - && [ "$(wc -l < "${CASE_DIR}/pr_list_calls" 2>/dev/null || echo 1)" -ge 2 ]; then + && [ "$(cat "${CASE_DIR}/head_list_calls" 2>/dev/null || echo 0)" -ge 2 ]; then # Jq-processed empty: the pre-push PR merged, no open pin PRs left. printf '' exit 0 @@ -1187,6 +1187,23 @@ else fi assert_no_mutations +# 59f. Trailing garbage on the canonical line itself (stray suffix) -> +# refuse at release time, mirroring the merge gate's whole-line anchor. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"x\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +( 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 "canonical releaseTag assignments" <<< "$(cat "${OUT}")"; then + ok "release refuses trailing garbage on the canonical line" +else + bad "release refuses trailing garbage on the canonical line" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + # 70. Supersede: build-metadata suffix on the open pin branch compares # EQUAL (metadata excluded from precedence) -> refuse like any >= # marker. From 83c812e0d837a95f0c835adad4bb498fb0fb5e1d Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 18:10:06 +0100 Subject: [PATCH 46/53] ci: exercise the guard against real deactivated states --- scripts/release/test-open-spm-pr.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 59abf02..855ac66 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -96,7 +96,6 @@ fi if [ "$1" = "pr" ] && [ "$2" = "list" ]; then # Post-push re-lookup simulation: the second list returns empty when # the knob is set (the pre-push PR merged in flight). - printf 'x\n' >> "${CASE_DIR}/pr_list_calls" 2>/dev/null || true # relookup_fails: fail ONLY the post-push re-lookup (the second # --head list), leaving the pre-flight canary green. if [ "$3" = "--head" ] || [ "$4" = "--head" ]; then @@ -1054,9 +1053,11 @@ else bad "supersede refuses a newer open pin PR" "exit ${rc}: $(cat "${OUT}")" fi -# 61. Guard over a deactivated newer-or-equal marker: refresh allowed (rewind refusal enforced upstream by open-spm-pr.sh). -set_fixtures 0 1 'let releaseTag = "wallet-bindings-v9.9.9" - checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none +# 61. Guard over a deactivated NEWER marker (v9.9.9, zeroed checksum): +# refresh allowed - the rewind refusal for this shape lives upstream in +# open-spm-pr.sh, the guard only refuses same-tag repairs. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v9.9.9"\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -1067,9 +1068,10 @@ LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated newer marker (enforced upstream)"; else bad "guard allows refresh over deactivated newer marker" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 62. Guard over a deactivated equal-version marker: refresh allowed (enforced upstream). -set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3" - checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none +# 62. Guard over a deactivated EQUAL-version marker (v1.2.3, zeroed +# checksum): same-tag repair path -> refuses on the checksum mismatch. +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -1077,12 +1079,13 @@ set_fixtures 0 1 'let releaseTag = "wallet-bindings-v1.2.3" > "${OUT}" 2>&1 ) rc=$? LOG_CONTENTS="$(cat "${LOG}")" -if [ "${rc}" = "0" ]; then ok "guard allows refresh over deactivated equal marker (enforced upstream)"; else bad "guard allows refresh over deactivated equal marker" "exit ${rc}: $(cat "${OUT}")"; fi +if [ "${rc}" = "1" ] && grep -q "do not match the pin" <<< "$(cat "${OUT}")"; then ok "guard refuses a deactivated equal-version marker"; else bad "guard refuses a deactivated equal-version marker" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations -# 63. Guard: deactivated OLDER pin -> allow (forward release). -set_fixtures 0 1 'let releaseTag = "wallet-bindings-v0.1.0" - checksum: "0000000000000000000000000000000000000000000000000000000000000000"' pr.none +# 63. Guard: deactivated OLDER pin (v0.1.0, zeroed checksum) -> allow +# (forward release). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v0.1.0"\nchecksum: "0000000000000000000000000000000000000000000000000000000000000000"\n' > "${TMP}/origin_swift" : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -1281,7 +1284,6 @@ assert_no_mutations # instead of claiming it updated a merged PR's head. set_fixtures 0 1 "${FULLY_PINNED}" pr.own printf '1' > "${TMP}/second_pr_list_empty" -rm -f "${TMP}/pr_list_calls" : > "${LOG}" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -1289,7 +1291,6 @@ rm -f "${TMP}/pr_list_calls" > "${OUT}" 2>&1 ) rc=$? printf '0' > "${TMP}/second_pr_list_empty" -rm -f "${TMP}/pr_list_calls" LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ] && grep -q "gh pr create" "${LOG}" && ! grep -q "updated its head branch" "${LOG}"; then ok "post-push empty re-lookup falls through to create" From 5fe4eb38e625bd7095cf19e6610ef058e3b8aff1 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 18:24:34 +0100 Subject: [PATCH 47/53] ci: sharpen pin diagnostics and document trigger assumptions --- .github/workflows/lint.yml | 2 ++ .github/workflows/release.yml | 6 ++-- scripts/release/guard-release-refresh.sh | 3 +- scripts/release/open-spm-pr.sh | 6 +++- scripts/release/semver.sh | 5 +++- scripts/release/test-open-spm-pr.sh | 37 +++++++++++++++++++++--- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e4b926e..4f15917 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,7 @@ name: Lint workflows and scripts +# Like ci.yml, these branch filters hardcode "main"; workflow triggers +# cannot use expressions, so a default-branch rename must update them. on: push: branches: [main] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 66cec32..ce7c058 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,10 @@ on: - "wallet-bindings-v*" # Releases are fully serialized: two tags cut near-simultaneously would -# race the pin PRs (the rewind guard runs at PR-creation time, so merge -# order would decide which pin wins). One group queues every release. +# race the pin PRs and the asset publishes (interleaved supersede +# closes and --clobber uploads from two runs could interleave). The +# merge-time pin-order gate refuses rewinds regardless, but one group +# queues every release to keep those steps from interleaving. concurrency: group: release-${{ github.repository }} cancel-in-progress: false diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 087323d..cc7f60f 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -80,7 +80,8 @@ if [ "${pin_tag}" = "${TAG}" ]; then echo "rebuilt artifacts match the merged pin; asset refresh proceeds safely" exit 0 fi - echo "::error::rebuilt artifacts (checksum $(esc "${XCSUM}")) do not match the pin merged on $(esc "${DEFAULT_BRANCH}") ($(esc "${pin_sum}")); release assets left untouched - repair manually" + pin_sum_display="${pin_sum:-}" + echo "::error::rebuilt artifacts (checksum $(esc "${XCSUM}")) do not match the pin merged on $(esc "${DEFAULT_BRANCH}") ($(esc "${pin_sum_display}")); release assets left untouched - repair manually" exit 1 fi # A pin for a DIFFERENT release is the normal forward-release state: diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index d6e33eb..961f455 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -209,7 +209,11 @@ elif [ -n "${origin_pin_tag}" ]; then # validated out-of-band, so a malformed result refuses instead of # slipping past the guard. if [ -z "${origin_pin_sum_raw}" ]; then - echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" + if printf '%s\n' "${origin_code}" | grep -qE '^checksum:'; then + echo "::error::origin/${DEFAULT_BRANCH} carries a checksum line with an empty value alongside ${origin_pin_tag}; repair manually" + else + echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" + fi exit 1 fi cmp="$(semver_cmp "${VERSION}" "${origin_version}")" diff --git a/scripts/release/semver.sh b/scripts/release/semver.sh index 889c326..bea6b32 100755 --- a/scripts/release/semver.sh +++ b/scripts/release/semver.sh @@ -26,7 +26,10 @@ semver_prerelease_cmp() { # <0 if $1 < $2, 0 equal, >0 if $1 > $2 # overflow). The caller regexes admit leading zeros, which semver # forbids; with this comparator '01' > '1' deterministically, while # the numeric-triple path treats 10#'01' == 10#'1' as equal — a - # documented deviation between the two sites, not a bug. + # documented deviation between the two sites, not a bug. The + # caller regexes also admit empty prerelease identifiers + # (1.2.3-a..b); the comparator orders the empty identifier lowest, + # deterministically - same deviation class as leading zeros. if [[ "${x}" =~ ^[0-9]+$ ]] && [[ "${y}" =~ ^[0-9]+$ ]]; then if [ "${#x}" -ne "${#y}" ]; then [ "${#x}" -lt "${#y}" ] && { echo -1; return; } diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 855ac66..691865e 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -639,10 +639,10 @@ assert_no_mutations printf '0' > "${TMP}/show_fails" reset_origin -# 42. Comment decoys inside an unterminated block comment; the real -# code pin (v1.0.0) follows the block. Correct stripping sees 1.2.3 > -# 1.0.0 and allows; a stripping regression leaks the decoys (mangled -# multi-pin state, or >= the incoming version) and refuses. +# 42. Comment decoys inside a terminated block comment; the real code +# pin (v1.0.0) follows the block. Correct stripping sees 1.2.3 > 1.0.0 +# and allows; a stripping regression leaks the decoys (mangled multi-pin +# state, or >= the incoming version) and refuses. printf '/*\nchecksum: "1111111111111111111111111111111111111111111111111111111111111111"\nlet releaseTag = "wallet-bindings-v1.2.3"\nlet releaseTag = "wallet-bindings-v9.9.9"\n*/\nlet releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/origin_swift" ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ @@ -947,6 +947,18 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" run_gate "pin-spm-checksum-v1.3.0" if [ "${rc}" = "0" ]; then ok "gate tolerates a legacy v-suffix branch name"; else bad "gate tolerates a legacy v-suffix branch name" "exit ${rc}: $(cat "${OUT}")"; fi +# A failed PR-head fetch refuses before any ordering decision. +printf '1' > "${TMP}/fetch_fails" +printf '0' > "${TMP}/head_touched" +run_gate "feature" +printf '0' > "${TMP}/fetch_fails" +printf '1' > "${TMP}/head_touched" +if [ "${rc}" = "1" ] && grep -q "cannot fetch the PR head" "${OUT}"; then + ok "gate fails closed on a failed PR-head fetch" +else + bad "gate fails closed on a failed PR-head fetch" "exit ${rc}: $(cat "${OUT}")" +fi + # A reserved-namespace branch whose suffix is not a semver -> refuse # at the derivation check. run_gate "pin-spm-checksum-oops" @@ -1190,6 +1202,23 @@ else fi assert_no_mutations +# 59g. A checksum line with an EMPTY value -> refuse with the precise +# diagnostic (an empty value is not an absent line). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: ""\n' > "${TMP}/origin_swift" +( 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 "checksum line with an empty value" <<< "$(cat "${OUT}")"; then + ok "release refuses an empty-value checksum" +else + bad "release refuses an empty-value checksum" "exit ${rc}: $(cat "${OUT}")" +fi +assert_no_mutations + # 59f. Trailing garbage on the canonical line itself (stray suffix) -> # refuse at release time, mirroring the merge gate's whole-line anchor. set_fixtures 0 1 "${FULLY_PINNED}" pr.none From 33391f15aee2dc11f62c4220949aabc9c59d539a Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 18:37:56 +0100 Subject: [PATCH 48/53] ci: anchor base checksum shapes across the release scripts --- scripts/release/guard-release-refresh.sh | 4 +++- scripts/release/open-spm-pr.sh | 3 ++- scripts/release/test-open-spm-pr.sh | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index cc7f60f..2bd4a8b 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -66,8 +66,10 @@ fi # such as '+'). pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -E '^let releaseTag = "wallet-bindings-v' | grep -oE 'wallet-bindings-v[^"]*')" +# $-anchored: trailing garbage on the checksum line is a mangled state, +# not a usable pin (same grammar as check-pin-order.sh's checksum_valid). pin_sum="$(printf '%s\n' "${origin_code}" \ - | grep -E '^checksum: "[0-9a-f]{64}"' | head -1 | grep -oE '[0-9a-f]{64}' || true)" + | grep -E '^checksum: "[0-9a-f]{64}"$' | head -1 | grep -oE '[0-9a-f]{64}' || true)" # A mangled releaseTag (e.g. bare 'wallet-bindings-v' with no version) # must fail closed: clobbering assets on a main with a broken pin would # desync SPM resolution exactly like a checksum mismatch would. diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 961f455..cc4dab8 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -168,8 +168,9 @@ fi # must refuse here exactly like it refuses at merge time. origin_pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" +# $-anchored hex shape, consistent with the guard and the merge gate. origin_pin_sum_raw="$(printf '%s\n' "${origin_code}" \ - | grep -E '^checksum: "' | head -1 | grep -oE '"[^"]*"' | tr -d '"' || true)" + | grep -E '^checksum: "[0-9a-f]{64}"$' | head -1 | grep -oE '[0-9a-f]{64}' || true)" origin_pin_sum="$(printf '%s\n' "${origin_pin_sum_raw}" \ | grep -oE '^[0-9a-f]{64}$' || true)" origin_pin_active=0 diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 691865e..e83d54c 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1107,6 +1107,23 @@ rc=$? LOG_CONTENTS="$(cat "${LOG}")" if [ "${rc}" = "0" ]; then ok "guard allows deactivated older pin"; else bad "guard allows deactivated older pin" "exit ${rc}"; fi +# 63b. Guard: trailing garbage on the base checksum line -> the hex +# extraction refuses it as mangled (same-tag refresh cannot succeed +# against a corrupted pin). +set_fixtures 0 1 "${FULLY_PINNED}" pr.none +printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"x\n' > "${TMP}/origin_swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" GITHUB_REPOSITORY="mintlayer/rust-sdk" CASE_DIR="${TMP}" \ + bash "${SCRIPT_DIR}/guard-release-refresh.sh" wallet-bindings-v1.2.3 "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654" main \ + > "${OUT}" 2>&1 ) +rc=$? +LOG_CONTENTS="$(cat "${LOG}")" +if [ "${rc}" = "1" ] && grep -q "do not match the pin" <<< "$(cat "${OUT}")"; then + ok "guard refuses trailing garbage on the base checksum" +else + bad "guard refuses trailing garbage on the base checksum" "exit ${rc}: $(cat "${OUT}")" +fi + # 64. Guard: unparseable origin pin tag (no version) -> fail closed. set_fixtures 0 1 "${FULLY_PINNED}" pr.none printf 'let releaseTag = "wallet-bindings-v"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" @@ -1377,7 +1394,10 @@ if [ "$(semver_cmp_check "1.2.3" "1.2.3-rc.1")" = "1" ] \ && [ "$(semver_cmp_check "1.2.3+meta.a" "1.2.3+meta.b")" = "0" ] \ && [ "$(semver_cmp_check "1.2.3" "1.2.3+meta")" = "0" ] \ && [ "$(semver_cmp_check "1.2.3-2" "1.2.3-18446744073709551617")" = "-1" ] \ - && [ "$(semver_cmp_check "1.02.3" "1.2.3")" = "0" ]; then + && [ "$(semver_cmp_check "1.02.3" "1.2.3")" = "0" ] \ + && [ "$(semver_cmp_check "1.2.3-a..b" "1.2.3-a.b")" = "-1" ] \ + && [ "$(semver_cmp_check "1.2.3-a.b" "1.2.3-a..b")" = "1" ] \ + && [ "$(semver_cmp_check "1.2.3-a." "1.2.3-a.b")" = "-1" ]; then ok "semver comparator unit checks" else bad "semver comparator unit checks" "unexpected comparator output" From fa68175de6fb01fef2af94ba1571be09f676a0b8 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 18:48:26 +0100 Subject: [PATCH 49/53] ci: triage mangled base checksums at the counts guard --- scripts/release/open-spm-pr.sh | 43 ++++++++++++----------------- scripts/release/test-open-spm-pr.sh | 5 ++-- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index cc4dab8..95877a6 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -153,14 +153,21 @@ origin_code="$(strip_swift_comments "${origin_swift}")" # after the closing quote) refuses here exactly like it refuses at # merge time. tag_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" -sum_assignments="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "' || true)" +sum_wellformed="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum: "[0-9a-f]{64}"$' || true)" +checksum_any="$(printf '%s\n' "${origin_code}" | grep -cE '^checksum:' || true)" # Pin-bearing occurrence count, mirroring the merge gate: extras beside # the canonical assignment (broken prefix, releaseTagX variants) would # open a pin PR the gate is guaranteed to reject. The download-URL line # never contains the substring 'let releaseTag'. tag_bearing="$(printf '%s\n' "${origin_code}" | { grep -o 'let releaseTag' || true; } | wc -l | tr -d ' ')" -if [ "${tag_assignments}" != "1" ] || [ "${sum_assignments}" != "1" ] || [ "${tag_bearing}" != "1" ]; then - echo "::error::origin/${DEFAULT_BRANCH} carries ${tag_assignments} canonical releaseTag assignments, ${tag_bearing} pin-bearing line(s) and ${sum_assignments} checksum assignments; expected exactly one canonical of each" +if [ "${tag_assignments}" != "1" ] || [ "${sum_wellformed}" != "1" ] || [ "${checksum_any}" != "1" ] || [ "${tag_bearing}" != "1" ]; then + if [ "${checksum_any}" = "0" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line" + elif [ "${sum_wellformed}" = "0" ]; then + echo "::error::origin/${DEFAULT_BRANCH} carries a mangled or empty checksum value; repair manually" + else + echo "::error::origin/${DEFAULT_BRANCH} carries ${tag_assignments} canonical releaseTag assignments, ${tag_bearing} pin-bearing line(s) and ${sum_wellformed} checksum assignments; expected exactly one canonical of each" + fi exit 1 fi # Same extraction/validation the merge gate uses: the whole tag token, @@ -168,11 +175,10 @@ fi # must refuse here exactly like it refuses at merge time. origin_pin_tag="$(printf '%s\n' "${origin_code}" \ | grep -E '^let releaseTag = ' | grep -oE 'wallet-bindings-v[^"]*')" -# $-anchored hex shape, consistent with the guard and the merge gate. -origin_pin_sum_raw="$(printf '%s\n' "${origin_code}" \ - | grep -E '^checksum: "[0-9a-f]{64}"$' | head -1 | grep -oE '[0-9a-f]{64}' || true)" -origin_pin_sum="$(printf '%s\n' "${origin_pin_sum_raw}" \ - | grep -oE '^[0-9a-f]{64}$' || true)" +# The counts guard above guarantees exactly one well-formed ($-anchored +# 64-hex) checksum line, so its value extracts unconditionally here. +origin_pin_sum="$(printf '%s\n' "${origin_code}" \ + | grep -E '^checksum: "[0-9a-f]{64}"$' | head -1 | grep -oE '[0-9a-f]{64}')" origin_pin_active=0 origin_version="" if [ -n "${origin_pin_sum}" ] && [ "${origin_pin_sum}" != "0000000000000000000000000000000000000000000000000000000000000000" ]; then @@ -199,24 +205,11 @@ if [ "${origin_pin_active}" = "1" ]; then echo "::error::origin/${DEFAULT_BRANCH} already pins $(esc "${origin_pin_tag}") (>= ${VERSION}); refusing to rewind the pin" exit 1 fi -elif [ -n "${origin_pin_sum_raw}" ] && [ -z "${origin_pin_sum}" ]; then - # A checksum line exists but is not 64 lowercase hex: mangled pin. - echo "::error::origin/${DEFAULT_BRANCH} carries a mangled checksum line: $(esc "${origin_pin_sum_raw}")" - exit 1 elif [ -n "${origin_pin_tag}" ]; then - # Not active, not checksum-mangled: either a deactivated - # (zeroed-checksum) pin or a tag line without any checksum line. - # Both refuse; the deactivated path orders with the comparator - # validated out-of-band, so a malformed result refuses instead of - # slipping past the guard. - if [ -z "${origin_pin_sum_raw}" ]; then - if printf '%s\n' "${origin_code}" | grep -qE '^checksum:'; then - echo "::error::origin/${DEFAULT_BRANCH} carries a checksum line with an empty value alongside ${origin_pin_tag}; repair manually" - else - echo "::error::origin/${DEFAULT_BRANCH} carries a releaseTag without a checksum line: $(esc "${origin_pin_tag}")" - fi - exit 1 - fi + # Not active and the counts guard verified exactly one well-formed + # checksum line: this is a deactivated (zeroed-checksum) pin. Ordering + # uses the comparator validated out-of-band, so a malformed result + # refuses instead of slipping past the guard. cmp="$(semver_cmp "${VERSION}" "${origin_version}")" if [[ ! "${cmp}" =~ ^-?[012]$ ]]; then echo "::error::semver comparison failed for ${VERSION} against ${origin_version}" diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index e83d54c..102d9f9 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1180,7 +1180,8 @@ LOG_CONTENTS="$(cat "${LOG}")" # The upstream counts guard refuses this shape first (1 tag, 0 # checksums); the inner tag-without-checksum branch below it is # unreachable for this fixture and stays as defense in depth. -if [ "${rc}" = "1" ] && grep -q "0 checksum assignments" <<< "$(cat "${OUT}")"; then ok "tag-without-checksum origin refused"; else bad "tag-without-checksum origin refused" "exit ${rc}: $(cat "${OUT}")"; fi +# The triaged counts guard now names the missing-checksum-line shape. +if [ "${rc}" = "1" ] && grep -q "without a checksum line" <<< "$(cat "${OUT}")"; then ok "tag-without-checksum origin refused"; else bad "tag-without-checksum origin refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations # 68. A hand-mangled base tag (wallet-bindings-vv1.2.3) must refuse @@ -1229,7 +1230,7 @@ printf 'let releaseTag = "wallet-bindings-v1.2.3"\nchecksum: ""\n' > "${TMP}/ori > "${OUT}" 2>&1 ) rc=$? LOG_CONTENTS="$(cat "${LOG}")" -if [ "${rc}" = "1" ] && grep -q "checksum line with an empty value" <<< "$(cat "${OUT}")"; then +if [ "${rc}" = "1" ] && grep -q "mangled or empty checksum value" <<< "$(cat "${OUT}")"; then ok "release refuses an empty-value checksum" else bad "release refuses an empty-value checksum" "exit ${rc}: $(cat "${OUT}")" From f4839296cfd27ed40d7aaf2dbfe21ebf5798be2c Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 18:56:47 +0100 Subject: [PATCH 50/53] ci: one canonical branch input validation for release scripts --- scripts/release/check-pin-order.sh | 6 +----- scripts/release/guard-release-refresh.sh | 6 +----- scripts/release/open-spm-pr.sh | 5 +---- scripts/release/pin-order-gate.sh | 6 +----- scripts/release/pinlib.sh | 15 +++++++++++++++ scripts/release/test-open-spm-pr.sh | 5 ++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 218e54c..147cea7 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -31,11 +31,7 @@ source "${BASH_SOURCE[0]%/*}/semver.sh" BASE_BRANCH="${1:?base branch required}" EXPECTED_TAG="${2-}" INCOMING_REF="${3:-}" -if [[ ! "${BASE_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ - || [[ "${BASE_BRANCH}" == pin-spm-checksum-* ]]; then - echo "::error::unexpected base branch: $(esc "${BASE_BRANCH}")" - exit 1 -fi +validate_branch_input "${BASE_BRANCH}" "base branch" if [ -n "${EXPECTED_TAG}" ] && [[ ! "${EXPECTED_TAG}" =~ ^wallet-bindings-v[0-9]{1,18}\.[0-9]{1,18}\.[0-9]{1,18}([-+][0-9A-Za-z.-]+)?$ ]]; then echo "::error::unexpected expected tag: $(esc "${EXPECTED_TAG}")" exit 1 diff --git a/scripts/release/guard-release-refresh.sh b/scripts/release/guard-release-refresh.sh index 2bd4a8b..bfb5afd 100755 --- a/scripts/release/guard-release-refresh.sh +++ b/scripts/release/guard-release-refresh.sh @@ -28,11 +28,7 @@ if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]] || [ "${XCSUM//0/}" = "" ]; then echo "::error::checksum is not 64 lowercase hex characters (all-zero refused)" exit 1 fi -if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ - || [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then - echo "::error::unexpected default branch: $(esc "${DEFAULT_BRANCH}")" - exit 1 -fi +validate_branch_input "${DEFAULT_BRANCH}" "default branch" # Refresh origin/ so the pin state reflects main as of now, # not the checkout snapshot: a pin PR merged while this release run is diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index 95877a6..ac6c414 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -50,10 +50,7 @@ if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]] || [ "${XCSUM//0/}" = "" ]; then echo "::error::checksum is not 64 lowercase hex characters (all-zero refused)" exit 1 fi -if [[ ! "${DEFAULT_BRANCH}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then - echo "::error::unexpected default branch format: $(esc "${DEFAULT_BRANCH}")" - exit 1 -fi +validate_branch_input "${DEFAULT_BRANCH}" "default branch" # The default branch must never live in the reserved bot namespace: a # force-push there would rewind main instead of a disposable branch. if [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then diff --git a/scripts/release/pin-order-gate.sh b/scripts/release/pin-order-gate.sh index 64f9e92..609dfdd 100755 --- a/scripts/release/pin-order-gate.sh +++ b/scripts/release/pin-order-gate.sh @@ -32,11 +32,7 @@ HEAD_REF="${HEAD_REF:?head ref required}" EVENT_NAME="${EVENT_NAME:-}" PR_NUMBER="${PR_NUMBER:-}" -if [[ ! "${BASE_REF}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]] \ - || [[ "${BASE_REF}" == pin-spm-checksum-* ]]; then - echo "::error::unexpected base branch: $(esc "${BASE_REF}")" - exit 1 -fi +validate_branch_input "${BASE_REF}" "base branch" # The checkout is the base branch; pull the PR head commit so the diff # and the data-only read of the head's Package.swift can see it (push diff --git a/scripts/release/pinlib.sh b/scripts/release/pinlib.sh index ba6ec19..ca19bf6 100755 --- a/scripts/release/pinlib.sh +++ b/scripts/release/pinlib.sh @@ -41,3 +41,18 @@ count_pin_lines() { # '{ if ($0 == t) a++; if ($0 == s) b++; if ($0 ~ /^checksum: "/) c++ } \ END { printf "%d %d %d\n", a+0, b+0, c+0 }' } + +# Validate a branch-name input (charset regex plus refusal of the +# reserved pin-spm-checksum-* namespace). One canonical diagnostic for +# every release script; exits 1 so callers need no error handling. +validate_branch_input() { # + local value="$1" role="$2" + if [[ ! "${value}" =~ ^[A-Za-z0-9][A-Za-z0-9._/-]*$ ]]; then + echo "::error::unexpected ${role} format: $(esc "${value}")" + exit 1 + fi + if [[ "${value}" == pin-spm-checksum-* ]]; then + echo "::error::the ${role} must not use the reserved pin-spm-checksum-* namespace: $(esc "${value}")" + exit 1 + fi +} diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 102d9f9..5cd291b 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -1177,9 +1177,8 @@ printf 'let releaseTag = "wallet-bindings-v9.9.9"\n' > "${TMP}/origin_swift" > "${OUT}" 2>&1 ) rc=$? LOG_CONTENTS="$(cat "${LOG}")" -# The upstream counts guard refuses this shape first (1 tag, 0 -# checksums); the inner tag-without-checksum branch below it is -# unreachable for this fixture and stays as defense in depth. +# The triaged counts guard refuses this shape and names it: one tag +# line, zero checksum lines. # The triaged counts guard now names the missing-checksum-line shape. if [ "${rc}" = "1" ] && grep -q "without a checksum line" <<< "$(cat "${OUT}")"; then ok "tag-without-checksum origin refused"; else bad "tag-without-checksum origin refused" "exit ${rc}: $(cat "${OUT}")"; fi assert_no_mutations From 104a96d608f02344f8b141eeb8d8ce3d61afa96a Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 19:04:49 +0100 Subject: [PATCH 51/53] ci: cover the gate base version validation --- scripts/release/check-pin-order.sh | 3 ++- scripts/release/open-spm-pr.sh | 6 ------ scripts/release/test-open-spm-pr.sh | 10 ++++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/release/check-pin-order.sh b/scripts/release/check-pin-order.sh index 147cea7..13d93d7 100755 --- a/scripts/release/check-pin-order.sh +++ b/scripts/release/check-pin-order.sh @@ -107,7 +107,8 @@ fi # substring 'let releaseTag' is safe because the download-URL line # never contains it (its \(releaseTag) interpolation is Swift string # interpolation inside a string literal and survives stripping; the -# line reads 'let releaseBaseUrl = ...'). +# assignment reads 'let releaseBaseUrl = ...' with the URL string +# following on the next line). current_bearing="$(printf '%s\n' "${origin_code}" | { grep -o 'let releaseTag' || true; } | wc -l | tr -d ' ')" current_matches="$(printf '%s\n' "${origin_code}" \ | grep -cE '^let releaseTag = "wallet-bindings-v[^"]*"$' || true)" diff --git a/scripts/release/open-spm-pr.sh b/scripts/release/open-spm-pr.sh index ac6c414..daac183 100755 --- a/scripts/release/open-spm-pr.sh +++ b/scripts/release/open-spm-pr.sh @@ -51,12 +51,6 @@ if [[ ! "${XCSUM}" =~ ^[0-9a-f]{64}$ ]] || [ "${XCSUM//0/}" = "" ]; then exit 1 fi validate_branch_input "${DEFAULT_BRANCH}" "default branch" -# The default branch must never live in the reserved bot namespace: a -# force-push there would rewind main instead of a disposable branch. -if [[ "${DEFAULT_BRANCH}" == pin-spm-checksum-* ]]; then - echo "::error::default branch must not use the reserved pin-spm-checksum-* namespace" - exit 1 -fi if [ -z "${GITHUB_REPOSITORY:-}" ]; then echo "::error::GITHUB_REPOSITORY is not set" exit 1 diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 5cd291b..20ea3c4 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -800,6 +800,16 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" rc=$? if [ "${rc}" = "1" ] && grep -q "carries no code lines" <<< "$(cat "${OUT}")"; then ok "pin order refuses a comment-only base"; else bad "pin order refuses a comment-only base" "exit ${rc}: $(cat "${OUT}")"; fi +# A base tag with an unparseable version token (empty version after the +# wallet-bindings-v prefix) -> refuse, mirroring the sibling scripts. +printf 'let releaseTag = "wallet-bindings-v"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" +printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${STUBS}/repo/Package.swift" +( cd "${STUBS}/repo" && \ + PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ + bash "${ORDER}" main "" > "${OUT}" 2>&1 ) +rc=$? +if [ "${rc}" = "1" ] && grep -q "unparseable current pin version" <<< "$(cat "${OUT}")"; then ok "pin order refuses an unparseable current pin version"; else bad "pin order refuses an unparseable current pin version" "exit ${rc}: $(cat "${OUT}")"; fi + # Broken-prefix variant: a double space before '=' breaks the anchored # prefix itself — detection must not be prefix-anchored. printf 'let releaseTag = "wallet-bindings-v1.0.0"\nchecksum: "cad323bf1d59c87ba0c252952933ea467f72afc0eda8e17845da4fe78d7b0654"\n' > "${TMP}/origin_swift" From 33a2670150abee3f69b94d7f92d1cc14f9d47ca7 Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sat, 14 Nov 2026 19:13:33 +0100 Subject: [PATCH 52/53] ci: check pin diff applicability without a pipe --- scripts/release/pin-order-gate.sh | 11 ++++++++--- scripts/release/test-open-spm-pr.sh | 18 ++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/release/pin-order-gate.sh b/scripts/release/pin-order-gate.sh index 609dfdd..fb5223d 100755 --- a/scripts/release/pin-order-gate.sh +++ b/scripts/release/pin-order-gate.sh @@ -45,12 +45,17 @@ fi # Fail closed on diff errors: an unreadable head (e.g. a force-push # landing between event emission and the fetch) must not masquerade as -# "Package.swift untouched". -if ! head_files="$(git diff --name-only "origin/${BASE_REF}...${HEAD_SHA}")"; then +# "Package.swift untouched". Path-limited --quiet produces no output, +# so the check cannot false-negative on a huge changed-file list (a +# 'grep -q' consumer would SIGPIPE the producer and, under pipefail, +# invert the verdict). +diff_rc=0 +git diff --quiet "origin/${BASE_REF}...${HEAD_SHA}" -- Package.swift || diff_rc=$? +if [ "${diff_rc}" -gt 1 ]; then echo "::error::cannot diff the incoming pin against origin/${BASE_REF}" exit 1 fi -if ! printf '%s\n' "${head_files}" | grep -q '^Package.swift$'; then +if [ "${diff_rc}" = "0" ]; then echo "Package.swift untouched; nothing to check" exit 0 fi diff --git a/scripts/release/test-open-spm-pr.sh b/scripts/release/test-open-spm-pr.sh index 20ea3c4..64c4c58 100755 --- a/scripts/release/test-open-spm-pr.sh +++ b/scripts/release/test-open-spm-pr.sh @@ -64,9 +64,7 @@ case "$1 $2" in "fetch origin" | "fetch --unshallow" | "fetch --no-tags") [ "$(cat "${CASE_DIR}/fetch_fails" 2>/dev/null || echo 0)" = "1" ] && exit 1 exit 0 ;; - "diff --name-only") - [ "$(cat "${CASE_DIR}/head_touched" 2>/dev/null || echo 0)" = "1" ] && echo "Package.swift" - exit 0 ;; + "rev-parse HEAD") cat "${CASE_DIR}/head_commit" ;; "show origin/"*) if [ "$(cat "${CASE_DIR}/show_fails" 2>/dev/null || echo 0)" = "1" ]; then @@ -862,7 +860,7 @@ printf 'SHA256SUMS for the release\n%s MintlayerWalletBindings.xcframework.zip\ printf '0' > "${TMP}/release_download_fails" # Untouched Package.swift -> skip without reading anything. -printf '0' > "${TMP}/head_touched" +printf '0' > "${TMP}/default_diff" run_gate() { ( cd "${STUBS}/repo" && \ PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \ @@ -889,7 +887,7 @@ else fi # Touched + forward pin bound to the published sums -> allow. -printf '1' > "${TMP}/head_touched" +printf '1' > "${TMP}/default_diff" printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" run_gate "feature" if [ "${rc}" = "0" ]; then ok "gate allows a bound forward pin"; else bad "gate allows a bound forward pin" "exit ${rc}: $(cat "${OUT}")"; fi @@ -925,18 +923,18 @@ fi # Push event: same binding and ordering without the PR-head fetch. printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" -printf '1' > "${TMP}/head_touched" +printf '1' > "${TMP}/default_diff" run_gate_push "feature" if [ "${rc}" = "0" ]; then ok "gate push event allows a bound forward pin"; else bad "gate push event allows a bound forward pin" "exit ${rc}: $(cat "${OUT}")"; fi -printf '0' > "${TMP}/head_touched" +printf '0' > "${TMP}/default_diff" run_gate_push "feature" if [ "${rc}" = "0" ] && grep -q "untouched" "${OUT}"; then ok "gate push event skips an untouched Package.swift" else bad "gate push event skips an untouched Package.swift" "exit ${rc}: $(cat "${OUT}")" fi -printf '1' > "${TMP}/head_touched" +printf '1' > "${TMP}/default_diff" # Reserved namespace: strict tag equality against the branch name. printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift" @@ -959,10 +957,10 @@ if [ "${rc}" = "0" ]; then ok "gate tolerates a legacy v-suffix branch name"; el # A failed PR-head fetch refuses before any ordering decision. printf '1' > "${TMP}/fetch_fails" -printf '0' > "${TMP}/head_touched" +printf '0' > "${TMP}/default_diff" run_gate "feature" printf '0' > "${TMP}/fetch_fails" -printf '1' > "${TMP}/head_touched" +printf '1' > "${TMP}/default_diff" if [ "${rc}" = "1" ] && grep -q "cannot fetch the PR head" "${OUT}"; then ok "gate fails closed on a failed PR-head fetch" else From bfc3a3abd91de5ced56cf5a373736f5086d9107f Mon Sep 17 00:00:00 2001 From: nullPointerEnjoyer Date: Sun, 15 Nov 2026 01:28:12 +0100 Subject: [PATCH 53/53] ci: skip the pin gate on its own bootstrap pr --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cd48e5..4a53357 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,16 @@ jobs: # stub harness covers it); reserved-namespace heads get # strict tag equality, every other Package.swift edit gets # ordering-only enforcement. + # + # Bootstrap: the script ships with the PR that introduces the + # gate, so the trusted-base checkout cannot contain it until + # that PR lands. Absence on the base is impossible post-merge + # (deleting the script from main would itself be a reviewed + # change), so this branch only ever fires for the bootstrap. + if [ ! -f scripts/release/pin-order-gate.sh ]; then + echo "::warning::pin-order gate not present on the base branch (bootstrap PR); enforcement begins once the gate PR merges" + exit 0 + fi scripts/release/pin-order-gate.sh fmt: