Skip to content

Commit 77cd301

Browse files
committed
Add GitHub Actions workflows for Homebrew formula updates and tap setup
1 parent ef1c358 commit 77cd301

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

.github/workflows/homebrew.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Update Homebrew Formula
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
update-formula:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
14+
- name: Set up environment
15+
run: |
16+
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
17+
echo "DARWIN_ARM64_URL=https://github.com/mxvsh/cpw/releases/download/${GITHUB_REF#refs/tags/}/cpw-darwin-arm64" >> $GITHUB_ENV
18+
echo "LINUX_ARM64_URL=https://github.com/mxvsh/cpw/releases/download/${GITHUB_REF#refs/tags/}/cpw-linux-arm64" >> $GITHUB_ENV
19+
echo "LINUX_ARM_URL=https://github.com/mxvsh/cpw/releases/download/${GITHUB_REF#refs/tags/}/cpw-linux-armv7" >> $GITHUB_ENV
20+
21+
- name: Download binaries and calculate checksums
22+
run: |
23+
mkdir -p ./bin
24+
curl -L $DARWIN_ARM64_URL -o ./bin/cpw-darwin-arm64
25+
curl -L $LINUX_ARM64_URL -o ./bin/cpw-linux-arm64
26+
curl -L $LINUX_ARM_URL -o ./bin/cpw-linux-armv7
27+
28+
DARWIN_ARM64_SHA256=$(sha256sum ./bin/cpw-darwin-arm64 | awk '{print $1}')
29+
LINUX_ARM64_SHA256=$(sha256sum ./bin/cpw-linux-arm64 | awk '{print $1}')
30+
LINUX_ARM_SHA256=$(sha256sum ./bin/cpw-linux-armv7 | awk '{print $1}')
31+
32+
echo "DARWIN_ARM64_SHA256=$DARWIN_ARM64_SHA256" >> $GITHUB_ENV
33+
echo "LINUX_ARM64_SHA256=$LINUX_ARM64_SHA256" >> $GITHUB_ENV
34+
echo "LINUX_ARM_SHA256=$LINUX_ARM_SHA256" >> $GITHUB_ENV
35+
36+
- name: Update Homebrew formula
37+
run: |
38+
sed -i "s/VERSION_PLACEHOLDER/$VERSION/g" Formula/cpw.rb
39+
sed -i "s/SHA256_PLACEHOLDER_DARWIN_ARM64/$DARWIN_ARM64_SHA256/g" Formula/cpw.rb
40+
sed -i "s/SHA256_PLACEHOLDER_LINUX_ARM64/$LINUX_ARM64_SHA256/g" Formula/cpw.rb
41+
sed -i "s/SHA256_PLACEHOLDER_LINUX_ARM/$LINUX_ARM_SHA256/g" Formula/cpw.rb
42+
43+
cat Formula/cpw.rb
44+
45+
- name: Clone tap repository
46+
run: |
47+
git config --global user.email "action@github.com"
48+
git config --global user.name "GitHub Action"
49+
git clone https://github.com/${{ github.repository_owner }}/homebrew-cpw.git tap
50+
51+
- name: Update formula in tap
52+
run: |
53+
mkdir -p tap/Formula
54+
cp Formula/cpw.rb tap/Formula/
55+
56+
- name: Commit and push to tap
57+
working-directory: ./tap
58+
run: |
59+
git add Formula/cpw.rb
60+
git commit -m "Update cpw formula to v${{ env.VERSION }}"
61+
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository_owner }}/homebrew-cpw.git

.github/workflows/setup_tap.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Setup Homebrew Tap
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
create_repo:
7+
description: 'Create tap repository if it does not exist'
8+
required: true
9+
default: 'true'
10+
11+
jobs:
12+
setup-tap:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Create tap repository
19+
if: ${{ github.event.inputs.create_repo == 'true' }}
20+
uses: actions/github-script@v6
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
script: |
24+
try {
25+
const { data } = await github.rest.repos.get({
26+
owner: context.repo.owner,
27+
repo: 'homebrew-cpw'
28+
});
29+
console.log('Tap repository already exists');
30+
} catch (error) {
31+
if (error.status === 404) {
32+
console.log('Creating tap repository...');
33+
const { data } = await github.rest.repos.createInOrg({
34+
org: context.repo.owner,
35+
name: 'homebrew-cpw',
36+
description: 'Homebrew tap for CPW - Copy on Write file watcher',
37+
private: false,
38+
auto_init: true
39+
});
40+
console.log('Tap repository created: ' + data.html_url);
41+
} else {
42+
console.error('Error checking repository:', error);
43+
process.exit(1);
44+
}
45+
}
46+
47+
- name: Setup Git
48+
run: |
49+
git config --global user.email "action@github.com"
50+
git config --global user.name "GitHub Action"
51+
52+
- name: Clone tap repository
53+
run: |
54+
git clone https://github.com/${{ github.repository_owner }}/homebrew-cpw.git tap
55+
56+
- name: Create formula directory
57+
run: |
58+
mkdir -p tap/Formula
59+
60+
- name: Copy formula template
61+
run: |
62+
cp Formula/cpw.rb tap/Formula/
63+
64+
- name: Commit and push
65+
working-directory: ./tap
66+
run: |
67+
git add Formula/cpw.rb
68+
git commit -m "Initial formula setup" || echo "No changes to commit"
69+
git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository_owner }}/homebrew-cpw.git

0 commit comments

Comments
 (0)