-
-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (136 loc) · 4.04 KB
/
release.yml
File metadata and controls
155 lines (136 loc) · 4.04 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
bump:
description: "Semantic version bump"
required: true
default: patch
type: choice
options:
- patch
- minor
- major
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
jobs:
verify:
name: Verify before release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Root tests
run: go test ./...
- name: Root race tests
run: go test -race ./...
- name: Download validation module dependencies
working-directory: validation/playground
env:
GOWORK: off
run: go mod download
- name: Validation submodule tests
working-directory: validation/playground
env:
GOWORK: off
run: go test ./...
- name: Download REST API example dependencies
working-directory: examples/restapi
env:
GOWORK: off
run: go mod download
- name: REST API example tests
working-directory: examples/restapi
env:
GOWORK: off
run: go test ./...
tag-release:
name: Create release tag
runs-on: ubuntu-latest
needs: verify
if: github.event_name == 'workflow_dispatch'
outputs:
tag_name: ${{ steps.tag.outputs.tag_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
id: tag
env:
BUMP: ${{ inputs.bump }}
run: |
set -euo pipefail
latest_tag="$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -n 1)"
if [ -z "$latest_tag" ]; then
latest_tag="v0.0.0"
fi
version="${latest_tag#v}"
IFS='.' read -r major minor patch <<< "$version"
if ! [[ "$major" =~ ^[0-9]+$ && "$minor" =~ ^[0-9]+$ && "$patch" =~ ^[0-9]+$ ]]; then
echo "could not parse semver from '$latest_tag'" >&2
exit 1
fi
case "$BUMP" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
*)
echo "unsupported bump: $BUMP" >&2
exit 1
;;
esac
tag_name="v${major}.${minor}.${patch}"
if git rev-parse -q --verify "refs/tags/$tag_name" >/dev/null; then
echo "tag $tag_name already exists locally" >&2
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/$tag_name" >/dev/null 2>&1; then
echo "tag $tag_name already exists on origin" >&2
exit 1
fi
git tag "$tag_name"
git push origin "$tag_name"
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
github-release:
name: Publish GitHub release
runs-on: ubuntu-latest
needs:
- verify
- tag-release
if: |
!failure() && !cancelled()
&& needs.verify.result == 'success'
&& (needs.tag-release.result == 'success' || needs.tag-release.result == 'skipped')
&& (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch')
steps:
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'workflow_dispatch' && needs.tag-release.outputs.tag_name || github.ref_name }}
generate_release_notes: true