mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 08:31:53 -05:00
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
122 lines
4.0 KiB
Bash
Executable File
122 lines
4.0 KiB
Bash
Executable File
#!/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[@]:-}"
|