-
Notifications
You must be signed in to change notification settings - Fork 1
327 lines (282 loc) · 11.7 KB
/
gitlab_webhook_build.yml
File metadata and controls
327 lines (282 loc) · 11.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
name: "GitLab Webhook: Build and Test"
on:
# Triggered by GitLab webhook via repository_dispatch
repository_dispatch:
types:
- gitlab-push
- gitlab-merge-request
- gitlab-tag
# Also allow manual triggering for testing
workflow_dispatch:
inputs:
gitlab_branch:
description: 'GitLab branch to build'
required: false
default: 'enterprise'
gitlab_ref:
description: 'GitLab commit SHA or ref'
required: false
default: ''
run_tests:
description: 'Run tests'
type: boolean
required: false
default: true
permissions:
contents: read
actions: read
checks: write
jobs:
# Job to process GitLab webhook and build
gitlab-webhook-build:
runs-on: ubuntu-latest
steps:
# Checkout artifactory repo (for workflow context)
- name: Checkout artifactory repo
uses: actions/checkout@v4
# Parse GitLab webhook payload
- name: Parse GitLab webhook payload
id: parse_webhook
run: |
echo "Event type: ${{ github.event.action }}"
# Extract information from webhook payload
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
# Check if GitLab template variables were replaced properly
RAW_REF="${{ github.event.client_payload.ref }}"
RAW_USER="${{ github.event.client_payload.user_name }}"
echo "Raw ref from payload: '$RAW_REF'"
echo "Raw user from payload: '$RAW_USER'"
# If template variables weren't replaced (still contain %), use defaults
if [[ "$RAW_REF" == *"%{"* ]] || [ -z "$RAW_REF" ] || [ "$RAW_REF" = "null" ]; then
echo "⚠️ GitLab template variables not replaced, using defaults"
GITLAB_REF="refs/heads/enterprise"
GITLAB_BRANCH="enterprise"
GITLAB_USER="GitLab User"
GITLAB_COMMIT=""
GITLAB_COMMIT_MSG="GitLab webhook trigger (template variables not replaced)"
else
echo "✅ GitLab template variables replaced successfully"
GITLAB_REF="${{ github.event.client_payload.ref }}"
GITLAB_BRANCH=$(echo "$GITLAB_REF" | sed 's|refs/heads/||')
if [ "$GITLAB_BRANCH" = "null" ]; then
GITLAB_BRANCH="enterprise"
GITLAB_REF="refs/heads/enterprise"
fi
GITLAB_USER="${{ github.event.client_payload.user_name }}"
GITLAB_COMMIT="${{ github.event.client_payload.after }}"
GITLAB_COMMIT_MSG="Push to $GITLAB_BRANCH by $GITLAB_USER"
fi
echo "branch=$GITLAB_BRANCH" >> $GITHUB_OUTPUT
echo "commit=$GITLAB_COMMIT" >> $GITHUB_OUTPUT
echo "commit_message=$GITLAB_COMMIT_MSG" >> $GITHUB_OUTPUT
echo "user=$GITLAB_USER" >> $GITHUB_OUTPUT
echo "📡 GitLab Webhook Received"
echo "Branch: $GITLAB_BRANCH"
echo "Commit: $GITLAB_COMMIT"
echo "User: $GITLAB_USER"
echo "Message: $GITLAB_COMMIT_MSG"
else
# Manual trigger
GITLAB_BRANCH="${{ github.event.inputs.gitlab_branch || 'enterprise' }}"
GITLAB_COMMIT="${{ github.event.inputs.gitlab_ref || '' }}"
echo "branch=$GITLAB_BRANCH" >> $GITHUB_OUTPUT
echo "commit=$GITLAB_COMMIT" >> $GITHUB_OUTPUT
echo "commit_message=Manual trigger" >> $GITHUB_OUTPUT
echo "user=${{ github.actor }}" >> $GITHUB_OUTPUT
echo "🔧 Manual Trigger"
echo "Branch: $GITLAB_BRANCH"
fi
# Clone the private GitLab repository
- name: Clone private GitLab repo
id: clone
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
run: |
BRANCH="${{ steps.parse_webhook.outputs.branch }}"
COMMIT="${{ steps.parse_webhook.outputs.commit }}"
echo "🔄 Cloning GitLab repository..."
echo "Branch: $BRANCH"
# Clone the repository
git clone -b $BRANCH https://gitlab-ci-token:${GITLAB_TOKEN}@gitlab.com/chrislusf/seaweedfs.git seaweedfs-source
cd seaweedfs-source
# If specific commit was provided, checkout that commit
if [ -n "$COMMIT" ] && [ "$COMMIT" != "null" ]; then
echo "Checking out specific commit: $COMMIT"
git checkout $COMMIT
fi
# Get commit information
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_SHORT=$(git rev-parse --short=8 HEAD)
COMMIT_MSG=$(git log -1 --pretty=%B)
COMMIT_AUTHOR=$(git log -1 --pretty=%an)
COMMIT_DATE=$(git log -1 --pretty=%ci)
echo "commit_sha=$COMMIT_SHORT" >> $GITHUB_OUTPUT
echo "COMMIT_SHA=$COMMIT_SHORT" >> $GITHUB_ENV
echo "✅ Cloned successfully"
echo "Commit: $COMMIT_SHA"
echo "Author: $COMMIT_AUTHOR"
echo "Date: $COMMIT_DATE"
echo "Message: $COMMIT_MSG"
echo ""
echo "Recent commits:"
git log --oneline -5
# Set up Go environment
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'seaweedfs-source/go.mod'
cache-dependency-path: seaweedfs-source/go.sum
# Verify Go modules
- name: Verify Go modules
working-directory: seaweedfs-source
run: |
echo "🔍 Verifying Go modules..."
go mod verify
go mod download
echo "✅ Modules verified"
# Run Go vet and format checks
- name: Run Go checks
working-directory: seaweedfs-source
run: |
echo "🔍 Running go vet..."
go vet ./weed/... || echo "::warning::go vet found issues"
echo "🔍 Checking go fmt..."
UNFORMATTED=$(gofmt -s -l weed/)
if [ -n "$UNFORMATTED" ]; then
echo "::warning::The following files are not properly formatted:"
echo "$UNFORMATTED"
else
echo "✅ All files are properly formatted"
fi
# Run tests if requested
- name: Run tests
if: github.event.inputs.run_tests != 'false'
working-directory: seaweedfs-source
run: |
echo "🧪 Running tests..."
# Run basic tests with timeout
go test -v -timeout=10m ./weed/storage/... || echo "::warning::Storage tests had failures"
go test -v -timeout=10m ./weed/filer/... || echo "::warning::Filer tests had failures"
go test -v -timeout=10m ./weed/server/... || echo "::warning::Server tests had failures"
echo "✅ Tests completed"
# Build verification binary
- name: Build verification
working-directory: seaweedfs-source
run: |
echo "🔨 Building weed binary for verification..."
CGO_ENABLED=0 go build -o weed-test ./weed
echo "📋 Binary info:"
ls -lh weed-test
./weed-test version
echo "✅ Build successful"
rm weed-test
# Create build summary
- name: Build summary
if: always()
run: |
echo "## 🎯 GitLab Webhook Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📡 Trigger Information" >> $GITHUB_STEP_SUMMARY
echo "- **Event**: ${{ github.event.action || 'manual' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: ${{ steps.parse_webhook.outputs.branch }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ steps.clone.outputs.commit_sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **User**: ${{ steps.parse_webhook.outputs.user }}" >> $GITHUB_STEP_SUMMARY
echo "- **Message**: ${{ steps.parse_webhook.outputs.commit_message }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### ✅ Build Status" >> $GITHUB_STEP_SUMMARY
echo "- **Clone**: ${{ steps.clone.outcome }}" >> $GITHUB_STEP_SUMMARY
echo "- **Go Setup**: Success" >> $GITHUB_STEP_SUMMARY
echo "- **Verification**: Success" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🚀 Build completed successfully!" >> $GITHUB_STEP_SUMMARY
# Optional: Build release binaries for important branches/tags
build-release-binaries:
needs: gitlab-webhook-build
# Only run for enterprise branch or tags
if: |
(github.event.client_payload.ref == 'refs/heads/enterprise') ||
(startsWith(github.event.client_payload.ref, 'refs/tags/')) ||
(github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
steps:
- name: Checkout artifactory repo
uses: actions/checkout@v4
- name: Clone private GitLab repo
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
run: |
BRANCH="${{ github.event.client_payload.ref }}"
if [ -z "$BRANCH" ]; then
BRANCH="enterprise"
else
BRANCH=$(echo "$BRANCH" | sed 's|refs/heads/||' | sed 's|refs/tags/||')
fi
git clone -b $BRANCH https://gitlab-ci-token:${GITLAB_TOKEN}@gitlab.com/chrislusf/seaweedfs.git seaweedfs-source
cd seaweedfs-source
echo "COMMIT_SHA=$(git rev-parse --short=8 HEAD)" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'seaweedfs-source/go.mod'
cache-dependency-path: seaweedfs-source/go.sum
- name: Build binary
working-directory: seaweedfs-source
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
GODEBUG: http2client=0
run: |
BINARY_NAME="weed"
if [ "$GOOS" = "windows" ]; then
BINARY_NAME="weed.exe"
fi
OUTPUT_NAME="weed-enterprise-${GOOS}-${GOARCH}"
if [ "$GOOS" = "windows" ]; then
OUTPUT_NAME="${OUTPUT_NAME}.exe"
fi
echo "🔨 Building $OUTPUT_NAME..."
go build \
-buildvcs=false \
-ldflags "-s -w -extldflags -static -X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=${{ env.COMMIT_SHA }}" \
-o $OUTPUT_NAME \
./weed
ls -lh $OUTPUT_NAME
echo "✅ Build completed"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: weed-${{ matrix.goos }}-${{ matrix.goarch }}
path: seaweedfs-source/weed-*
retention-days: 30
# Notification job (optional)
notify:
needs: [gitlab-webhook-build, build-release-binaries]
if: always()
runs-on: ubuntu-latest
steps:
- name: Build notification
run: |
if [ "${{ needs.gitlab-webhook-build.result }}" = "success" ]; then
echo "✅ GitLab webhook build completed successfully"
else
echo "❌ GitLab webhook build failed"
fi
if [ "${{ needs.build-release-binaries.result }}" = "success" ]; then
echo "✅ Release binaries built successfully"
elif [ "${{ needs.build-release-binaries.result }}" = "skipped" ]; then
echo "⏭️ Release binaries skipped"
else
echo "❌ Release binaries build failed"
fi