Skip to content

Commit 0d859b2

Browse files
unhappychoiceclaude
andcommitted
fix: improve homebrew formula update script reliability
Replace complex AWK script with simpler sed commands to ensure all architectures are updated correctly during releases. This fixes the issue where ARM versions were not being updated to the latest release. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f4b8466 commit 0d859b2

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -235,40 +235,28 @@ jobs:
235235
236236
cd homebrew-tap
237237
238-
# Use awk to update the formula
239-
awk -v version="$VERSION" \
240-
-v macos_intel_url="$MACOS_INTEL_URL" \
241-
-v macos_intel_sha="$MACOS_INTEL_SHA" \
242-
-v macos_arm_url="$MACOS_ARM_URL" \
243-
-v macos_arm_sha="$MACOS_ARM_SHA" \
244-
-v linux_intel_url="$LINUX_INTEL_URL" \
245-
-v linux_intel_sha="$LINUX_INTEL_SHA" \
246-
-v linux_arm_url="$LINUX_ARM_URL" \
247-
-v linux_arm_sha="$LINUX_ARM_SHA" '
248-
BEGIN { in_macos = 0; in_linux = 0; in_intel = 0; in_arm = 0 }
249-
/on_macos do/ { in_macos = 1; in_linux = 0; print; next }
250-
/on_linux do/ { in_linux = 1; in_macos = 0; print; next }
251-
/on_intel do/ { in_intel = 1; in_arm = 0; print; next }
252-
/on_arm do/ { in_arm = 1; in_intel = 0; print; next }
253-
/end/ { in_macos = 0; in_linux = 0; in_intel = 0; in_arm = 0; print; next }
254-
/url "/ {
255-
if (in_macos && in_intel) print " url \"" macos_intel_url "\""
256-
else if (in_macos && in_arm) print " url \"" macos_arm_url "\""
257-
else if (in_linux && in_intel) print " url \"" linux_intel_url "\""
258-
else if (in_linux && in_arm) print " url \"" linux_arm_url "\""
259-
else print
260-
next
261-
}
262-
/sha256 "/ {
263-
if (in_macos && in_intel) print " sha256 \"" macos_intel_sha "\""
264-
else if (in_macos && in_arm) print " sha256 \"" macos_arm_sha "\""
265-
else if (in_linux && in_intel) print " sha256 \"" linux_intel_sha "\""
266-
else if (in_linux && in_arm) print " sha256 \"" linux_arm_sha "\""
267-
else print
268-
next
269-
}
270-
{ print }
271-
' Formula/gittype.rb > Formula/gittype.rb.tmp && mv Formula/gittype.rb.tmp Formula/gittype.rb
238+
# Use sed to update each architecture's URL and SHA
239+
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-x86_64-apple-darwin.tar.gz|$MACOS_INTEL_URL|g" Formula/gittype.rb
240+
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-aarch64-apple-darwin.tar.gz|$MACOS_ARM_URL|g" Formula/gittype.rb
241+
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-x86_64-unknown-linux-gnu.tar.gz|$LINUX_INTEL_URL|g" Formula/gittype.rb
242+
sed -i "s|https://github.com/unhappychoice/gittype/releases/download/v[0-9.]\+/gittype-v[0-9.]\+-aarch64-unknown-linux-gnu.tar.gz|$LINUX_ARM_URL|g" Formula/gittype.rb
243+
244+
# Update SHA values in the same order they appear in the file
245+
# macOS Intel
246+
FIRST_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -1 | cut -d: -f1)
247+
sed -i "${FIRST_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$MACOS_INTEL_SHA\"/" Formula/gittype.rb
248+
249+
# macOS ARM
250+
SECOND_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -2 | tail -1 | cut -d: -f1)
251+
sed -i "${SECOND_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$MACOS_ARM_SHA\"/" Formula/gittype.rb
252+
253+
# Linux Intel
254+
THIRD_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -3 | tail -1 | cut -d: -f1)
255+
sed -i "${THIRD_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$LINUX_INTEL_SHA\"/" Formula/gittype.rb
256+
257+
# Linux ARM
258+
FOURTH_SHA_LINE=$(grep -n 'sha256 "' Formula/gittype.rb | head -4 | tail -1 | cut -d: -f1)
259+
sed -i "${FOURTH_SHA_LINE}s/sha256 \"[a-f0-9]\+\"/sha256 \"$LINUX_ARM_SHA\"/" Formula/gittype.rb
272260
273261
git config --local user.email "action@github.com"
274262
git config --local user.name "GitHub Action"

0 commit comments

Comments
 (0)