Skip to content

Commit 7b13476

Browse files
committed
fix(ci): update homebrew script for binary formula
Update script to handle formula with on_arm/on_intel blocks: - Download both ARM64 and x86_64 binary tarballs - Calculate SHA256 for each architecture - Update version, URLs, and checksums separately
1 parent 1eefa17 commit 7b13476

1 file changed

Lines changed: 46 additions & 11 deletions

File tree

.github/workflows/release.yaml

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,62 @@ jobs:
285285
286286
echo "==> Updating formula to version ${VERSION}"
287287
288-
# Download source tarball and calculate SHA256
289-
TARBALL_URL="https://github.com/${REPO}/archive/refs/tags/v${VERSION}.tar.gz"
290-
echo "==> Downloading ${TARBALL_URL}"
291-
292-
HTTP_CODE=$(curl -sL -w "%{http_code}" -o /tmp/source.tar.gz "$TARBALL_URL")
288+
# Download ARM64 binary and calculate SHA256
289+
ARM64_URL="https://github.com/${REPO}/releases/download/v${VERSION}/sx-${VERSION}-aarch64-apple-darwin.tar.gz"
290+
echo "==> Downloading ARM64 binary: ${ARM64_URL}"
291+
HTTP_CODE=$(curl -sL -w "%{http_code}" -o /tmp/arm64.tar.gz "$ARM64_URL")
293292
if [ "$HTTP_CODE" != "200" ]; then
294-
echo "Error: Failed to download tarball (HTTP ${HTTP_CODE})"
293+
echo "Error: Failed to download ARM64 binary (HTTP ${HTTP_CODE})"
295294
exit 1
296295
fi
296+
ARM64_SHA256=$(shasum -a 256 /tmp/arm64.tar.gz | cut -d' ' -f1)
297+
echo "==> ARM64 SHA256: ${ARM64_SHA256}"
297298
298-
SHA256=$(shasum -a 256 /tmp/source.tar.gz | cut -d' ' -f1)
299-
echo "==> SHA256: ${SHA256}"
299+
# Download x86_64 binary and calculate SHA256
300+
X86_64_URL="https://github.com/${REPO}/releases/download/v${VERSION}/sx-${VERSION}-x86_64-apple-darwin.tar.gz"
301+
echo "==> Downloading x86_64 binary: ${X86_64_URL}"
302+
HTTP_CODE=$(curl -sL -w "%{http_code}" -o /tmp/x86_64.tar.gz "$X86_64_URL")
303+
if [ "$HTTP_CODE" != "200" ]; then
304+
echo "Error: Failed to download x86_64 binary (HTTP ${HTTP_CODE})"
305+
exit 1
306+
fi
307+
X86_64_SHA256=$(shasum -a 256 /tmp/x86_64.tar.gz | cut -d' ' -f1)
308+
echo "==> x86_64 SHA256: ${X86_64_SHA256}"
300309
301310
# Get current formula
302311
echo "==> Fetching current formula"
303312
gh api "repos/${TAP_REPO}/contents/Formula/sx.rb" --jq '.content' | base64 -d > /tmp/formula.rb
304313
305-
# Update version and SHA256 in formula
314+
# Update formula
306315
echo "==> Updating formula"
307-
sed -i -E "s|url \"https://github.com/${REPO}/archive/refs/tags/v[^\"]+\.tar\.gz\"|url \"${TARBALL_URL}\"|" /tmp/formula.rb
308-
sed -i -E "s|sha256 \"[a-f0-9]+\"|sha256 \"${SHA256}\"|" /tmp/formula.rb
316+
317+
# Update version
318+
sed -i -E "s|version \"[^\"]+\"|version \"${VERSION}\"|" /tmp/formula.rb
319+
320+
# Update ARM64 URL and SHA256 (in on_arm block)
321+
sed -i -E "s|url \"https://github.com/${REPO}/releases/download/v[^/]+/sx-[^-]+-aarch64-apple-darwin\.tar\.gz\"|url \"${ARM64_URL}\"|" /tmp/formula.rb
322+
323+
# Update x86_64 URL and SHA256 (in on_intel block)
324+
sed -i -E "s|url \"https://github.com/${REPO}/releases/download/v[^/]+/sx-[^-]+-x86_64-apple-darwin\.tar\.gz\"|url \"${X86_64_URL}\"|" /tmp/formula.rb
325+
326+
# Update SHA256 values - ARM64 first (appears first in file), then x86_64
327+
# Use awk to update sha256 values in order of appearance
328+
awk -v arm64="${ARM64_SHA256}" -v x86="${X86_64_SHA256}" '
329+
/sha256 "[a-f0-9]+"/ {
330+
if (!first_done) {
331+
sub(/sha256 "[a-f0-9]+"/, "sha256 \"" arm64 "\"")
332+
first_done = 1
333+
} else {
334+
sub(/sha256 "[a-f0-9]+"/, "sha256 \"" x86 "\"")
335+
}
336+
}
337+
{ print }
338+
' /tmp/formula.rb > /tmp/formula_updated.rb
339+
mv /tmp/formula_updated.rb /tmp/formula.rb
340+
341+
# Show changes
342+
echo "==> Updated formula:"
343+
cat /tmp/formula.rb
309344
310345
# Get current file SHA (needed for update)
311346
FILE_SHA=$(gh api "repos/${TAP_REPO}/contents/Formula/sx.rb" --jq '.sha')

0 commit comments

Comments
 (0)