-
Notifications
You must be signed in to change notification settings - Fork 0
207 lines (177 loc) · 6.98 KB
/
release.yml
File metadata and controls
207 lines (177 loc) · 6.98 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
name: Manual Release
run-name: "Release ${{ inputs.version }}${{ inputs.prerelease && ' (prerelease)' || '' }}"
on:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g. 0.1.2 or v0.1.2)"
required: true
type: string
prerelease:
description: "Mark as pre-release?"
required: false
default: false
type: boolean
permissions:
contents: write
env:
GO_VERSION: 1.25.3
GOLANGCI_LINT_VERSION: v2.5.0
jobs:
version-bump-check:
name: Version bump check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Version bump check
shell: bash
run: |
set -euo pipefail
raw="${{ inputs.version }}"
NEW_VERSION="${raw#v}" # normalized
# basic semver check: X.Y.Z with optional prerelease, but we only accept bare X.Y.Z for base version
if [[ ! "$NEW_VERSION" =~ ^[0-9]+(\.[0-9]+){2}([\-+][0-9A-Za-z\.-]+)?$ ]]; then
echo "::error::Input must be SemVer like 0.5.0 or 1.2.3-rc.1"
exit 1
fi
# latest FINAL tag: strictly vX.Y.Z (ignore all prereleases)
LATEST_FINAL_TAG=$(git tag --list 'v[0-9]*' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V | tail -n1 || true)
LATEST_FINAL_TAG=${LATEST_FINAL_TAG:-v0.0.0}
OLD_FINAL_VERSION=${LATEST_FINAL_TAG#v}
echo "Latest FINAL tag: $LATEST_FINAL_TAG"
echo "VERSION file: $NEW_VERSION"
# STRICT: VERSION must be > latest final (no equality)
if [[ "$NEW_VERSION" == "$OLD_FINAL_VERSION" ]]; then
echo "::error::VERSION ($NEW_VERSION) must be greater than latest final ($OLD_FINAL_VERSION)"
exit 1
fi
if [[ "$(printf '%s\n' "$OLD_FINAL_VERSION" "$NEW_VERSION" | sort -V | tail -n1)" != "$NEW_VERSION" ]]; then
echo "::error::VERSION ($NEW_VERSION) must be greater than latest final ($OLD_FINAL_VERSION)"
exit 1
fi
echo "VERSION is newer than latest final: $OLD_FINAL_VERSION → $NEW_VERSION"
release:
name: Test, tag & release
needs: [version-bump-check]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
- name: Run tests
run: go test -mod=readonly ./... -count=1 -race
- name: Compute tag (final or next -rc.N)
id: compute_tag
shell: bash
run: |
set -euo pipefail
PRERELEASE="${{ inputs.prerelease }}"
raw="${{ inputs.version }}"
VERSION="${raw#v}" # normalized base: X.Y.Z
# existence helpers
final_exists() { git rev-parse "v${VERSION}" >/dev/null 2>&1; }
any_rc_tags() { git tag --list "v${VERSION}-rc*" | grep -q .; }
# find next rc number (supports both -rc1 and -rc.1 historical patterns)
next_rc_tag() {
local base="$1"
local maxn
maxn=$(git tag --list "v${base}-rc*" \
| sed -E 's/^.*-rc\.?([0-9]+)$/\1/' \
| grep -E '^[0-9]+$' \
| sort -n | tail -n1 || true)
if [[ -z "${maxn:-}" ]]; then
echo "v${base}-rc.1"
else
echo "v${base}-rc.$((maxn+1))"
fi
}
# guard: do not allow prerelease/final if final already exists for this version
if final_exists; then
if [[ "$PRERELEASE" == "true" ]]; then
echo "::error::Cannot create prerelease: final tag v${VERSION} already exists"
else
echo "::error::Final tag v${VERSION} already exists; bump VERSION first"
fi
exit 1
fi
if [[ "$PRERELEASE" == "true" ]]; then
TAG="$(next_rc_tag "$VERSION")"
IS_PRE="true"
else
TAG="v${VERSION}"
IS_PRE="false"
fi
# final guard: avoid accidental retagging if somehow exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "::error::Tag $TAG already exists"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "is_prerelease=$IS_PRE" >> "$GITHUB_OUTPUT"
echo "Computed tag: $TAG (prerelease=$IS_PRE)"
- name: Create Git tag
shell: bash
run: |
set -euo pipefail
TAG="${{ steps.compute_tag.outputs.tag }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists; skipping tag creation."
else
git tag -a "$TAG" -m "chore(release): $TAG"
git push origin "$TAG"
fi
- name: Find previous final tag (-rc.N excluded)
id: prev_final
shell: bash
run: |
set -euo pipefail
PREV=$(git tag --list 'v[0-9]*' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V | tail -n2 | head -n1 || true)
echo "prev=$PREV" >> "$GITHUB_OUTPUT"
- name: Generate changelog (RC)
id: git-cliff-rc
if: ${{ steps.compute_tag.outputs.is_prerelease == 'true' }}
uses: orhun/git-cliff-action@v4
with:
args: --current --no-exec
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
- name: Generate changelog (final release)
id: git-cliff-final
if: ${{ steps.compute_tag.outputs.is_prerelease == 'false' }}
uses: orhun/git-cliff-action@v4
with:
# If no previous final tag, this produces an empty range; optionally
# fall back to the root commit if you want *all* history instead.
args: "${{ steps.prev_final.outputs.prev }}..${{ steps.compute_tag.outputs.tag }} --no-exec"
env:
GITHUB_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.compute_tag.outputs.tag }}
name: wadjit ${{ steps.compute_tag.outputs.tag }}
body: ${{ steps.compute_tag.outputs.is_prerelease == 'true'
&& steps.git-cliff-rc.outputs.content
|| steps.git-cliff-final.outputs.content }}
prerelease: ${{ steps.compute_tag.outputs.is_prerelease }}
make_latest: ${{ steps.compute_tag.outputs.is_prerelease == 'false' }}
env:
GITHUB_TOKEN: ${{ github.token }}