-
Notifications
You must be signed in to change notification settings - Fork 1
490 lines (400 loc) · 15.3 KB
/
release.yml
File metadata and controls
490 lines (400 loc) · 15.3 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
env:
GO_VERSION: '1.26.0'
jobs:
preflight:
name: Preflight Checks
runs-on: ubuntu-latest
defaults:
run:
working-directory: cli
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go (bootstrap)
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- name: Install Go ${{ env.GO_VERSION }}
run: |
go install golang.org/dl/go${{ env.GO_VERSION }}@latest
go${{ env.GO_VERSION }} download
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
ln -sf $(which go${{ env.GO_VERSION }}) $(go env GOPATH)/bin/go
- name: Verify Go version
run: go version
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Install azd
run: curl -fsSL https://aka.ms/install-azd.sh | bash
- name: Install azd extensions
run: |
azd extension source add azd --location https://aka.ms/azd/extensions/registry --type url 2>/dev/null || true
azd extension install microsoft.azd.extensions --source azd
- name: Format check
run: |
if [ -n "$(gofmt -l ./src/)" ]; then
echo "Go files need formatting:"
gofmt -l ./src/
exit 1
fi
- name: Lint
run: golangci-lint run --timeout=5m ./src/...
- name: Security scan
run: gosec -quiet -exclude=G204,G304 ./src/...
- name: Vulnerability check
run: govulncheck ./src/...
test:
name: Test
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: cli
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go (bootstrap)
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- name: Install Go ${{ env.GO_VERSION }} (Unix)
if: runner.os != 'Windows'
run: |
go install golang.org/dl/go${{ env.GO_VERSION }}@latest
go${{ env.GO_VERSION }} download
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
ln -sf $(which go${{ env.GO_VERSION }}) $(go env GOPATH)/bin/go
- name: Install Go ${{ env.GO_VERSION }} (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
go install golang.org/dl/go${{ env.GO_VERSION }}@latest
& go${{ env.GO_VERSION }} download
$gopath = go env GOPATH
"$gopath\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
Copy-Item "$gopath\bin\go${{ env.GO_VERSION }}.exe" "$gopath\bin\go.exe" -Force
- name: Verify Go version
run: go version
- name: Download dependencies
run: go mod download
- name: Run tests
shell: bash
run: |
mkdir -p ../coverage
if [ "${{ matrix.os }}" = "macos-latest" ]; then
go test -short -v -coverprofile=../coverage/coverage.out ./src/...
else
go test -short -v -race -coverprofile=../coverage/coverage.out ./src/...
fi
- name: Upload coverage to Codecov
if: github.repository == 'jongio/azd-rest'
uses: codecov/codecov-action@v4
with:
file: coverage/coverage.out
flags: unittests
name: codecov-${{ matrix.os }}-go-${{ env.GO_VERSION }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
verbose: true
lint:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: cli
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go (bootstrap)
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- name: Install Go ${{ env.GO_VERSION }}
run: |
go install golang.org/dl/go${{ env.GO_VERSION }}@latest
go${{ env.GO_VERSION }} download
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
ln -sf $(which go${{ env.GO_VERSION }}) $(go env GOPATH)/bin/go
- name: Verify Go version
run: go version
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
- name: Run golangci-lint
run: golangci-lint run --timeout=5m ./src/...
build:
name: Build
runs-on: ubuntu-latest
needs: [preflight, test, lint]
defaults:
run:
working-directory: cli
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go (bootstrap)
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- name: Install Go ${{ env.GO_VERSION }}
run: |
go install golang.org/dl/go${{ env.GO_VERSION }}@latest
go${{ env.GO_VERSION }} download
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
ln -sf $(which go${{ env.GO_VERSION }}) $(go env GOPATH)/bin/go
- name: Verify Go version
run: go version
- name: Build for multiple platforms
run: |
GOOS=windows GOARCH=amd64 go build -o bin/windows-amd64/rest.exe ./src/cmd/rest
GOOS=windows GOARCH=arm64 go build -o bin/windows-arm64/rest.exe ./src/cmd/rest
GOOS=linux GOARCH=amd64 go build -o bin/linux-amd64/rest ./src/cmd/rest
GOOS=darwin GOARCH=amd64 go build -o bin/darwin-amd64/rest ./src/cmd/rest
GOOS=darwin GOARCH=arm64 go build -o bin/darwin-arm64/rest ./src/cmd/rest
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binaries
path: cli/bin/
release:
name: Release
runs-on: ubuntu-latest
needs: [preflight, test, lint, build]
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go (bootstrap)
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- name: Install Go ${{ env.GO_VERSION }}
run: |
go install golang.org/dl/go${{ env.GO_VERSION }}@latest
go${{ env.GO_VERSION }} download
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
ln -sf $(which go${{ env.GO_VERSION }}) $(go env GOPATH)/bin/go
- name: Verify Go version
run: go version
- name: Calculate next version
id: version
run: |
CURRENT=$(grep '^version:' cli/extension.yaml | awk '{print $2}')
IFS='.' read -r major minor patch <<< "$CURRENT"
case "${{ inputs.bump }}" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
NEXT="$major.$minor.$patch"
echo "current=$CURRENT" >> $GITHUB_OUTPUT
echo "next=$NEXT" >> $GITHUB_OUTPUT
echo "Bumping from $CURRENT to $NEXT"
- name: Update version files and create PR
id: version_pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.version.outputs.next }}"
BRANCH="release/v${VERSION}"
git push origin --delete "$BRANCH" 2>/dev/null || true
git branch -D "$BRANCH" 2>/dev/null || true
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
sed -i "s/^version: .*/version: $VERSION/" cli/extension.yaml
PREV="${{ steps.version.outputs.current }}"
if git rev-parse "v${PREV}" >/dev/null 2>&1; then
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges v${PREV}..HEAD)
else
LAST_VERSION_COMMIT=$(git log --grep="^chore: bump version to" --format="%H" -n 1)
if [ -n "$LAST_VERSION_COMMIT" ]; then
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges ${LAST_VERSION_COMMIT}..HEAD)
else
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges)
fi
fi
DATE=$(date +%Y-%m-%d)
{
echo "## [$VERSION] - $DATE"
echo ""
echo "$COMMITS"
echo ""
cat CHANGELOG.md
} > CHANGELOG.new.md
mv CHANGELOG.new.md CHANGELOG.md
git add cli/extension.yaml CHANGELOG.md
git commit -m "chore: bump version to $VERSION"
git push origin "$BRANCH"
PR_URL=$(gh pr create \
--title "chore: Release v${VERSION}" \
--body "Automated version bump to ${VERSION} for release." \
--base main \
--head "$BRANCH")
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Enable auto-merge and wait for merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.version_pr.outputs.pr_number }}"
echo "Waiting for CI checks to be queued..."
sleep 10
MAX_RETRIES=3
RETRY=0
while [ $RETRY -lt $MAX_RETRIES ]; do
if gh pr merge "$PR_NUMBER" --auto --squash 2>&1; then
echo "Auto-merge enabled successfully!"
break
else
RETRY=$((RETRY + 1))
if [ $RETRY -lt $MAX_RETRIES ]; then
echo "Retrying in 10 seconds... (attempt $RETRY/$MAX_RETRIES)"
sleep 10
else
echo "Failed to enable auto-merge after $MAX_RETRIES attempts"
exit 1
fi
fi
done
echo "Waiting for PR to be merged..."
TIMEOUT=600
ELAPSED=0
INTERVAL=15
while [ $ELAPSED -lt $TIMEOUT ]; do
PR_DATA=$(gh pr view "$PR_NUMBER" --json state,mergeable,statusCheckRollup)
STATE=$(echo "$PR_DATA" | jq -r '.state')
MERGEABLE=$(echo "$PR_DATA" | jq -r '.mergeable')
echo "PR state: $STATE, Mergeable: $MERGEABLE"
if [ "$STATE" = "MERGED" ]; then
echo "PR merged successfully!"
break
fi
PENDING_CHECKS=$(echo "$PR_DATA" | jq '[.statusCheckRollup[] | select(.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "PENDING")] | length')
TOTAL_CHECKS=$(echo "$PR_DATA" | jq '.statusCheckRollup | length')
echo "Checks: $((TOTAL_CHECKS - PENDING_CHECKS))/$TOTAL_CHECKS complete"
if [ "$PENDING_CHECKS" -eq 0 ] && [ "$TOTAL_CHECKS" -gt 0 ]; then
FAILED_CHECKS=$(echo "$PR_DATA" | jq -r '.statusCheckRollup[] | select(.conclusion == "FAILURE" or .conclusion == "CANCELLED") | .name')
if [ -n "$FAILED_CHECKS" ]; then
echo "ERROR: Some checks failed:"
echo "$FAILED_CHECKS"
exit 1
fi
fi
sleep $INTERVAL
ELAPSED=$((ELAPSED + INTERVAL))
done
if [ "$STATE" != "MERGED" ]; then
echo "ERROR: PR did not merge within timeout"
exit 1
fi
- name: Checkout main and create tag
run: |
VERSION="${{ steps.version.outputs.next }}"
git checkout main
git pull origin main
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Delete existing tag if present (from a previous failed run)
git tag -d "v${VERSION}" 2>/dev/null || true
git push origin --delete "v${VERSION}" 2>/dev/null || true
git tag -a "v${VERSION}" -m "Release version ${VERSION}"
git push origin "v${VERSION}"
- name: Install azd
run: curl -fsSL https://aka.ms/install-azd.sh | bash
- name: Install azd extensions
run: |
azd extension source add azd --location https://aka.ms/azd/extensions/registry --type url 2>/dev/null || true
azd extension install microsoft.azd.extensions --source azd
- name: Build binaries
working-directory: cli
run: |
export EXTENSION_ID="jongio.azd.rest"
export EXTENSION_VERSION="${{ steps.version.outputs.next }}"
azd x build --all
- name: Package
working-directory: cli
run: azd x pack
- name: Extract release notes
id: release_notes
run: |
VERSION="${{ steps.version.outputs.next }}"
awk '
BEGIN { in_section = 0 }
/^## \['"$VERSION"'\]/ { in_section = 1; next }
/^## \[/ { in_section = 0 }
in_section && NF > 0 { print }
' CHANGELOG.md > /tmp/release-notes.md
echo "Release notes for v$VERSION:"
cat /tmp/release-notes.md
- name: Release
working-directory: cli
run: |
VERSION="${{ steps.version.outputs.next }}"
TAG_NAME="azd-ext-jongio-azd-rest_${VERSION}"
# Delete existing release if present (from a previous failed run)
gh release delete "$TAG_NAME" --yes 2>/dev/null || true
azd x release \
--repo "${{ github.repository }}" \
--version "$VERSION" \
--notes-file /tmp/release-notes.md \
--confirm
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update registry
working-directory: cli
run: |
azd x publish \
--registry ../registry.json \
--version "${{ steps.version.outputs.next }}" \
--repo "${{ github.repository }}"
cd ..
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add registry.json
if ! git diff --cached --quiet; then
git commit -m "chore: update registry for v${{ steps.version.outputs.next }}"
git push
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}