-
Notifications
You must be signed in to change notification settings - Fork 28
177 lines (142 loc) · 6.55 KB
/
update-homebrew.yml
File metadata and controls
177 lines (142 loc) · 6.55 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: 更新 Homebrew 配方
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag_name:
description: 发布标签名称 (例如 v0.2.3)
required: true
type: string
jobs:
update-homebrew:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: 获取发布信息
id: release_info
run: |
if [ "${{ github.event_name }}" = "release" ]; then
TAG_NAME="${{ github.event.release.tag_name }}"
else
TAG_NAME="${{ github.event.inputs.tag_name }}"
fi
VERSION_NUMBER=${TAG_NAME#v}
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "version_number=${VERSION_NUMBER}" >> $GITHUB_OUTPUT
echo "Release tag: ${TAG_NAME}"
echo "Version number: ${VERSION_NUMBER}"
- name: 验证发布资源是否存在
run: |
TAG_NAME="${{ steps.release_info.outputs.tag_name }}"
VERSION_NUMBER="${{ steps.release_info.outputs.version_number }}"
# 检查 release assets 是否存在
# URL 格式:/download/{TAG_NAME}/sanshu-cli-{TAG_NAME}-{platform}.tar.gz
INTEL_URL="https://github.com/yuaotian/sanshu/releases/download/${TAG_NAME}/sanshu-cli-${TAG_NAME}-macos-x86_64.tar.gz"
ARM_URL="https://github.com/yuaotian/sanshu/releases/download/${TAG_NAME}/sanshu-cli-${TAG_NAME}-macos-aarch64.tar.gz"
echo "Checking Intel asset: $INTEL_URL"
if ! curl --head --fail "$INTEL_URL" > /dev/null 2>&1; then
echo "❌ Intel asset not found: $INTEL_URL"
exit 1
fi
echo "Checking ARM asset: $ARM_URL"
if ! curl --head --fail "$ARM_URL" > /dev/null 2>&1; then
echo "❌ ARM asset not found: $ARM_URL"
exit 1
fi
echo "✅ All release assets verified"
- name: 计算发布资源的 SHA256
id: sha256
run: |
TAG_NAME="${{ steps.release_info.outputs.tag_name }}"
VERSION_NUMBER="${{ steps.release_info.outputs.version_number }}"
INTEL_URL="https://github.com/yuaotian/sanshu/releases/download/${TAG_NAME}/sanshu-cli-${TAG_NAME}-macos-x86_64.tar.gz"
ARM_URL="https://github.com/yuaotian/sanshu/releases/download/${TAG_NAME}/sanshu-cli-${TAG_NAME}-macos-aarch64.tar.gz"
echo "Downloading and calculating SHA256..."
# 下载并计算 SHA256
curl -L -o /tmp/intel.tar.gz "$INTEL_URL"
curl -L -o /tmp/arm.tar.gz "$ARM_URL"
INTEL_SHA256=$(sha256sum /tmp/intel.tar.gz | cut -d' ' -f1)
ARM_SHA256=$(sha256sum /tmp/arm.tar.gz | cut -d' ' -f1)
echo "intel_sha256=${INTEL_SHA256}" >> $GITHUB_OUTPUT
echo "arm_sha256=${ARM_SHA256}" >> $GITHUB_OUTPUT
echo "intel_url=${INTEL_URL}" >> $GITHUB_OUTPUT
echo "arm_url=${ARM_URL}" >> $GITHUB_OUTPUT
echo "Intel SHA256: $INTEL_SHA256"
echo "ARM SHA256: $ARM_SHA256"
- name: 检出 homebrew-sanshu 仓库
uses: actions/checkout@v4
with:
repository: yuaotian/homebrew-sanshu
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
path: homebrew-tap
- name: 配置 homebrew-tap 的 Git
run: |
cd homebrew-tap
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
- name: 更新 Homebrew 配方
run: |
TAG_NAME="${{ steps.release_info.outputs.tag_name }}"
VERSION_NUMBER="${{ steps.release_info.outputs.version_number }}"
INTEL_SHA256="${{ steps.sha256.outputs.intel_sha256 }}"
ARM_SHA256="${{ steps.sha256.outputs.arm_sha256 }}"
INTEL_URL="${{ steps.sha256.outputs.intel_url }}"
ARM_URL="${{ steps.sha256.outputs.arm_url }}"
cd homebrew-tap
# 确保 Formula 文件存在
if [[ ! -f "Formula/sanshu.rb" ]]; then
echo "❌ Error: Formula/sanshu.rb not found in tap repository"
exit 1
fi
echo "Updating Formula with:"
echo " Version: ${VERSION_NUMBER}"
echo " Intel URL: ${INTEL_URL}"
echo " Intel SHA256: ${INTEL_SHA256}"
echo " ARM URL: ${ARM_URL}"
echo " ARM SHA256: ${ARM_SHA256}"
# 更新版本号
sed -i "s|version \".*\"|version \"${VERSION_NUMBER}\"|g" Formula/sanshu.rb
# 更新 Intel 版本的 URL 和 SHA256(适配新的 on_intel 语法)
sed -i "s|https://github.com/yuaotian/sanshu/releases/download/v[0-9.]*/sanshu-cli-v[0-9.]*-macos-x86_64.tar.gz|${INTEL_URL}|g" Formula/sanshu.rb
sed -i "/on_intel do/,/end/ { /sha256/ s|sha256[[:space:]]*\".*\"|sha256 \"${INTEL_SHA256}\"|; }" Formula/sanshu.rb
# 更新 ARM 版本的 URL 和 SHA256(适配新的 on_arm 语法)
sed -i "s|https://github.com/yuaotian/sanshu/releases/download/v[0-9.]*/sanshu-cli-v[0-9.]*-macos-aarch64.tar.gz|${ARM_URL}|g" Formula/sanshu.rb
sed -i "/on_arm do/,/end/ { /sha256/ s|sha256[[:space:]]*\".*\"|sha256 \"${ARM_SHA256}\"|; }" Formula/sanshu.rb
- name: 验证配方更改
run: |
cd homebrew-tap
echo "=== Formula changes ==="
git diff Formula/sanshu.rb || true
echo "=== Updated Formula content ==="
cat Formula/sanshu.rb
- name: 提交并推送到 homebrew-sanshu 仓库
run: |
TAG_NAME="${{ steps.release_info.outputs.tag_name }}"
VERSION_NUMBER="${{ steps.release_info.outputs.version_number }}"
cd homebrew-tap
# 检查是否有更改
if git diff --quiet Formula/sanshu.rb; then
echo "No changes to Formula, skipping commit"
exit 0
fi
# 提交并推送更改
git add Formula/sanshu.rb
git commit -m "chore: update formula to ${TAG_NAME}
- Update version to ${VERSION_NUMBER}
- Update download URLs and SHA256 checksums
- Auto-generated by update-homebrew workflow"
git push origin main
echo "✅ Successfully updated homebrew-sanshu repository"
- name: 测试配方 (可选)
run: |
echo "🧪 Formula update completed successfully!"
echo "You can test the formula with:"
echo " brew tap yuaotian/sanshu"
echo " brew install sanshu"