Skip to content

Commit f922ab8

Browse files
committed
ci: rewrite Homebrew formula update with manual template
Replace dawidd6/action-homebrew-bump-formula with a custom script that downloads release assets, computes SHA256 checksums, and generates the formula with multi-platform support (macOS/Linux, x86_64/aarch64). Also add Homebrew installation instructions to README.
1 parent 2ba79cb commit f922ab8

2 files changed

Lines changed: 100 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,96 @@ jobs:
144144
runs-on: ubuntu-latest
145145
if: "!contains(github.ref, 'alpha') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc')"
146146
steps:
147-
- name: Update Homebrew formula
148-
uses: dawidd6/action-homebrew-bump-formula@v3
149-
continue-on-error: true
147+
- name: Download release assets and compute checksums
148+
id: checksums
149+
env:
150+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
VERSION: ${{ needs.create-release.outputs.version }}
152+
run: |
153+
BASE_URL="https://github.com/DropFan/codelens/releases/download/v${VERSION}-rust"
154+
155+
# Download and compute SHA256 for each platform
156+
SHA_MACOS_X86=$(curl -sL "${BASE_URL}/codelens-${VERSION}-x86_64-apple-darwin.tar.gz" | sha256sum | cut -d' ' -f1)
157+
SHA_MACOS_ARM=$(curl -sL "${BASE_URL}/codelens-${VERSION}-aarch64-apple-darwin.tar.gz" | sha256sum | cut -d' ' -f1)
158+
SHA_LINUX_X86=$(curl -sL "${BASE_URL}/codelens-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" | sha256sum | cut -d' ' -f1)
159+
SHA_LINUX_ARM=$(curl -sL "${BASE_URL}/codelens-${VERSION}-aarch64-unknown-linux-gnu.tar.gz" | sha256sum | cut -d' ' -f1)
160+
161+
echo "sha_macos_x86=${SHA_MACOS_X86}" >> $GITHUB_OUTPUT
162+
echo "sha_macos_arm=${SHA_MACOS_ARM}" >> $GITHUB_OUTPUT
163+
echo "sha_linux_x86=${SHA_LINUX_X86}" >> $GITHUB_OUTPUT
164+
echo "sha_linux_arm=${SHA_LINUX_ARM}" >> $GITHUB_OUTPUT
165+
166+
- name: Checkout homebrew-tap
167+
uses: actions/checkout@v4
150168
with:
169+
repository: DropFan/homebrew-tap
151170
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
152-
tap: DropFan/homebrew-tap
153-
formula: codelens
154-
tag: v${{ needs.create-release.outputs.version }}-rust
171+
path: homebrew-tap
172+
173+
- name: Update formula
174+
env:
175+
VERSION: ${{ needs.create-release.outputs.version }}
176+
SHA_MACOS_X86: ${{ steps.checksums.outputs.sha_macos_x86 }}
177+
SHA_MACOS_ARM: ${{ steps.checksums.outputs.sha_macos_arm }}
178+
SHA_LINUX_X86: ${{ steps.checksums.outputs.sha_linux_x86 }}
179+
SHA_LINUX_ARM: ${{ steps.checksums.outputs.sha_linux_arm }}
180+
run: |
181+
cat > homebrew-tap/Formula/codelens.rb << 'FORMULA'
182+
class Codelens < Formula
183+
desc "High performance code statistics tool written in Rust"
184+
homepage "https://github.com/DropFan/codelens"
185+
version "VERSION_PLACEHOLDER"
186+
license "MIT"
187+
188+
on_macos do
189+
on_intel do
190+
url "https://github.com/DropFan/codelens/releases/download/vVERSION_PLACEHOLDER-rust/codelens-VERSION_PLACEHOLDER-x86_64-apple-darwin.tar.gz"
191+
sha256 "SHA_MACOS_X86_PLACEHOLDER"
192+
end
193+
on_arm do
194+
url "https://github.com/DropFan/codelens/releases/download/vVERSION_PLACEHOLDER-rust/codelens-VERSION_PLACEHOLDER-aarch64-apple-darwin.tar.gz"
195+
sha256 "SHA_MACOS_ARM_PLACEHOLDER"
196+
end
197+
end
198+
199+
on_linux do
200+
on_intel do
201+
url "https://github.com/DropFan/codelens/releases/download/vVERSION_PLACEHOLDER-rust/codelens-VERSION_PLACEHOLDER-x86_64-unknown-linux-gnu.tar.gz"
202+
sha256 "SHA_LINUX_X86_PLACEHOLDER"
203+
end
204+
on_arm do
205+
url "https://github.com/DropFan/codelens/releases/download/vVERSION_PLACEHOLDER-rust/codelens-VERSION_PLACEHOLDER-aarch64-unknown-linux-gnu.tar.gz"
206+
sha256 "SHA_LINUX_ARM_PLACEHOLDER"
207+
end
208+
end
209+
210+
def install
211+
bin.install "codelens"
212+
end
213+
214+
test do
215+
assert_match "codelens", shell_output("#{bin}/codelens --version")
216+
end
217+
end
218+
FORMULA
219+
220+
# Replace placeholders with actual values
221+
sed -i "s/VERSION_PLACEHOLDER/${VERSION}/g" homebrew-tap/Formula/codelens.rb
222+
sed -i "s/SHA_MACOS_X86_PLACEHOLDER/${SHA_MACOS_X86}/g" homebrew-tap/Formula/codelens.rb
223+
sed -i "s/SHA_MACOS_ARM_PLACEHOLDER/${SHA_MACOS_ARM}/g" homebrew-tap/Formula/codelens.rb
224+
sed -i "s/SHA_LINUX_X86_PLACEHOLDER/${SHA_LINUX_X86}/g" homebrew-tap/Formula/codelens.rb
225+
sed -i "s/SHA_LINUX_ARM_PLACEHOLDER/${SHA_LINUX_ARM}/g" homebrew-tap/Formula/codelens.rb
226+
227+
# Remove leading spaces from heredoc
228+
sed -i 's/^ //' homebrew-tap/Formula/codelens.rb
229+
230+
- name: Commit and push
231+
working-directory: homebrew-tap
232+
env:
233+
VERSION: ${{ needs.create-release.outputs.version }}
234+
run: |
235+
git config user.name "github-actions[bot]"
236+
git config user.email "github-actions[bot]@users.noreply.github.com"
237+
git add Formula/codelens.rb
238+
git commit -m "codelens ${VERSION}" || echo "No changes to commit"
239+
git push

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ High performance code statistics tool written in Rust.
1313

1414
## Installation
1515

16+
### Homebrew (macOS/Linux)
17+
18+
```bash
19+
brew install DropFan/tap/codelens
20+
```
21+
22+
### Cargo
23+
1624
```bash
1725
cargo install codelens
1826
```
1927

20-
Or build from source:
28+
### Build from source
2129

2230
```bash
2331
git clone https://github.com/DropFan/codelens

0 commit comments

Comments
 (0)