Branchwell

Bucksley / website / tools / set-release.sh

1#!/bin/bash
2# Usage: tools/set-release.sh VERSION BUILD SHA256 BYTES
3# Points the whole site at downloads/Bucksley-VERSION.dmg: the first run switches every page from
4# "Coming soon" to the real Mac download. It regenerates the pages and llms.txt with
5# tools/build-site.py --release (download page, home page, header, help, privacy, and the JSON-LD
6# softwareVersion, downloadUrl and InStock offer on every page). Run by bucksley/scripts/release-mac.sh
7# after it copies the DMG to downloads/ and the feed to appcast.xml. SHA256 and BYTES may be
8# "pending" for a placeholder; otherwise the staged DMG must exist and match both.
9#
10# The DMG itself is served from the R2 bucket bucksley-downloads, not from git. Upload it before
11# pushing (see README):
12# npx wrangler r2 object put bucksley-downloads/Bucksley-VERSION.dmg --file downloads/Bucksley-VERSION.dmg --remote --content-type application/x-apple-diskimage
13set -euo pipefail
14usage='Usage: tools/set-release.sh VERSION BUILD SHA256 BYTES'
15version="${1:?$usage}" build="${2:?$usage}" sha="${3:?$usage}" bytes="${4:?$usage}"
16[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'VERSION must look like 1.2.3.' >&2; exit 1; }
17[[ "$build" =~ ^[0-9]+$ ]] || { echo 'BUILD must be a whole number.' >&2; exit 1; }
18[[ "$sha" =~ ^[0-9a-f]{64}$ || "$sha" == pending ]] || { echo 'Pass the 64-character SHA-256 of the DMG, or "pending".' >&2; exit 1; }
19[[ "$bytes" =~ ^[0-9]+$ || "$bytes" == pending ]] || { echo 'BYTES must be the DMG size in bytes, or "pending".' >&2; exit 1; }
20cd "$(dirname "$0")/.."
21
22dmg="downloads/Bucksley-$version.dmg"
23if [[ "$sha" != pending ]]; then
24 [[ -f "$dmg" ]] || { echo "Stage $dmg first." >&2; exit 1; }
25 [[ "$(shasum -a 256 "$dmg" | cut -d' ' -f1)" == "$sha" ]] || { echo "Checksum does not match $dmg." >&2; exit 1; }
26fi
27if [[ "$bytes" != pending && -f "$dmg" ]]; then
28 [[ "$(stat -f %z "$dmg" 2>/dev/null || stat -c %s "$dmg")" == "$bytes" ]] || { echo "Size does not match $dmg." >&2; exit 1; }
29fi
30
31# Size as Finder shows it (decimal megabytes).
32if [[ "$bytes" == pending ]]; then size='Size pending'; else size="$(awk -v b="$bytes" 'BEGIN { printf "%.1f MB", b / 1000000 }')"; fi
33
34python3 tools/build-site.py --release "$version" "$build" "$sha" "$size"
35
36grep -q "Bucksley-$version.dmg" download/index.html || { echo 'The download page has no link to the DMG.' >&2; exit 1; }
37echo "Site points at $dmg (version $version, build $build, $size, SHA-256 $sha)."
38grep -n "data-release=\"\(version\|build\|size\|sha\)\"" download/index.html | sed -E 's/^([0-9]+):.*(data-release="[a-z]+">[^<]*).*/ download\/index.html:\1 \2/'
39grep -n '^- Current release' llms.txt