Skip to content

Commit 54ac0f5

Browse files
committed
ci: automate homebrew tap updates
1 parent 5bef8b6 commit 54ac0f5

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.github/workflows/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,44 @@ jobs:
3535
- run: node -v
3636
- run: npm -v
3737
- run: npm publish --provenance
38+
39+
update-homebrew-tap:
40+
needs: publish-npm
41+
if: startsWith(github.ref, 'refs/tags/v')
42+
runs-on: ubuntu-latest
43+
permissions:
44+
contents: read
45+
env:
46+
TAP_REPO: luckfunc/homebrew-tap
47+
FORMULA_PATH: Formula/kill-port-process-cli.rb
48+
steps:
49+
- uses: actions/checkout@v5
50+
- uses: actions/setup-node@v6
51+
with:
52+
node-version: 24
53+
- name: Resolve release version
54+
run: |
55+
VERSION="${GITHUB_REF_NAME#v}"
56+
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
57+
echo "TARBALL_URL=https://registry.npmjs.org/kill-port-process-cli/-/kill-port-process-cli-$VERSION.tgz" >> "$GITHUB_ENV"
58+
- name: Compute tarball sha256
59+
run: |
60+
curl -fsSL "$TARBALL_URL" -o package.tgz
61+
echo "SHA256=$(shasum -a 256 package.tgz | awk '{print $1}')" >> "$GITHUB_ENV"
62+
- name: Clone tap repository
63+
env:
64+
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
65+
run: |
66+
git clone "https://x-access-token:${HOMEBREW_TAP_GITHUB_TOKEN}@github.com/${TAP_REPO}.git" ../homebrew-tap
67+
- name: Update formula
68+
run: |
69+
node scripts/update-homebrew-formula.js "../homebrew-tap/${FORMULA_PATH}" "$VERSION" "$SHA256"
70+
- name: Commit and push formula update
71+
working-directory: ../homebrew-tap
72+
run: |
73+
git config user.name "github-actions[bot]"
74+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
75+
git add "${FORMULA_PATH}"
76+
git diff --cached --quiet && exit 0
77+
git commit -m "chore: bump kill-port-process-cli to ${VERSION}"
78+
git push origin HEAD:main

scripts/update-homebrew-formula.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
5+
const [, , formulaPath, version, sha256] = process.argv;
6+
7+
if (!formulaPath || !version || !sha256) {
8+
console.error('Usage: node scripts/update-homebrew-formula.js <formulaPath> <version> <sha256>');
9+
process.exit(1);
10+
}
11+
12+
const packageName = 'kill-port-process-cli';
13+
const tarballUrl = `https://registry.npmjs.org/${packageName}/-/${packageName}-${version}.tgz`;
14+
15+
const formula = fs.readFileSync(formulaPath, 'utf8');
16+
const nextFormula = formula
17+
.replace(/url "https:\/\/registry\.npmjs\.org\/kill-port-process-cli\/-\/kill-port-process-cli-[^"]+\.tgz"/, `url "${tarballUrl}"`)
18+
.replace(/sha256 "[^"]+"/, `sha256 "${sha256}"`);
19+
20+
if (formula === nextFormula) {
21+
console.log(`Formula already points to ${version}`);
22+
process.exit(0);
23+
}
24+
25+
fs.writeFileSync(formulaPath, nextFormula);
26+
console.log(`Updated formula to ${version}`);

0 commit comments

Comments
 (0)