homebrew-tap
Clone
Read only, no credentials:
https://rodent.software/homebrew-tap.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/homebrew-tap.git
Homebrew tap for Rodent Software.
Add the Vole Homebrew formula and autobump script
ab3f4cbaeb37ac85d574dc3b53ee448a5b2f27e3 · keenan · 7d ago
scripts/autobump.sh +106
| @@ -0,0 +1,106 @@ | |||
| 1 | #! /bin/sh | ||
| 2 | # Refresh Formula/vole.rb to a published Vole release. | ||
| 3 | # | ||
| 4 | # The formula's version and checksums must agree with the release's own | ||
| 5 | # SHA256SUMS. This script reads that list for a tag, verifies each darwin asset | ||
| 6 | # against it, and rewrites the version and the two checksums in the formula. It | ||
| 7 | # refuses to write a checksum that does not match the downloaded asset, so a bad | ||
| 8 | # release or a typo fails the bump rather than the install. | ||
| 9 | # | ||
| 10 | # Usage: | ||
| 11 | # scripts/autobump.sh # the newest tag reachable from the homepage | ||
| 12 | # scripts/autobump.sh v0.2.0 # a specific tag | ||
| 13 | # | ||
| 14 | # It only edits Formula/vole.rb; commit and push are the caller's job. | ||
| 15 | set -eu | ||
| 16 | |||
| 17 | ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | ||
| 18 | cd "$ROOT" | ||
| 19 | |||
| 20 | BASE_URL=${VOLE_BASE_URL:-https://rodent.software/vole} | ||
| 21 | FORMULA=Formula/vole.rb | ||
| 22 | |||
| 23 | fail() { | ||
| 24 | printf 'autobump: %s\n' "$*" >&2 | ||
| 25 | exit 1 | ||
| 26 | } | ||
| 27 | |||
| 28 | sha256() { | ||
| 29 | if command -v sha256sum >/dev/null 2>&1; then | ||
| 30 | sha256sum "$1" | awk '{print $1}' | ||
| 31 | elif command -v shasum >/dev/null 2>&1; then | ||
| 32 | shasum -a 256 "$1" | awk '{print $1}' | ||
| 33 | else | ||
| 34 | fail "sha256sum or shasum is required" | ||
| 35 | fi | ||
| 36 | } | ||
| 37 | |||
| 38 | curl_with_retry() { | ||
| 39 | curl -fsSL --retry 3 --retry-delay 1 "$@" | ||
| 40 | } | ||
| 41 | |||
| 42 | tag=${1:-} | ||
| 43 | if [ -z "$tag" ]; then | ||
| 44 | # The homepage names the current stable release. This is a discovery step, so | ||
| 45 | # a release page that moves does not brick a manual bump: say so and stop. | ||
| 46 | tag=$(curl_with_retry "$BASE_URL" | sed -n 's|.*/releases/v\?\([0-9][^/" ]*\).*|\1|p' | head -n 1) | ||
| 47 | [ -n "$tag" ] || fail "no release tag found on $BASE_URL; pass one explicitly" | ||
| 48 | printf 'autobump: using latest release %s\n' "$tag" | ||
| 49 | fi | ||
| 50 | |||
| 51 | sums=$(mktemp) | ||
| 52 | trap 'rm -f "$sums" "${sums}.dl"' 0 | ||
| 53 | |||
| 54 | curl_with_retry "$BASE_URL/releases/$tag/artifacts/SHA256SUMS" -o "$sums" || | ||
| 55 | fail "cannot read SHA256SUMS for $tag" | ||
| 56 | |||
| 57 | # Extract the two darwin checksums, then prove each by downloading the asset and | ||
| 58 | # hashing it. A release that serves a different binary than its SUMS advertises | ||
| 59 | # must stop the bump here. | ||
| 60 | arm_sha=$(awk '$2 == "vole-darwin-arm64" {print $1}' "$sums") | ||
| 61 | amd_sha=$(awk '$2 == "vole-darwin-amd64" {print $1}' "$sums") | ||
| 62 | [ -n "$arm_sha" ] || fail "SHA256SUMS for $tag has no vole-darwin-arm64 entry" | ||
| 63 | [ -n "$amd_sha" ] || fail "SHA256SUMS for $tag has no vole-darwin-amd64 entry" | ||
| 64 | |||
| 65 | verify() { # asset checksum | ||
| 66 | curl_with_retry "$BASE_URL/releases/$tag/artifacts/$1" -o "${sums}.dl" || | ||
| 67 | fail "cannot download $1 for $tag" | ||
| 68 | got=$(sha256 "${sums}.dl") | ||
| 69 | [ "$got" = "$2" ] || fail "$1 does not match SHA256SUMS (got $got, want $2)" | ||
| 70 | } | ||
| 71 | |||
| 72 | verify vole-darwin-arm64 "$arm_sha" | ||
| 73 | verify vole-darwin-amd64 "$amd_sha" | ||
| 74 | |||
| 75 | version=${tag#v} | ||
| 76 | |||
| 77 | # Rewrite the version and the two checksums. The formula orders its sha256 lines | ||
| 78 | # arm64 first (inside on_arm), then amd64 (inside on_intel), so each can be | ||
| 79 | # addressed by position without depending on the Ruby quoting around it. | ||
| 80 | python3 - "$FORMULA" "$version" "$arm_sha" "$amd_sha" <<'PY' | ||
| 81 | import re, sys | ||
| 82 | path, version, arm, amd = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4] | ||
| 83 | with open(path) as f: | ||
| 84 | lines = f.readlines() | ||
| 85 | |||
| 86 | out = [] | ||
| 87 | sha_index = 0 | ||
| 88 | for line in lines: | ||
| 89 | mv = re.match(r'^( *)version ".*"', line) | ||
| 90 | ms = re.match(r'^( *)sha256 ".*"', line) | ||
| 91 | if mv: | ||
| 92 | out.append(f'{mv.group(1)}version "{version}"\n') | ||
| 93 | elif ms: | ||
| 94 | sha_index += 1 | ||
| 95 | sha = arm if sha_index == 1 else amd | ||
| 96 | out.append(f'{ms.group(1)}sha256 "{sha}"\n') | ||
| 97 | else: | ||
| 98 | out.append(line) | ||
| 99 | |||
| 100 | with open(path, 'w') as f: | ||
| 101 | f.writelines(out) | ||
| 102 | PY | ||
| 103 | |||
| 104 | printf 'autobump: wrote Formula/vole.rb for %s (version %s)\n' "$tag" "$version" | ||
| 105 | printf 'autobump: arm64 %s\n' "$arm_sha" | ||
| 106 | printf 'autobump: amd64 %s\n' "$amd_sha" | ||