-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (89 loc) · 2.76 KB
/
Copy pathrelease.yaml
File metadata and controls
104 lines (89 loc) · 2.76 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
name: Tag and Release
on:
push:
branches:
- main
paths:
- VERSION
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag_created: ${{ steps.create_tag.outputs.created }}
steps:
- name: Checkout with full history
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Read version from VERSION file
id: version
run: |
if [ ! -f VERSION ]; then
echo "ERROR: VERSION file not found"
exit 1
fi
VERSION=$(cat VERSION | tr -d '[:space:]')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Read version: $VERSION"
- name: Validate SemVer format
run: |
VERSION="${{ steps.version.outputs.version }}"
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "ERROR: Invalid version format '$VERSION'"
echo "Version must be valid SemVer: MAJOR.MINOR.PATCH (e.g., 1.2.3)"
exit 1
fi
echo "Version '$VERSION' is valid SemVer"
- name: Create and push tag
id: create_tag
run: |
TAG="v${{ steps.version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag '$TAG' already exists, skipping tag creation"
echo "created=false" >> "$GITHUB_OUTPUT"
else
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
echo "Created and pushed tag: $TAG"
echo "created=true" >> "$GITHUB_OUTPUT"
fi
test:
needs: tag
if: needs.tag.outputs.tag_created == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- run: go test ./...
release:
needs: [tag, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4.5.2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: goreleaser/goreleaser-action@v7
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}