Skip to content

Commit 4dbf6ac

Browse files
committed
Add GitHub Actions workflow to auto-update Homebrew formula on release
- Introduce workflow to compute SHA256 checksum of release tarball. - Update Homebrew formula with the new version, URL, and checksum. - Automate commit and push to the Homebrew tap repository.
1 parent b8951b4 commit 4dbf6ac

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Update Homebrew Formula
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
update-homebrew:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Check out the ch.sh repository
13+
uses: actions/checkout@v4
14+
15+
- name: Get the latest release tag
16+
id: get_tag
17+
run: echo "LATEST_TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
18+
19+
- name: Generate SHA256 checksum
20+
run: |
21+
TARBALL_URL="https://github.com/nicholascross/ch.sh/archive/refs/tags/${{ env.LATEST_TAG }}.tar.gz"
22+
curl -L -o ch.sh.tar.gz "$TARBALL_URL"
23+
echo "SHA256=$(shasum -a 256 ch.sh.tar.gz | awk '{print $1}')" >> $GITHUB_ENV
24+
rm ch.sh.tar.gz
25+
26+
- name: Setup SSH for pushing to Homebrew tap
27+
env:
28+
HOMEBREW_DEPLOY_KEY: ${{ secrets.HOMEBREW_DEPLOY_KEY }}
29+
run: |
30+
mkdir -p ~/.ssh
31+
echo "$HOMEBREW_DEPLOY_KEY" > ~/.ssh/id_ed25519
32+
chmod 600 ~/.ssh/id_ed25519
33+
ssh-keyscan github.com >> ~/.ssh/known_hosts
34+
35+
- name: Clone the Homebrew tap repository
36+
run: |
37+
git clone [email protected]:nicholascross/homebrew-ch.sh.git homebrew-tap
38+
cd homebrew-tap
39+
git config user.name "github-actions[bot]"
40+
git config user.email "github-actions[bot]@users.noreply.github.com"
41+
42+
- name: Ensure Formula directory exists
43+
run: mkdir -p homebrew-tap/Formula
44+
45+
- name: Update Homebrew formula
46+
run: |
47+
FORMULA_PATH="homebrew-tap/Formula/ch.rb"
48+
cat > "$FORMULA_PATH" <<EOF
49+
class Ch < Formula
50+
desc "Cheatsheet generator with markdown rendering"
51+
homepage "https://github.com/nicholascross/ch.sh"
52+
url "https://github.com/nicholascross/ch.sh/archive/refs/tags/\${LATEST_TAG}.tar.gz"
53+
sha256 "\${SHA256}"
54+
version "\${LATEST_TAG}"
55+
56+
depends_on "glow"
57+
depends_on "nicholascross/promptly/promptly"
58+
depends_on "fzf"
59+
60+
def install
61+
bin.install "ch.sh" => "ch"
62+
pkgshare.install "theme.json"
63+
end
64+
65+
def post_install
66+
config_path = File.join(ENV["HOME"], ".config", "ch.sh")
67+
mkdir_p config_path
68+
cp pkgshare/"theme.json", File.join(config_path, "theme.json")
69+
end
70+
71+
test do
72+
assert_predicate bin/"ch", :executable?
73+
assert_match "Usage", shell_output("\#{bin}/ch --help")
74+
end
75+
76+
def caveats
77+
<<~EOS
78+
A default theme has been installed to:
79+
\#{ENV["HOME"]}/.config/ch.sh/theme.json
80+
81+
You can edit this file to customize your theme.
82+
EOS
83+
end
84+
end
85+
EOF
86+
echo "Homebrew formula updated"
87+
88+
- name: Commit and push changes to Homebrew tap
89+
run: |
90+
cd homebrew-tap
91+
git add Formula/ch.rb
92+
git commit -m "Update ch.sh formula to version \${LATEST_TAG}"
93+
git push origin main

0 commit comments

Comments
 (0)