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.
Make the tap shared across Rodent Software projects
8b2c3ebfcc703c9090254b3a624fbdd15e471794 · keenan · 7d ago · parent 60730641
Make the tap shared across Rodent Software projects The tap is not Vole-specific: it ships one formula per project. Generalize autobump.sh to take a project name and derive the formula, asset names, and base URL from it, and rewrite the README as the Rodent Software tap with a project table and an adding-a-project section.
scripts/autobump.sh +31−22
| @@ -1,30 +1,40 @@ | |||
| 1 | 1 | #! /bin/sh | |
| 2 | # Refresh Formula/vole.rb to a published Vole release. | ||
| 2 | # Refresh one project's formula to a published release. | ||
| 3 | 3 | # | |
| 4 | # This is a shared tap: every Rodent Software project ships its formula here. | ||
| 4 | 5 | # 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. | ||
| 6 | # SHA256SUMS, so this script reads that list for a tag, verifies each darwin | ||
| 7 | # asset against it, and rewrites the version and the two checksums in the | ||
| 8 | # formula. It refuses to write a checksum that does not match the downloaded | ||
| 9 | # asset, so a bad release or a typo fails the bump rather than the install. | ||
| 9 | 10 | # | |
| 10 | 11 | # Usage: | |
| 11 | # scripts/autobump.sh # the newest tag reachable from the homepage | ||
| 12 | # scripts/autobump.sh v0.2.0 # a specific tag | ||
| 12 | # scripts/autobump.sh vole # the newest tag reachable from the homepage | ||
| 13 | # scripts/autobump.sh vole v0.2.0 # a specific tag | ||
| 13 | 14 | # | |
| 14 | # It only edits Formula/vole.rb; commit and push are the caller's job. | ||
| 15 | # It only edits Formula/<project>.rb; commit and push are the caller's job. | ||
| 15 | 16 | set -eu | |
| 16 | 17 | ||
| 17 | 18 | ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | |
| 18 | 19 | cd "$ROOT" | |
| 19 | 20 | ||
| 20 | BASE_URL=${VOLE_BASE_URL:-https://rodent.software/vole} | ||
| 21 | FORMULA=Formula/vole.rb | ||
| 21 | project=${1:?usage: scripts/autobump.sh <project> [<tag>]} | ||
| 22 | tag=${2:-} | ||
| 23 | |||
| 24 | # A project's homepage is https://rodent.software/<project>, its release assets | ||
| 25 | # are <project>-darwin-arm64 and <project>-darwin-amd64, and its formula is | ||
| 26 | # Formula/<project>.rb. Projects whose asset names or URL differ can override | ||
| 27 | # BASE_URL with the full project root (no trailing slash). | ||
| 28 | BASE_URL=${BASE_URL:-https://rodent.software/$project} | ||
| 29 | FORMULA=Formula/$project.rb | ||
| 22 | 30 | ||
| 23 | 31 | fail() { | |
| 24 | 32 | printf 'autobump: %s\n' "$*" >&2 | |
| 25 | 33 | exit 1 | |
| 26 | 34 | } | |
| 27 | 35 | ||
| 36 | [ -f "$FORMULA" ] || fail "no formula for $project at $FORMULA" | ||
| 37 | |||
| 28 | 38 | sha256() { | |
| 29 | 39 | if command -v sha256sum >/dev/null 2>&1; then | |
| 30 | 40 | sha256sum "$1" | awk '{print $1}' | |
| @@ -39,13 +49,12 @@ curl_with_retry() { | |||
| 39 | 49 | curl -fsSL --retry 3 --retry-delay 1 "$@" | |
| 40 | 50 | } | |
| 41 | 51 | ||
| 42 | tag=${1:-} | ||
| 43 | 52 | 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. | ||
| 53 | # The project homepage names its current stable release. This is a discovery | ||
| 54 | # step, so a page that moves does not brick a manual bump: say so and stop. | ||
| 46 | 55 | tag=$(curl_with_retry "$BASE_URL" | sed -n 's|.*/releases/v\?\([0-9][^/" ]*\).*|\1|p' | head -n 1) | |
| 47 | 56 | [ -n "$tag" ] || fail "no release tag found on $BASE_URL; pass one explicitly" | |
| 48 | printf 'autobump: using latest release %s\n' "$tag" | ||
| 57 | printf 'autobump: %s: using latest release %s\n' "$project" "$tag" | ||
| 49 | 58 | fi | |
| 50 | 59 | ||
| 51 | 60 | sums=$(mktemp) | |
| @@ -57,10 +66,10 @@ curl_with_retry "$BASE_URL/releases/$tag/artifacts/SHA256SUMS" -o "$sums" || | |||
| 57 | 66 | # Extract the two darwin checksums, then prove each by downloading the asset and | |
| 58 | 67 | # hashing it. A release that serves a different binary than its SUMS advertises | |
| 59 | 68 | # 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" | ||
| 69 | arm_sha=$(awk -v a="$project-darwin-arm64" '$2 == a {print $1}' "$sums") | ||
| 70 | amd_sha=$(awk -v a="$project-darwin-amd64" '$2 == a {print $1}' "$sums") | ||
| 71 | [ -n "$arm_sha" ] || fail "SHA256SUMS for $tag has no $project-darwin-arm64 entry" | ||
| 72 | [ -n "$amd_sha" ] || fail "SHA256SUMS for $tag has no $project-darwin-amd64 entry" | ||
| 64 | 73 | ||
| 65 | 74 | verify() { # asset checksum | |
| 66 | 75 | curl_with_retry "$BASE_URL/releases/$tag/artifacts/$1" -o "${sums}.dl" || | |
| @@ -69,12 +78,12 @@ verify() { # asset checksum | |||
| 69 | 78 | [ "$got" = "$2" ] || fail "$1 does not match SHA256SUMS (got $got, want $2)" | |
| 70 | 79 | } | |
| 71 | 80 | ||
| 72 | verify vole-darwin-arm64 "$arm_sha" | ||
| 73 | verify vole-darwin-amd64 "$amd_sha" | ||
| 81 | verify "$project-darwin-arm64" "$arm_sha" | ||
| 82 | verify "$project-darwin-amd64" "$amd_sha" | ||
| 74 | 83 | ||
| 75 | 84 | version=${tag#v} | |
| 76 | 85 | ||
| 77 | # Rewrite the version and the two checksums. The formula orders its sha256 lines | ||
| 86 | # Rewrite the version and the two checksums. Each formula orders its sha256 lines | ||
| 78 | 87 | # arm64 first (inside on_arm), then amd64 (inside on_intel), so each can be | |
| 79 | 88 | # addressed by position without depending on the Ruby quoting around it. | |
| 80 | 89 | python3 - "$FORMULA" "$version" "$arm_sha" "$amd_sha" <<'PY' | |
| @@ -101,6 +110,6 @@ with open(path, 'w') as f: | |||
| 101 | 110 | f.writelines(out) | |
| 102 | 111 | PY | |
| 103 | 112 | ||
| 104 | printf 'autobump: wrote Formula/vole.rb for %s (version %s)\n' "$tag" "$version" | ||
| 113 | printf 'autobump: wrote %s for %s (version %s)\n' "$FORMULA" "$tag" "$version" | ||
| 105 | 114 | printf 'autobump: arm64 %s\n' "$arm_sha" | |
| 106 | 115 | printf 'autobump: amd64 %s\n' "$amd_sha" | |