mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 00:45:17 -05:00
fix(release): attach missing standalone binaries to an existing release (#9696)
2.4.0 and 2.5.0 shipped no standalone binaries, and nothing could add them afterwards: re-running a release uses the tag's own workflow and pushes the images again. Run by hand from main with a tag, release.yml now builds the binaries that release lacks, or the ones named, from the tag's source, and attaches them signed and attested as a tag run does. It first verifies the release's sha256sums.txt against its cosign bundle and the attached binaries against that file, then rewrites it to cover every binary. A backfill never pushes or signs images and never creates a release; tag runs build and publish as before. Refs #8715
This commit is contained in:
1 parent
3e1f9457ab
commit
82c82ec553
7 files changed
+509
-28
No files matched your search
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Downloads into <dir> the standalone binaries a release already carries, and its sha256sums.txt,
|
||||
# for release-binaries-sums.sh to check and extend.
|
||||
#
|
||||
# release-binaries-existing.sh <tag> <dir>
|
||||
#
|
||||
# The names come from the release's asset list, and each one is downloaded by its exact name, so
|
||||
# a release with nothing attached downloads nothing, while a download that fails stops the
|
||||
# backfill: carrying on with a partial <dir> would rewrite sha256sums.txt without the lines of the
|
||||
# binaries it missed. Of the cosign bundles only sha256sums.txt's is kept, which
|
||||
# release-binaries-sums.sh verifies before trusting the file; the backfill signs what it publishes.
|
||||
set -euo pipefail
|
||||
|
||||
TAG=${1:?usage: release-binaries-existing.sh <tag> <dir>}
|
||||
DIR=${2:?usage: release-binaries-existing.sh <tag> <dir>}
|
||||
mkdir -p "$DIR"
|
||||
|
||||
names=$(gh release view "$TAG" --json assets --jq '.assets[].name')
|
||||
while IFS= read -r name; do
|
||||
case "$name" in
|
||||
sha256sums.txt|sha256sums.txt.sigstore.json) gh release download "$TAG" -D "$DIR" -p "$name" ;;
|
||||
*.sigstore.json) continue ;;
|
||||
floci-aws-*) gh release download "$TAG" -D "$DIR" -p "$name" ;;
|
||||
esac
|
||||
done <<< "$names"
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
# Decides which standalone binaries a Release run builds and publishes.
|
||||
#
|
||||
# EVENT=push release-binaries-plan.sh # a tag push: everything
|
||||
# EVENT=workflow_dispatch TAG=2.5.0 PLATFORMS=missing [REPLACE=false] [REF=refs/heads/main] \
|
||||
# GH_REPO=floci-io/floci release-binaries-plan.sh # a backfill
|
||||
#
|
||||
# PLATFORMS is `missing` (the binaries the release does not have yet), `all`, or a comma list of
|
||||
# linux-amd64, linux-arm64, linux-arm64-baseline, darwin-amd64, windows-amd64. A named platform the
|
||||
# release already carries is refused unless REPLACE=true; `missing` never replaces anything.
|
||||
#
|
||||
# Writes key=value lines to $GITHUB_OUTPUT (stdout when unset, so it doubles as a dry run):
|
||||
# linux_amd64, linux_arm64, linux_arm64_baseline, darwin_amd64, windows_amd64 true|false
|
||||
# standalone comma list of the selected macOS/Windows platforms, for standalone-binaries.yml
|
||||
# any true when at least one binary is selected
|
||||
# Exits non-zero, building nothing, when the request is invalid.
|
||||
set -euo pipefail
|
||||
|
||||
ALL=(linux-amd64 linux-arm64 linux-arm64-baseline darwin-amd64 windows-amd64)
|
||||
OUT=${GITHUB_OUTPUT:-/dev/stdout}
|
||||
SUMMARY=${GITHUB_STEP_SUMMARY:-/dev/null}
|
||||
|
||||
asset_name() {
|
||||
case "$1" in
|
||||
windows-amd64) echo "floci-aws-windows-amd64.exe" ;;
|
||||
*) echo "floci-aws-$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
fail() {
|
||||
echo "::error::$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
emit() {
|
||||
local selected=" $* " standalone="" any=false
|
||||
for p in "${ALL[@]}"; do
|
||||
if [[ $selected == *" $p "* ]]; then
|
||||
echo "${p//-/_}=true" >> "$OUT"
|
||||
any=true
|
||||
case "$p" in
|
||||
darwin-*|windows-*) standalone="${standalone:+$standalone,}$p" ;;
|
||||
esac
|
||||
else
|
||||
echo "${p//-/_}=false" >> "$OUT"
|
||||
fi
|
||||
done
|
||||
echo "standalone=$standalone" >> "$OUT"
|
||||
echo "any=$any" >> "$OUT"
|
||||
}
|
||||
|
||||
if [ "${EVENT:?EVENT is required}" = push ]; then
|
||||
emit "${ALL[@]}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TAG=${TAG:?TAG is required for a backfill}
|
||||
PLATFORMS=${PLATFORMS:-missing}
|
||||
REPLACE=${REPLACE:-false}
|
||||
|
||||
[[ $TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || fail "tag '$TAG' is not a release version (x.y.z)"
|
||||
# The release identity docs/getting-started/installation.md verifies is release.yml at any ref, so
|
||||
# only main's copy of this workflow may sign a backfill.
|
||||
if [ -n "${REF:-}" ] && [ "$REF" != refs/heads/main ]; then
|
||||
fail "a backfill runs from main only, not $REF"
|
||||
fi
|
||||
|
||||
command -v gh > /dev/null || fail "gh is not installed"
|
||||
attached=$(gh release view "$TAG" --json assets -q '.assets[].name') \
|
||||
|| fail "could not read release $TAG (does it exist?); a backfill never creates a release (semantic-release does)"
|
||||
|
||||
is_attached() {
|
||||
grep -qxF "$(asset_name "$1")" <<< "$attached"
|
||||
}
|
||||
|
||||
selected=()
|
||||
case "$PLATFORMS" in
|
||||
missing)
|
||||
for p in "${ALL[@]}"; do
|
||||
is_attached "$p" || selected+=("$p")
|
||||
done
|
||||
;;
|
||||
all)
|
||||
selected=("${ALL[@]}")
|
||||
;;
|
||||
*)
|
||||
IFS=',' read -ra requested <<< "$PLATFORMS"
|
||||
for p in "${requested[@]}"; do
|
||||
p=${p// /}
|
||||
[ -z "$p" ] && continue
|
||||
[[ " ${ALL[*]} " == *" $p "* ]] || fail "unknown platform '$p' (known: ${ALL[*]})"
|
||||
selected+=("$p")
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$PLATFORMS" != missing ] && [ "$REPLACE" != true ]; then
|
||||
for p in "${selected[@]}"; do
|
||||
if is_attached "$p"; then
|
||||
fail "$TAG already has $(asset_name "$p"); run with replace=true to rebuild and overwrite it"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
{
|
||||
echo "### Standalone binaries for $TAG"
|
||||
echo
|
||||
echo "Request: \`$PLATFORMS\`, replace: \`$REPLACE\`"
|
||||
echo
|
||||
for p in "${ALL[@]}"; do
|
||||
state=$(is_attached "$p" && echo attached || echo missing)
|
||||
action=skip
|
||||
[[ " ${selected[*]:-} " == *" $p "* ]] && action=build
|
||||
echo "- \`$(asset_name "$p")\`: $state, $action"
|
||||
done
|
||||
} >> "$SUMMARY"
|
||||
|
||||
if [ ${#selected[@]} -eq 0 ]; then
|
||||
echo "$TAG already has every standalone binary; nothing to build" >&2
|
||||
fi
|
||||
emit "${selected[@]:-}"
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
# Writes <dist>/sha256sums.txt for a release: the binaries staged in <dist> plus every binary the
|
||||
# release already carries (downloaded into <existing>) that <dist> does not replace.
|
||||
#
|
||||
# release-binaries-sums.sh <existing> <dist>
|
||||
#
|
||||
# The release's current sha256sums.txt is first verified against its cosign bundle, signed by
|
||||
# release.yml as docs/getting-started/installation.md tells users to check it, and the existing
|
||||
# binaries are then checked against that file. So a backfill never vouches for a file the release
|
||||
# did not already sign: a sums file without a bundle that verifies, or an existing binary that is
|
||||
# missing from it or does not match it, stops the publish. With nothing in <existing> (a tag
|
||||
# run) the result is plain `sha256sum floci-aws-*` over <dist>, as before.
|
||||
set -euo pipefail
|
||||
|
||||
EXISTING=${1:?usage: release-binaries-sums.sh <existing> <dist>}
|
||||
DIST=${2:?usage: release-binaries-sums.sh <existing> <dist>}
|
||||
|
||||
binaries() {
|
||||
find "$1" -maxdepth 1 -type f -name 'floci-aws-*' ! -name '*.sigstore.json' -exec basename {} \; | sort
|
||||
}
|
||||
|
||||
existing=$(binaries "$EXISTING")
|
||||
lines=()
|
||||
if [ -n "$existing" ]; then
|
||||
if [ ! -f "$EXISTING/sha256sums.txt" ]; then
|
||||
echo "::error::the release has binaries but no sha256sums.txt; it cannot be extended safely" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f "$EXISTING/sha256sums.txt.sigstore.json" ]; then
|
||||
echo "::error::the release's sha256sums.txt has no cosign bundle; it cannot be extended safely" >&2
|
||||
exit 1
|
||||
fi
|
||||
cosign verify-blob "$EXISTING/sha256sums.txt" --bundle "$EXISTING/sha256sums.txt.sigstore.json" \
|
||||
--certificate-identity-regexp '^https://github.com/floci-io/floci/.github/workflows/release.yml@' \
|
||||
--certificate-oidc-issuer https://token.actions.githubusercontent.com >&2 \
|
||||
|| { echo "::error::the release's sha256sums.txt does not verify against its cosign bundle" >&2; exit 1; }
|
||||
while IFS= read -r name; do
|
||||
grep -qE "^[0-9a-f]{64} $name\$" "$EXISTING/sha256sums.txt" \
|
||||
|| { echo "::error::$name is attached but not listed in the release's sha256sums.txt" >&2; exit 1; }
|
||||
done <<< "$existing"
|
||||
(cd "$EXISTING" && sha256sum --ignore-missing -c sha256sums.txt) >&2
|
||||
while IFS= read -r name; do
|
||||
[ -e "$DIST/$name" ] && continue
|
||||
lines+=("$(grep -E "^[0-9a-f]{64} $name\$" "$EXISTING/sha256sums.txt")")
|
||||
done <<< "$existing"
|
||||
fi
|
||||
|
||||
while IFS= read -r name; do
|
||||
[ -n "$name" ] && lines+=("$(cd "$DIST" && sha256sum "$name")")
|
||||
done <<< "$(binaries "$DIST")"
|
||||
|
||||
[ ${#lines[@]} -gt 0 ] || { echo "::error::no binaries to list" >&2; exit 1; }
|
||||
printf '%s\n' "${lines[@]}" | sort -k2 > "$DIST/sha256sums.txt"
|
||||
cat "$DIST/sha256sums.txt"
|
||||
Reference in new issue
Block a user