-
Notifications
You must be signed in to change notification settings - Fork 12
259 lines (213 loc) · 9.7 KB
/
Copy pathpush-to-homebrew-tap.yml
File metadata and controls
259 lines (213 loc) · 9.7 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: Push to Homebrew Tap
# Support manual trigger with parameters to control whether to execute push
on:
workflow_dispatch:
inputs:
push_to_tap:
description: 'Push rb file to homebrew-agb repository (true/false)'
required: true
type: boolean
default: false
version:
description: 'Version for the Formula (optional, will use latest tag if not provided)'
required: false
type: string
default: ''
# Permission settings
permissions:
contents: read
actions: read
# Environment variables
env:
HOMEBREW_TAP_REPO: 'homebrew-agb' # Target repository name
SOURCE_RB_PATH: 'homebrew/agb.rb' # Source rb file path
TARGET_RB_PATH: 'Formula/agb.rb' # Target rb file path
jobs:
push-to-homebrew-tap:
name: Push Formula to Homebrew Tap
runs-on: ubuntu-latest
timeout-minutes: 15
# Only execute when parameter is true
if: ${{ github.event.inputs.push_to_tap == 'true' }}
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Git configuration
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com"
- name: Validate source rb file
run: |
echo "Checking source rb file..."
if [[ ! -f "${{ env.SOURCE_RB_PATH }}" ]]; then
echo "❌ Source rb file not found: ${{ env.SOURCE_RB_PATH }}"
exit 1
fi
echo "✅ Source rb file found: ${{ env.SOURCE_RB_PATH }}"
echo "File content preview:"
head -10 "${{ env.SOURCE_RB_PATH }}"
- name: Determine version
id: version
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
if [[ -n "${{ github.event.inputs.version }}" ]]; then
INPUT_VERSION="${{ github.event.inputs.version }}"
echo "Validating input version: $INPUT_VERSION"
# Verify if version exists in GitHub releases
RELEASE_EXISTS=$(gh api repos/${{ github.repository }}/releases/tags/v$INPUT_VERSION --silent 2>/dev/null && echo "true" || echo "false")
if [[ "$RELEASE_EXISTS" == "true" ]]; then
VERSION="$INPUT_VERSION"
echo "✅ Version v$VERSION found in releases"
else
echo "❌ Version v$INPUT_VERSION not found in GitHub releases"
echo "Available releases:"
gh api repos/${{ github.repository }}/releases --jq '.[].tag_name' | head -10
exit 1
fi
else
# Read current version number from rb file
echo "Reading version from rb file: ${{ env.SOURCE_RB_PATH }}"
if [[ ! -f "${{ env.SOURCE_RB_PATH }}" ]]; then
echo "❌ Source rb file not found: ${{ env.SOURCE_RB_PATH }}"
exit 1
fi
# Extract version number from rb file (looking for url "...v1.2.3.tar.gz" format)
VERSION=$(grep -o 'tags/v[0-9]\+\.[0-9]\+\.[0-9]\+' "${{ env.SOURCE_RB_PATH }}" | head -1 | sed 's/tags\/v//')
if [[ -z "$VERSION" ]]; then
echo "❌ Could not extract version from rb file"
echo "Rb file content:"
cat "${{ env.SOURCE_RB_PATH }}"
exit 1
fi
echo "✅ Using version from rb file: $VERSION"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Final version: $VERSION"
- name: Update rb file with current version
# Only execute update operation when user manually inputs version number
if: ${{ github.event.inputs.version != '' }}
run: |
echo "Updating rb file with version $VERSION..."
# Create temporary file to update version information
cp "${{ env.SOURCE_RB_PATH }}" /tmp/agb.rb.tmp
# Update version number (if rb file contains version information)
sed -i "s/version \"[^\"]*\"/version \"$VERSION\"/g" /tmp/agb.rb.tmp
# Update version tag in URL
sed -i "s|/tags/v[^/]*/|/tags/v$VERSION/|g" /tmp/agb.rb.tmp
echo "Updated rb file content:"
echo "========================"
cat /tmp/agb.rb.tmp
echo "========================"
- name: Use existing rb file (no version update)
# When user doesn't input version number, directly use existing rb file
if: ${{ github.event.inputs.version == '' }}
run: |
echo "Using existing rb file without version update..."
echo "Version will be read from existing rb file: $VERSION"
# Directly copy existing rb file
cp "${{ env.SOURCE_RB_PATH }}" /tmp/agb.rb.tmp
echo "Existing rb file content:"
echo "========================"
cat /tmp/agb.rb.tmp
echo "========================"
- name: Clone or create homebrew-agb repository
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
echo "Cloning homebrew-agb repository..."
echo "Repository URL: https://github.com/agbcloud/${{ env.HOMEBREW_TAP_REPO }}.git"
# Clone target repository
git clone "https://x-access-token:${{ secrets.HOMEBREW_TAP_TOKEN }}@github.com/agbcloud/${{ env.HOMEBREW_TAP_REPO }}.git" homebrew-tap
echo "✅ Successfully cloned homebrew-agb repository"
# Display repository information
cd homebrew-tap
echo "Current branch: $(git branch --show-current)"
echo "Repository structure:"
ls -la
cd ..
- name: Update Formula in homebrew-agb repository
run: |
echo "Updating Formula in homebrew-agb repository..."
cd homebrew-tap
# Check if Formula directory exists
if [[ -d "Formula" ]]; then
echo "✅ Formula directory already exists"
else
echo "📁 Formula directory not found, creating it..."
mkdir -p Formula
echo "✅ Formula directory created successfully"
fi
# Verify Formula directory actually exists
if [[ ! -d "Formula" ]]; then
echo "❌ Failed to create Formula directory"
exit 1
fi
# Copy updated rb file to target location
cp /tmp/agb.rb.tmp "${{ env.TARGET_RB_PATH }}"
echo "✅ Formula file updated at ${{ env.TARGET_RB_PATH }}"
# Display file content for confirmation
echo "Updated Formula content:"
echo "========================"
cat "${{ env.TARGET_RB_PATH }}"
echo "========================"
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
cd homebrew-tap
echo "📝 Preparing to commit and push Formula file..."
# Add changes (regardless of whether there are actual changes)
git add "${{ env.TARGET_RB_PATH }}"
# Create commit message
COMMIT_MSG="Update agb formula to version $VERSION
- Updated from source repository: ${{ github.repository }}
- Source file: ${{ env.SOURCE_RB_PATH }}
- Target file: ${{ env.TARGET_RB_PATH }}
- Triggered by: ${{ github.actor }}
- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- Timestamp: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
# Commit changes (allow empty commit)
git commit -m "$COMMIT_MSG" --allow-empty
echo "✅ Formula committed successfully"
# Push to remote repository
echo "Pushing changes to homebrew-agb repository..."
if git push origin main 2>/dev/null || git push origin master 2>/dev/null; then
echo "✅ Successfully pushed Formula to homebrew-agb repository"
else
echo "⚠️ Failed to push to existing branch, trying to create new branch..."
git push -u origin HEAD:main
echo "✅ Successfully created and pushed to main branch"
fi
- name: Summary
run: |
echo ""
echo "🎉 Formula push completed successfully!"
echo ""
echo "📋 Summary:"
echo " - Source repository: ${{ github.repository }}"
echo " - Target repository: agbcloud/${{ env.HOMEBREW_TAP_REPO }}"
echo " - Formula version: $VERSION"
echo " - Source file: ${{ env.SOURCE_RB_PATH }}"
echo " - Target file: ${{ env.TARGET_RB_PATH }}"
echo ""
echo "🍺 Users can now install with:"
echo " brew tap agbcloud/${{ env.HOMEBREW_TAP_REPO }}"
echo " brew install agb"
echo ""
echo "🔗 Repository URL:"
echo " https://github.com/agbcloud/${{ env.HOMEBREW_TAP_REPO }}"
# Show skip information when parameter is false
skip-push:
name: Skip Push (Parameter is false)
runs-on: ubuntu-latest
if: ${{ github.event.inputs.push_to_tap != 'true' }}
steps:
- name: Skip message
run: |
echo "⏭️ Skipping push to agbcloud-homebrew repository"
echo " Reason: push_to_tap parameter is set to '${{ github.event.inputs.push_to_tap }}'"
echo " To enable push, set the parameter to 'true' when running this workflow manually"