Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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 Linux binaries and correct the tap name

100ec144b6bd20f9c7a2ed6c87e45c4cf2b01778 · keenan · 7d ago · parent 8b2c3ebf

Add Linux binaries and correct the tap name

- Correct the tap label to rodent-software/homebrew-tap, the convention other
  multi-project org taps use, so it is not Vole-specific.
- Add on_linux blocks: brew validates formulae for every platform, and a formula
  with only on_macos blocks fails to tap ("requires at least a URL"). Vole ships
  Linux binaries, so include them.
- Make autobump read the asset set from the formula's own url lines, so it works
  for a macOS-only project or one that adds a platform without scripting changes.

scripts/autobump.sh +40−31

@@ -3,16 +3,18 @@
3 3 #
4 4 # This is a shared tap: every Rodent Software project ships its formula here.
5 5 # The formula's version and checksums must agree with the release's own
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.
6 # SHA256SUMS, so this script reads that list for a tag, verifies each asset the
7 # formula names against it, and rewrites the version and checksums. It refuses to
8 # write a checksum that does not match the downloaded asset, so a bad release or
9 # a typo fails the bump rather than the install.
10 10 #
11 11 # Usage:
12 12 # scripts/autobump.sh vole # the newest tag reachable from the homepage
13 13 # scripts/autobump.sh vole v0.2.0 # a specific tag
14 14 #
15 # It only edits Formula/<project>.rb; commit and push are the caller's job.
15 # It only edits Formula/<project>.rb; commit and push are the caller's job. The
16 # asset set is read from the formula's own `url` lines, so a macOS-only project
17 # works the same as one that also ships Linux binaries.
16 18 set -eu
17 19
18 20 ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
@@ -21,10 +23,9 @@ cd "$ROOT"
21 23 project=${1:?usage: scripts/autobump.sh <project> [<tag>]}
22 24 tag=${2:-}
23 25
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).
26 # A project's homepage is https://rodent.software/<project>, and its formula is
27 # Formula/<project>.rb. Projects whose URL differs can override BASE_URL with the
28 # full project root (no trailing slash).
28 29 BASE_URL=${BASE_URL:-https://rodent.software/$project}
29 30 FORMULA=Formula/$project.rb
30 31
@@ -49,6 +50,12 @@ curl_with_retry() {
49 50 curl -fsSL --retry 3 --retry-delay 1 "$@"
50 51 }
51 52
53 # The formula carries one `url` line per asset and one `sha256` line per asset,
54 # in the same order. Read the asset names from the URL basenames so a project
55 # that ships only macOS, or one that adds another platform, needs no change here.
56 assets=$(sed -n 's|.*artifacts/\([^"/][^"]*\)\".*|\1|p' "$FORMULA")
57 [ -n "$assets" ] || fail "$FORMULA has no artifact url lines"
58
52 59 if [ -z "$tag" ]; then
53 60 # The project homepage names its current stable release. This is a discovery
54 61 # step, so a page that moves does not brick a manual bump: say so and stop.
@@ -63,32 +70,33 @@ trap 'rm -f "$sums" "${sums}.dl"' 0
63 70 curl_with_retry "$BASE_URL/releases/$tag/artifacts/SHA256SUMS" -o "$sums" ||
64 71 fail "cannot read SHA256SUMS for $tag"
65 72
66 # Extract the two darwin checksums, then prove each by downloading the asset and
67 # hashing it. A release that serves a different binary than its SUMS advertises
68 # must stop the bump here.
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"
73
74 verify() { # asset checksum
75 curl_with_retry "$BASE_URL/releases/$tag/artifacts/$1" -o "${sums}.dl" ||
76 fail "cannot download $1 for $tag"
73 verify() { # asset
74 name=$1
75 checksum=$(awk -v a="$name" '$2 == a {print $1}' "$sums")
76 [ -n "$checksum" ] || fail "SHA256SUMS for $tag has no $name entry"
77 curl_with_retry "$BASE_URL/releases/$tag/artifacts/$name" -o "${sums}.dl" ||
78 fail "cannot download $name for $tag"
77 79 got=$(sha256 "${sums}.dl")
78 [ "$got" = "$2" ] || fail "$1 does not match SHA256SUMS (got $got, want $2)"
80 [ "$got" = "$checksum" ] || fail "$name does not match SHA256SUMS (got $got, want $checksum)"
81 printf '%s\n' "$checksum"
79 82 }
80 83
81 verify "$project-darwin-arm64" "$arm_sha"
82 verify "$project-darwin-amd64" "$amd_sha"
84 # Verify every asset and collect its checksum in formula order.
85 checksums=""
86 for asset in $assets; do
87 sha_line=$(verify "$asset")
88 checksums="$checksums $sha_line"
89 done
83 90
84 91 version=${tag#v}
85 92
86 # Rewrite the version and the two checksums. Each formula orders its sha256 lines
87 # arm64 first (inside on_arm), then amd64 (inside on_intel), so each can be
88 # addressed by position without depending on the Ruby quoting around it.
89 python3 - "$FORMULA" "$version" "$arm_sha" "$amd_sha" <<'PY'
93 # Rewrite the version and the checksums in the formula, preserving the order the
94 # `sha256` lines already appear in (which matches the `url` order).
95 python3 - "$FORMULA" "$version" $checksums <<'PY'
90 96 import re, sys
91 path, version, arm, amd = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
97 path = sys.argv[1]
98 version = sys.argv[2]
99 checksums = sys.argv[3:]
92 100 with open(path) as f:
93 101 lines = f.readlines()
94 102
@@ -100,16 +108,17 @@ for line in lines:
100 108 if mv:
101 109 out.append(f'{mv.group(1)}version "{version}"\n')
102 110 elif ms:
111 sha = checksums[sha_index]
103 112 sha_index += 1
104 sha = arm if sha_index == 1 else amd
105 113 out.append(f'{ms.group(1)}sha256 "{sha}"\n')
106 114 else:
107 115 out.append(line)
108 116
117 if sha_index != len(checksums):
118 sys.exit(f'formula has {sha_index} sha256 lines but {len(checksums)} assets were verified')
119
109 120 with open(path, 'w') as f:
110 121 f.writelines(out)
111 122 PY
112 123
113 124 printf 'autobump: wrote %s for %s (version %s)\n' "$FORMULA" "$tag" "$version"
114 printf 'autobump: arm64 %s\n' "$arm_sha"
115 printf 'autobump: amd64 %s\n' "$amd_sha"