Skip to content

Commit 8c86599

Browse files
committed
Add Release workflow
1 parent 9be536c commit 8c86599

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Release tag (e.g., v1.0.0)'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: '1.23'
27+
28+
- name: Validate tag format
29+
run: |
30+
if [[ ! "${{ github.event.inputs.tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
31+
echo "Error: Tag must follow semantic versioning format (e.g., v1.0.0, v1.0.0-beta.1)"
32+
exit 1
33+
fi
34+
35+
- name: Check if tag already exists
36+
run: |
37+
if git rev-parse "${{ github.event.inputs.tag }}" >/dev/null 2>&1; then
38+
echo "Error: Tag ${{ github.event.inputs.tag }} already exists"
39+
exit 1
40+
fi
41+
42+
- name: Run tests
43+
run: go test ./...
44+
45+
- name: Run go mod tidy
46+
run: go mod tidy
47+
48+
- name: Verify no changes after mod tidy
49+
run: |
50+
if ! git diff --exit-code; then
51+
echo "Error: go.mod or go.sum are not tidy"
52+
exit 1
53+
fi
54+
55+
- name: Create and push tag
56+
run: |
57+
git config --local user.email "[email protected]"
58+
git config --local user.name "GitHub Action"
59+
git tag -a "${{ github.event.inputs.tag }}" -m "Release ${{ github.event.inputs.tag }}"
60+
git push origin "${{ github.event.inputs.tag }}"
61+
62+
- name: Create GitHub release
63+
uses: actions/create-release@v1
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
with:
67+
tag_name: ${{ github.event.inputs.tag }}
68+
release_name: Release ${{ github.event.inputs.tag }}
69+
draft: false
70+
prerelease: ${{ contains(github.event.inputs.tag, '-') }}

0 commit comments

Comments
 (0)