blob: ebf84937bc3d059525a48633b349bcf100f5a15a (
plain) (
blame)
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
|
name: build
on: [pull_request, push]
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.24.x]
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
id: go
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run tests
run: go test ./...
- name: Tag new version
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euxo pipefail
next_version () {
local current
local impact
local MAJOR
local MINOR
local PATCH
local parts
impact="$1"
if [ -z "$1" ]
then
impact="patch"
fi
current=$(git tag | sort -r | grep "^v[0-9]*\.[0-9]*\.[0-9]" | sort -t "." -k1,1nr -k2,2nr -k3,3nr | cut -c2- | head -1 2> /dev/null) || true
if [[ -z "$current" ]]; then
current='0.0.0'
fi
parts=(${current//./ })
MAJOR=${parts[0]}
MINOR=${parts[1]}
PATCH=${parts[2]}
case "$impact" in
major)
((MAJOR+=1))
;;
minor)
((MINOR+=1))
;;
patch)
((PATCH+=1))
;;
esac
echo "$MAJOR.$MINOR.$PATCH"
}
tag_and_release () {
local commit
commit=$(git rev-parse HEAD)
local next
if [[ -z "$(git describe --contains "$commit" 2>/dev/null)" ]]; then
next="v$(next_version "$1")"
git tag "$next"
git config user.name github-actions
git config user.email github-actions@github.com
git push --tags
echo "RELEASE_TAG=$next" >> $GITHUB_ENV
fi
}
git fetch --all --tags
tag_and_release patch
|