-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (102 loc) · 3.79 KB
/
Copy pathrelease.yml
File metadata and controls
113 lines (102 loc) · 3.79 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version override (e.g. v1.2.3). Leave empty to auto-detect via git-cliff.'
required: false
default: ''
permissions:
contents: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- run: go test ./...
release:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Ensure tags are available
run: git fetch --force --tags
- name: Determine version via git-cliff
id: cliff
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --bumped-version
- name: Resolve release version
id: version
run: |
DETECTED_VERSION="$(echo "${{ steps.cliff.outputs.content }}" | tr -d '[:space:]')"
if [ -z "$DETECTED_VERSION" ]; then
LAST_TAG="$(git tag --list 'v*' --sort=-version:refname | head -n1)"
if [[ -z "$LAST_TAG" ]]; then
DETECTED_VERSION="v0.1.0"
echo "git-cliff returned empty; no prior tags found. Falling back to $DETECTED_VERSION"
elif [[ "$LAST_TAG" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
DETECTED_VERSION="v${MAJOR}.${MINOR}.$((PATCH + 1))"
echo "git-cliff returned empty; falling back to patch bump from $LAST_TAG -> $DETECTED_VERSION"
else
echo "Error: latest tag '$LAST_TAG' is not semver (vX.Y.Z). Set workflow input 'version'." >&2
exit 1
fi
fi
VERSION="${{ inputs.version }}"
if [ -z "$VERSION" ]; then
VERSION="$DETECTED_VERSION"
fi
if [ -z "$VERSION" ]; then
echo "Error: could not determine version. git-cliff returned nothing (no prior tags?). Use the version override input." >&2
exit 1
fi
if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then
echo "Error: tag '$VERSION' already exists. Set workflow input 'version' to a new value." >&2
exit 1
fi
echo "Releasing $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Generate changelog
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --tag ${{ steps.version.outputs.version }} -o CHANGELOG.md
- name: Commit changelog and create tag locally
run: |
VERSION="${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore: release $VERSION" || echo "No changelog changes to commit"
git tag -a "$VERSION" -m "$VERSION"
- name: Ensure clean git state for goreleaser
run: |
git clean -ffdx
if [ -n "$(git status --porcelain)" ]; then
echo "Error: working tree is dirty before goreleaser." >&2
git status --porcelain
exit 1
fi
- uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
- name: Push release commit and tag
run: git push origin HEAD:main --follow-tags