1
+ name : Update Homebrew Tap
2
+
3
+ on :
4
+ release :
5
+ types : [published, edited, released]
6
+ push :
7
+ tags :
8
+ - ' v*'
9
+
10
+ jobs :
11
+ update-tap :
12
+ runs-on : macos-latest
13
+ steps :
14
+ - name : Checkout tap
15
+ uses : actions/checkout@v4
16
+ with :
17
+ repository : ygsgdbd/homebrew-tap
18
+ token : ${{ secrets.TAP_TOKEN }}
19
+ path : homebrew-tap
20
+
21
+ - name : Get release info
22
+ id : release
23
+ run : |
24
+ # 获取版本号(移除 v 前缀如果存在)
25
+ VERSION=${GITHUB_REF#refs/tags/}
26
+ VERSION=${VERSION#v}
27
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
28
+
29
+ # 构建下载 URL 并验证文件是否存在
30
+ DOWNLOAD_URL="https://github.com/ygsgdbd/DanceKunKun/releases/download/${GITHUB_REF#refs/tags/}/DanceKunKun.dmg"
31
+ HTTP_STATUS=$(curl -L -s -o DanceKunKun.dmg -w "%{http_code}" "$DOWNLOAD_URL")
32
+
33
+ if [ "$HTTP_STATUS" != "200" ]; then
34
+ echo "::error::Failed to download DMG file. HTTP status: $HTTP_STATUS"
35
+ exit 1
36
+ fi
37
+
38
+ # 计算 SHA256
39
+ SHA256=$(shasum -a 256 DanceKunKun.dmg | cut -d ' ' -f 1)
40
+ if [ -z "$SHA256" ]; then
41
+ echo "::error::Failed to calculate SHA256"
42
+ exit 1
43
+ fi
44
+ echo "sha256=$SHA256" >> $GITHUB_OUTPUT
45
+
46
+ # 输出信息用于调试
47
+ echo "Version: $VERSION"
48
+ echo "SHA256: $SHA256"
49
+
50
+ - name : Verify tap directory
51
+ run : |
52
+ cd homebrew-tap
53
+ mkdir -p Casks
54
+ if [ ! -d "Casks" ]; then
55
+ echo "::error::Failed to create Casks directory"
56
+ exit 1
57
+ fi
58
+
59
+ - name : Update formula
60
+ run : |
61
+ cd homebrew-tap
62
+ cat > Casks/dancekunkun.rb << EOL
63
+ cask "dancekunkun" do
64
+ version "${{ steps.release.outputs.version }}"
65
+ sha256 "${{ steps.release.outputs.sha256 }}"
66
+
67
+ url "https://github.com/ygsgdbd/DanceKunKun/releases/download/v#{version}/DanceKunKun.dmg"
68
+ name "DanceKunKun"
69
+ desc "A fun macOS menu bar app featuring a dancing Cai Xukun that grooves to your CPU usage"
70
+ homepage "https://github.com/ygsgdbd/DanceKunKun"
71
+
72
+ auto_updates false
73
+ depends_on macos: ">= :ventura"
74
+
75
+ app "DanceKunKun.app"
76
+
77
+ zap trash: [
78
+ "~/Library/Application Support/DanceKunKun",
79
+ "~/Library/Preferences/top.ygsgdbd.DanceKunKun.plist",
80
+ "~/Library/Caches/top.ygsgdbd.DanceKunKun"
81
+ ]
82
+ end
83
+ EOL
84
+
85
+ - name : Verify formula
86
+ run : |
87
+ cd homebrew-tap
88
+ if [ ! -f "Casks/dancekunkun.rb" ]; then
89
+ echo "::error::Formula file was not created"
90
+ exit 1
91
+ fi
92
+
93
+ # 简单的语法检查
94
+ ruby -c Casks/dancekunkun.rb || {
95
+ echo "::error::Ruby syntax check failed"
96
+ exit 1
97
+ }
98
+
99
+ - name : Commit and push changes
100
+ run : |
101
+ cd homebrew-tap
102
+ git config user.name "GitHub Action Bot"
103
+ git config user.email "github-actions[bot]@users.noreply.github.com"
104
+
105
+ # 检查是否有变更
106
+ if git diff --quiet; then
107
+ echo "No changes to commit"
108
+ exit 0
109
+ fi
110
+
111
+ git add Casks/dancekunkun.rb
112
+ git commit -m "Update dancekunkun to ${{ steps.release.outputs.version }}"
113
+
114
+ # 添加重试逻辑
115
+ MAX_RETRIES=3
116
+ RETRY_COUNT=0
117
+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
118
+ if git push; then
119
+ echo "Successfully pushed changes"
120
+ exit 0
121
+ fi
122
+ RETRY_COUNT=$((RETRY_COUNT+1))
123
+ if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
124
+ echo "Push failed, retrying in 5 seconds..."
125
+ sleep 5
126
+ fi
127
+ done
128
+
129
+ echo "::error::Failed to push changes after $MAX_RETRIES attempts"
130
+ exit 1
0 commit comments