-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (116 loc) · 4.24 KB
/
homebrew-formula.yml
File metadata and controls
128 lines (116 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Homebrew Formula
on:
release:
types:
- published
workflow_dispatch:
inputs:
tag:
description: "Release tag to publish (for example v0.1.0). Defaults to latest tag on current ref."
required: false
type: string
permissions:
contents: read
jobs:
generate-formula:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve tag
id: meta
shell: bash
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
INPUT_TAG: ${{ github.event.inputs.tag }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
if [ -n "${RELEASE_TAG:-}" ]; then
tag="${RELEASE_TAG}"
elif [ -n "${INPUT_TAG:-}" ]; then
tag="${INPUT_TAG}"
else
tag="${REF_NAME}"
fi
case "${tag}" in
v*) ;;
*)
echo "Tag must start with 'v' (got: ${tag})" >&2
exit 1
;;
esac
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
- name: Build formula from release assets
shell: bash
run: |
set -euo pipefail
tag="${{ steps.meta.outputs.tag }}"
version="${{ steps.meta.outputs.version }}"
source_repo="iamyxsh/fishnet"
base_url="https://github.com/${source_repo}/releases/download/${tag}"
mac_arm_archive="fishnet-aarch64-apple-darwin.tar.gz"
mac_x64_archive="fishnet-x86_64-apple-darwin.tar.gz"
linux_x64_archive="fishnet-x86_64-unknown-linux-gnu.tar.gz"
mac_arm_sha="$(curl -fsSL "${base_url}/${mac_arm_archive}.sha256" | awk '{print $1; exit}')"
mac_x64_sha="$(curl -fsSL "${base_url}/${mac_x64_archive}.sha256" | awk '{print $1; exit}')"
linux_x64_sha="$(curl -fsSL "${base_url}/${linux_x64_archive}.sha256" | awk '{print $1; exit}')"
mkdir -p dist
scripts/generate-homebrew-formula.sh \
"${version}" \
"${base_url}/${mac_arm_archive}" "${mac_arm_sha}" \
"${base_url}/${mac_x64_archive}" "${mac_x64_sha}" \
"${base_url}/${linux_x64_archive}" "${linux_x64_sha}" \
> dist/fishnet.rb
- name: Upload generated formula
uses: actions/upload-artifact@v4
with:
name: homebrew-formula-${{ steps.meta.outputs.tag }}
path: dist/fishnet.rb
publish-to-tap:
if: ${{ vars.HOMEBREW_TAP_REPOSITORY != '' }}
needs: generate-formula
runs-on: ubuntu-latest
steps:
- name: Check tap token
id: check-token
run: |
if [ -n "${TAP_TOKEN}" ]; then
echo "has_token=true" >> "$GITHUB_OUTPUT"
else
echo "has_token=false" >> "$GITHUB_OUTPUT"
echo "::warning::HOMEBREW_TAP_TOKEN not configured — skipping tap publish."
fi
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Download formula artifact
if: steps.check-token.outputs.has_token == 'true'
uses: actions/download-artifact@v4
with:
name: homebrew-formula-${{ needs.generate-formula.outputs.tag }}
path: dist
- name: Publish formula to tap repository
if: steps.check-token.outputs.has_token == 'true'
shell: bash
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
TAP_REPO: ${{ vars.HOMEBREW_TAP_REPOSITORY }}
RELEASE_TAG: ${{ needs.generate-formula.outputs.tag }}
run: |
set -euo pipefail
git clone "https://x-access-token:${TAP_TOKEN}@github.com/${TAP_REPO}.git" tap
mkdir -p tap/Formula
cp dist/fishnet.rb tap/Formula/fishnet.rb
cd tap
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/fishnet.rb
if git diff --cached --quiet; then
echo "No formula changes detected."
exit 0
fi
git commit -m "fishnet: update formula for ${RELEASE_TAG}"
git push origin HEAD