Skip to content

Commit eb6536d

Browse files
committed
ci: add update formula action
1 parent a55da72 commit eb6536d

4 files changed

Lines changed: 120 additions & 95 deletions

File tree

.github/workflows/publish.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Pinc < Formula
2+
desc "Component based CMS with git like principles"
3+
homepage "https://github.com/pinc-official/pinc-playground"
4+
license "MIT"
5+
6+
depends_on "vips"
7+
8+
bottle do
9+
root_url "${BASE_URL}"
10+
${BOTTLE_LINES} end
11+
12+
depends_on "vips"
13+
14+
def install
15+
bin.install "bin/pinc"
16+
end
17+
18+
test do
19+
system "#{bin}/pinc", "--version"
20+
end
21+
end

.github/workflows/tests.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Update Formula
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
- edited
8+
9+
jobs:
10+
check-assets:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
has_darwin_amd64: ${{ steps.check.outputs.has_darwin_amd64 }}
14+
has_darwin_arm64: ${{ steps.check.outputs.has_darwin_arm64 }}
15+
has_linux_arm64: ${{ steps.check.outputs.has_linux_arm64 }}
16+
has_linux_amd64: ${{ steps.check.outputs.has_linux_amd64 }}
17+
steps:
18+
- name: Check available assets
19+
id: check
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
VERSION: ${{ github.event.release.tag_name }}
23+
run: |
24+
gh release view "${VERSION}" --repo "${{ github.repository }}" --json assets --jq '.assets[].name' > assets.txt
25+
cat assets.txt
26+
27+
grep -q "pinc-${VERSION}-darwin-amd64.tar.gz" assets.txt \
28+
&& echo "has_darwin_amd64=true" >> $GITHUB_OUTPUT \
29+
|| echo "has_darwin_amd64=false" >> $GITHUB_OUTPUT
30+
31+
grep -q "pinc-${VERSION}-darwin-arm64.tar.gz" assets.txt \
32+
&& echo "has_darwin_arm64=true" >> $GITHUB_OUTPUT \
33+
|| echo "has_darwin_arm64=false" >> $GITHUB_OUTPUT
34+
35+
grep -q "pinc-${VERSION}-linux-amd64.tar.gz" assets.txt \
36+
&& echo "has_linux_amd64=true" >> $GITHUB_OUTPUT \
37+
|| echo "has_linux_amd64=false" >> $GITHUB_OUTPUT
38+
39+
grep -q "pinc-${VERSION}-linux-arm64.tar.gz" assets.txt \
40+
&& echo "has_linux_arm64=true" >> $GITHUB_OUTPUT \
41+
|| echo "has_linux_arm64=false" >> $GITHUB_OUTPUT
42+
43+
update-formula:
44+
needs: check-assets
45+
runs-on: ubuntu-latest
46+
env:
47+
VERSION: ${{ github.event.release.tag_name }}
48+
BASE_URL: 'https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}'
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v6
53+
with:
54+
ref: main
55+
56+
- name: Download assets
57+
run: |
58+
gh release download "${VERSION}" \
59+
--repo "${{ github.repository }}" \
60+
--pattern "*.tar.gz" || true
61+
62+
- name: Compute SHA256s
63+
id: sha256
64+
run: |
65+
for PLATFORM in darwin-amd64 darwin-arm64 linux-amd64 linux-arm64; do
66+
FILE="pinc-${VERSION}-${PLATFORM}.tar.gz"
67+
if [ -f "${FILE}" ]; then
68+
SHA=$(sha256sum "${FILE}" | awk '{print $1}')
69+
echo "${PLATFORM//-/_}=${SHA}" >> $GITHUB_OUTPUT
70+
fi
71+
done
72+
73+
- name: Update formula
74+
run: |
75+
BOTTLE_LINES=""
76+
if [ "${{ needs.check-assets.outputs.has_darwin_arm64 }}" == "true" ]; then
77+
BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, arm64_sequoia: \"${{ steps.sha256.outputs.darwin_arm64 }}\"\n"
78+
fi
79+
if [ "${{ needs.check-assets.outputs.has_darwin_amd64 }}" == "true" ]; then
80+
BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, sequoia: \"${{ steps.sha256.outputs.darwin_amd64 }}\"\n"
81+
fi
82+
if [ "${{ needs.check-assets.outputs.has_linux_amd64 }}" == "true" ]; then
83+
BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, x86_64_linux: \"${{ steps.sha256.outputs.linux_amd64 }}\"\n"
84+
fi
85+
if [ "${{ needs.check-assets.outputs.has_linux_arm64 }}" == "true" ]; then
86+
BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, arm64_linux: \"${{ steps.sha256.outputs.linux_arm64 }}\"\n"
87+
fi
88+
89+
export BASE_URL
90+
export BOTTLE_LINES=$(printf "${BOTTLE_LINES}")
91+
envsubst < .github/workflows/templates/pinc.rb.template > Formula/pinc.rb
92+
93+
- name: Commit and push formula
94+
run: |
95+
git config user.name "github-actions[bot]"
96+
git config user.email "github-actions[bot]@users.noreply.github.com"
97+
git add Formula/pinc.rb
98+
git commit -m "pinc ${VERSION}"
99+
git push

0 commit comments

Comments
 (0)