fix: stage complete releases and verify installer checksums before publishing

This commit is contained in:
shoemoney 2026-11-27 19:40:43 -06:00
parent 598640b8df
commit 1809489c2d
No known key found for this signature in database
3 changed files with 69 additions and 76 deletions

View file

@ -31,11 +31,14 @@ jobs:
arch="${f##*_}"; rest="${f%_*}"; os="${rest##*_}"; bin="${rest%_*}"; bin="${bin%_*}" arch="${f##*_}"; rest="${f%_*}"; os="${rest##*_}"; bin="${rest%_*}"; bin="${bin%_*}"
mv "$f$ext" "${bin}_${os}_${arch}${ext}" mv "$f$ext" "${bin}_${os}_${arch}${ext}"
done done
cp ../install.sh ../install.ps1 .
rm SHA256SUMS
sha256sum devbox_* devbox-hub_* install.sh install.ps1 > SHA256SUMS
ls -la ls -la
- name: Publish GitHub release - name: Publish GitHub release
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
run: | run: |
gh release create "${{ github.ref_name }}" dist/* \ gh release create "${{ github.ref_name }}" dist/devbox_* dist/devbox-hub_* dist/install.sh dist/install.ps1 dist/SHA256SUMS \
--title "${{ github.ref_name }}" \ --title "${{ github.ref_name }}" \
--generate-notes --generate-notes

View file

@ -40,6 +40,9 @@ echo "Generating dist/SHA256SUMS"
fi fi
) )
# Provenance for publishing or promoting this exact build without rebuilding it.
printf '%s\n%s\n' "$(git rev-parse HEAD)" "$VERSION" > dist/BUILD_INFO
echo echo
echo "Done. Artifacts in dist/:" echo "Done. Artifacts in dist/:"
ls -lh dist/ ls -lh dist/

View file

@ -1,89 +1,76 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
# One-shot local release. No CI runner required. # Build and publish a complete release to the public distribution repository.
# # ./scripts/release.sh v2.1.0
# ./scripts/release.sh # (re)publish the moving 'latest' release # DEVBOX_SKIP_BUILD=1 ./scripts/release.sh latest # promote the same verified build
# ./scripts/release.sh v1.0.0 # cut a versioned release # Versioned releases are immutable. Uploads remain draft until every asset exists.
#
# Builds every target here (private source repo), then publishes to the PUBLIC
# devbox-dist repo so `curl|sh` works without a token. Assets carry the
# de-versioned names install.sh downloads, plus the installers themselves:
# install.sh install.ps1 devbox_<os>_<arch> devbox-hub_<os>_<arch> SHA256SUMS
#
# Auth: ~/.config/forgejo/token (or $FORGEJO_TOKEN). Override with FORGEJO_API /
# REPO (publish target) / DIST_BRANCH if the dist repo ever moves.
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
TAG="${1:-latest}" TAG="${1:-latest}"
API="${FORGEJO_API:-https://git.shoemoney.ai/api/v1}" API="${FORGEJO_API:-https://git.shoemoney.ai/api/v1}"
REPO="${REPO:-shoemoney/devbox-dist}" # public distribution repo (releases live here) REPO="${REPO:-shoemoney/devbox-dist}"
DIST_BRANCH="${DIST_BRANCH:-main}" # tags hang off this branch in the dist repo DIST_BRANCH="${DIST_BRANCH:-main}"
TOKEN="${FORGEJO_TOKEN:-$(cat ~/.config/forgejo/token 2>/dev/null || true)}" TOKEN="${FORGEJO_TOKEN:-$(cat ~/.config/forgejo/token 2>/dev/null || true)}"
[ -n "$TOKEN" ] || { echo "🛑 no Forgejo token (set FORGEJO_TOKEN or ~/.config/forgejo/token)" >&2; exit 1; } [ -n "$TOKEN" ] || { echo 'No Forgejo token configured' >&2; exit 1; }
[[ "$TAG" =~ ^(latest|v[0-9]+\.[0-9]+\.[0-9]+)$ ]] || { echo 'Expected latest or vMAJOR.MINOR.PATCH' >&2; exit 1; }
auth=(-H "Authorization: token $TOKEN") auth=(-H "Authorization: token $TOKEN")
api() { curl -fsSL "${auth[@]}" "$@"; } api() { curl --retry 2 --retry-delay 1 -fsSL "${auth[@]}" "$@"; }
# 1. Build. A real tag stamps its name into the binary; 'latest' uses git-describe.
if [ "$TAG" = latest ]; then
./scripts/build-release.sh
else
VERSION="$TAG" ./scripts/build-release.sh
fi
COMMIT=$(git rev-parse HEAD) COMMIT=$(git rev-parse HEAD)
# 2. Drop any existing release+tag with this name so we recreate cleanly (latest is a # Dist assets must have been built from exactly this source revision.
# moving target; re-cutting a vX.Y.Z is rare but should be idempotent too). if [ "${DEVBOX_SKIP_BUILD:-0}" != 1 ]; then
old_id=$(api "$API/repos/$REPO/releases/tags/$TAG" 2>/dev/null \ if [ "$TAG" = latest ]; then ./scripts/build-release.sh; else VERSION="$TAG" ./scripts/build-release.sh; fi
| python3 -c 'import sys,json;print(json.load(sys.stdin).get("id",""))' 2>/dev/null || true)
if [ -n "${old_id:-}" ]; then
echo "↻ replacing existing release '$TAG' (id $old_id)"
curl -fsSL -X DELETE "${auth[@]}" "$API/repos/$REPO/releases/$old_id" || true
fi
# Move the lightweight tag to HEAD for 'latest'; leave real version tags alone if present.
if [ "$TAG" = latest ]; then
curl -fsSL -X DELETE "${auth[@]}" "$API/repos/$REPO/tags/$TAG" >/dev/null 2>&1 || true
fi fi
[ -f dist/BUILD_INFO ] || { echo 'Missing dist/BUILD_INFO; build first' >&2; exit 1; }
[ "$(sed -n '1p' dist/BUILD_INFO)" = "$COMMIT" ] || { echo 'Build source revision does not match HEAD' >&2; exit 1; }
BUILD_VERSION=$(sed -n '2p' dist/BUILD_INFO)
[ "$TAG" = latest ] || [ "$BUILD_VERSION" = "$TAG" ] || { echo 'Build version does not match release tag' >&2; exit 1; }
(cd dist && sha256sum -c SHA256SUMS)
# 3. Create the release. Tag hangs off the dist repo's branch (the source $COMMIT # Prepare the exact names downloaded by install.sh and checksum the installers too.
# lives in the private repo, not here) — we keep $COMMIT only for provenance. STAGE=dist/release-assets
prerelease=$([ "$TAG" = latest ] && echo true || echo false) rm -rf "$STAGE"
body=$(printf 'devbox %s — built %s from source `%s`.\n\nInstall: `curl -fsSL https://git.shoemoney.ai/shoemoney/devbox-dist/releases/download/latest/install.sh | sh`' "$TAG" "$(date -u +%Y-%m-%dT%H:%MZ)" "${COMMIT:0:7}") mkdir -p "$STAGE"
rel_id=$(api -X POST "$API/repos/$REPO/releases" \ for bin in devbox devbox-hub; do
-H 'Content-Type: application/json' \ for target in linux/amd64 linux/arm64 linux/arm darwin/arm64 darwin/amd64 windows/amd64; do
-d "$(python3 -c 'import json,sys; t,c,b,p=sys.argv[1:5]; print(json.dumps({"tag_name":t,"target_commitish":c,"name":t,"body":b,"draft":False,"prerelease":p=="true"}))' "$TAG" "$DIST_BRANCH" "$body" "$prerelease")" \ os="${target%/*}"; arch="${target#*/}"; ext=""
| python3 -c 'import sys,json;print(json.load(sys.stdin)["id"])') [ "$os" != windows ] || ext=.exe
echo "✅ release '$TAG' created (id $rel_id)" cp "dist/${bin}_${BUILD_VERSION}_${os}_${arch}${ext}" "$STAGE/${bin}_${os}_${arch}${ext}"
# 4. Upload de-versioned assets. dist names are <bin>_<version>_<os>_<arch>[.exe].
# deversion <basename> -> <bin>_<os>_<arch>[.exe] (the name install.sh fetches).
deversion() {
local base="$1" ext="" arch rest os bin
case "$base" in *.exe) ext=".exe"; base="${base%.exe}";; esac
arch="${base##*_}"; rest="${base%_*}"
os="${rest##*_}"; bin="${rest%_*}"; bin="${bin%_*}" # strip version component
printf '%s_%s_%s%s' "$bin" "$os" "$arch" "$ext"
}
upload() {
local name; name=$(deversion "$(basename "$1")")
echo " ⬆ $name"
api -X POST "$API/repos/$REPO/releases/$rel_id/assets?name=$name" -F "attachment=@$1" >/dev/null
}
for f in dist/devbox_* dist/devbox-hub_*; do [ -f "$f" ] && upload "$f"; done
# The installers ride along as assets so `curl|sh` and `irm|iex` pull current copies.
for s in install.sh install.ps1; do
echo " ⬆ $s"
api -X POST "$API/repos/$REPO/releases/$rel_id/assets?name=$s" -F "attachment=@$s" >/dev/null
done done
# Rewrite SHA256SUMS to the de-versioned names so `shasum -c` matches the assets. done
while read -r h n; do printf '%s %s\n' "$h" "$(deversion "$n")"; done \ cp install.sh install.ps1 "$STAGE/"
< dist/SHA256SUMS > dist/SHA256SUMS.release (cd "$STAGE" && sha256sum devbox_* devbox-hub_* install.sh install.ps1 > SHA256SUMS)
echo " ⬆ SHA256SUMS"
api -X POST "$API/repos/$REPO/releases/$rel_id/assets?name=SHA256SUMS" \
-F "attachment=@dist/SHA256SUMS.release" >/dev/null
echo # Read errors fail the release; a 404 alone means the tag has no release.
echo "🎉 https://git.shoemoney.ai/$REPO/releases/tag/$TAG" old_json=$(mktemp)
trap 'rm -f "$old_json"' EXIT
code=$(curl -sSL "${auth[@]}" -o "$old_json" -w '%{http_code}' "$API/repos/$REPO/releases/tags/$TAG")
old_id=""
case "$code" in
200) old_id=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["id"])' "$old_json");;
404) ;;
*) echo "Release lookup failed: HTTP $code" >&2; exit 1;;
esac
if [ -n "$old_id" ] && [ "$TAG" != latest ]; then
echo "Release $TAG already exists; choose a new version" >&2; exit 1
fi
upload_tag="$TAG"
[ "$TAG" != latest ] || upload_tag="latest-staging-${COMMIT:0:12}-$(date +%s)"
body=$(printf 'devbox %s — built from source `%s`, binary version `%s`.\n\nBuilt-in Tailscale in the hub: `devbox-hub serve --data ./hub-data --tailscale`. No separate Tailscale installation is required on the hub. Authenticate using the logged login URL or TS_AUTHKEY; identity persists under <data>/tailscale. Clients use the regular Tailscale app. Existing HTTP/HTTPS deployments remain supported.\n\nInstall: `curl -fsSL https://git.shoemoney.ai/%s/releases/download/%s/install.sh | sh`\n\nAssets include 12 binaries, both installers, and SHA256SUMS. Building from source requires Go 1.27.4+.' "$TAG" "$COMMIT" "$BUILD_VERSION" "$REPO" "$TAG")
rel_id=$(api -X POST "$API/repos/$REPO/releases" -H 'Content-Type: application/json' \
-d "$(python3 -c 'import json,sys;print(json.dumps(dict(tag_name=sys.argv[1],target_commitish=sys.argv[2],name=sys.argv[3],body=sys.argv[4],draft=True,prerelease=False)))' "$upload_tag" "$DIST_BRANCH" "$TAG" "$body")" \
| python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')
echo "Uploading draft release $TAG (id $rel_id)"
for f in "$STAGE"/*; do
name=$(basename "$f")
echo " upload $name"
# Do not retry non-idempotent uploads: preserve a failed draft for inspection.
curl -fsSL "${auth[@]}" -X POST "$API/repos/$REPO/releases/$rel_id/assets?name=$name" -F "attachment=@$f" >/dev/null
done
count=$(api "$API/repos/$REPO/releases/$rel_id" | python3 -c 'import json,sys;print(len(json.load(sys.stdin)["assets"]))')
[ "$count" = 15 ] || { echo "Expected 15 assets, got $count; leaving draft unpublished" >&2; exit 1; }
# Keep the existing moving release until the replacement is fully uploaded.
if [ -n "$old_id" ]; then api -X DELETE "$API/repos/$REPO/releases/$old_id" >/dev/null; fi
api -X PATCH "$API/repos/$REPO/releases/$rel_id" -H 'Content-Type: application/json' \
-d "$(python3 -c 'import json,sys;print(json.dumps(dict(tag_name=sys.argv[1],draft=False)))' "$TAG")" >/dev/null
echo "https://git.shoemoney.ai/$REPO/releases/tag/$TAG"