Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import PackageDescription

let releaseTag = "wallet-bindings-v0.1.0"
let releaseTag = "wallet-bindings-v0.1.1"
let releaseBaseUrl =
"https://github.com/mintlayer/rust-sdk/releases/download/\(releaseTag)"

Expand All @@ -34,7 +34,7 @@ let package = Package(
name: "MintlayerWalletBindingsFFI",
url: "\(releaseBaseUrl)/MintlayerWalletBindings.xcframework.zip",
// Replaced by the release workflow when the artifact is attached.
checksum: "aaf7197f472c01483e1d4e9f7f222df1c046c12430820ef371f83f832f4d6b97"
checksum: "9049519c11ac14058420ce04cd1f5ce7b3f58cb0502e57013e88a21b0abd0f06"
),
// The generated Swift wrapper ships as source (standard UniFFI
// practice); the FFI static library inside the XCFramework is what
Expand Down
18 changes: 14 additions & 4 deletions scripts/release/pin-order-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# 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.
# EVENT_NAME, PR_NUMBER, GITHUB_REPOSITORY, GH_TOKEN. LC_ALL=C is
# enforced internally.
set -euo pipefail
export LC_ALL=C

Expand All @@ -29,6 +30,7 @@ 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}"
GITHUB_REPOSITORY="${GITHUB_REPOSITORY:?GitHub repository required}"
EVENT_NAME="${EVENT_NAME:-}"
PR_NUMBER="${PR_NUMBER:-}"

Expand Down Expand Up @@ -94,9 +96,17 @@ if [ "$(printf '%s\n' "${head_norm}" | grep -cE '^let releaseTag = ' || true)" !
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; }
# missing or unreadable manifest. Fetched via gh api: runner gh builds
# reject the --pattern/--output flags of `gh release download`.
asset_url="$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${head_tag}" \
--jq '.assets[] | select(.name == "SHA256SUMS") | .url' 2>/dev/null)" \
|| asset_url=""
Comment on lines +101 to +103

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug · medium
The --jq filter '.assets[] | select(.name == "SHA256SUMS") | .url' emits one line per matching asset. If the release ever carries more than one SHA256SUMS asset, asset_url will be multi-line and the subsequent gh api ... "${asset_url}" receives a malformed multi-line URL argument, failing closed with the misleading "unreadable SHA256SUMS" diagnostic. Limit to a single match (e.g. 'first(...[]) | .name == "SHA256SUMS" | .url' or pipe through head -n1) and/or add an explicit multi-match guard.

Suggestion:

Suggested change
asset_url="$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${head_tag}" \
--jq '.assets[] | select(.name == "SHA256SUMS") | .url' 2>/dev/null)" \
|| asset_url=""
asset_url="$(gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${head_tag}" \
--jq 'first(.assets[] | select(.name == "SHA256SUMS") | .url)' 2>/dev/null)" \
|| asset_url=""

if [ -z "${asset_url}" ]; then
echo "::error::release $(esc "${head_tag}") is missing or carries no readable SHA256SUMS; refusing an unverifiable pin"
exit 1
fi
sums="$(gh api -H "Accept: application/octet-stream" "${asset_url}" 2>/dev/null)" \
|| { echo "::error::release $(esc "${head_tag}") carries an unreadable 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}")"
Expand Down
51 changes: 43 additions & 8 deletions scripts/release/test-open-spm-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,21 @@ 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"
if [ "$1" = "api" ]; then
# Two-stage fetch: metadata (asset list) then the sums body. Each
# stage has its own fail knob value so both closed paths are covered.
api_fails="$(cat "${CASE_DIR}/release_api_fails" 2>/dev/null || echo 0)"
if [ "$2" = "-H" ]; then
[ "${api_fails}" = "2" ] && exit 1
cat "${CASE_DIR}/release_sums"
exit 0
fi
[ "${api_fails}" = "1" ] && exit 1
# Simulate the gate's --jq: emit the asset URL only when the canned
# release metadata actually carries the sums asset.
if grep -q '"name":"SHA256SUMS"' "${CASE_DIR}/release_assets_json"; then
printf 'https://api.github.com/repos/mintlayer/rust-sdk/releases/assets/1\n'
fi
exit 0
fi
if [ "$1" = "pr" ] && [ "$2" = "list" ]; then
Expand Down Expand Up @@ -857,13 +869,14 @@ printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}"
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"
printf '[{"name":"SHA256SUMS","url":"https://api.github.com/repos/mintlayer/rust-sdk/releases/assets/1"}]' > "${TMP}/release_assets_json"
printf '0' > "${TMP}/release_api_fails"

# Untouched Package.swift -> skip without reading anything.
printf '0' > "${TMP}/default_diff"
run_gate() {
( cd "${STUBS}/repo" && \
PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \
PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" GITHUB_REPOSITORY="mintlayer/rust-sdk" \
BASE_REF="main" HEAD_SHA="0123456789abcdef0123456789abcdef01234567" \
HEAD_REF="$1" EVENT_NAME="pull_request" PR_NUMBER="7" \
bash "${GATE}" > "${OUT}" 2>&1 )
Expand All @@ -873,7 +886,7 @@ run_gate() {
# already local.
run_gate_push() {
( cd "${STUBS}/repo" && \
PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" \
PATH="${STUBS}:${PATH}" CASE_DIR="${TMP}" GITHUB_REPOSITORY="mintlayer/rust-sdk" \
BASE_REF="main" HEAD_SHA="0123456789abcdef0123456789abcdef01234567" \
HEAD_REF="$1" EVENT_NAME="push" PR_NUMBER="" \
bash "${GATE}" > "${OUT}" 2>&1 )
Expand Down Expand Up @@ -903,15 +916,37 @@ 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"
printf '1' > "${TMP}/release_api_fails"
run_gate "feature"
printf '0' > "${TMP}/release_download_fails"
printf '0' > "${TMP}/release_api_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

# Metadata ok but no SHA256SUMS asset on the release -> fail closed.
printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift"
printf '[{"name":"OTHER.txt","url":"https://api.github.com/repos/mintlayer/rust-sdk/releases/assets/2"}]' > "${TMP}/release_assets_json"
run_gate "feature"
printf '[{"name":"SHA256SUMS","url":"https://api.github.com/repos/mintlayer/rust-sdk/releases/assets/1"}]' > "${TMP}/release_assets_json"
if [ "${rc}" = "1" ] && grep -q "missing or carries no readable SHA256SUMS" "${OUT}"; then
ok "gate fails closed on a release without the sums asset"
else
bad "gate fails closed on a release without the sums asset" "exit ${rc}: $(cat "${OUT}")"
fi

# Sums fetch fails after a good metadata call -> fail closed.
printf 'let releaseTag = "wallet-bindings-v1.3.0"\nchecksum: "%s"\n' "${XCSUM}" > "${TMP}/incoming_swift"
printf '2' > "${TMP}/release_api_fails"
run_gate "feature"
printf '0' > "${TMP}/release_api_fails"
if [ "${rc}" = "1" ] && grep -q "carries an unreadable SHA256SUMS" "${OUT}"; then
ok "gate fails closed on an unreadable sums fetch"
else
bad "gate fails closed on an unreadable sums fetch" "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"
Expand Down
Loading