-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (125 loc) · 4.51 KB
/
release.yml
File metadata and controls
146 lines (125 loc) · 4.51 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
name: Release
on:
push:
branches: [main]
permissions:
contents: write
pull-requests: write
jobs:
release-pr:
name: Create or update release PR
runs-on: ubuntu-latest
# Skip release commits to avoid infinite loops
if: "!startsWith(github.event.head_commit.message, 'chore(release):')"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine next version
id: next
run: |
set -euo pipefail
# Get current version from version.go
CURRENT=$(sed -n 's/^const Version = "\(.*\)"/\1/p' version.go)
echo "current=$CURRENT" >> $GITHUB_OUTPUT
# Use git-cliff to calculate the bumped version
pip install git-cliff >/dev/null 2>&1 || true
NEXT=$(git cliff --bumped-version 2>/dev/null | sed 's/^v//')
if [ -z "$NEXT" ] || [ "$NEXT" = "$CURRENT" ]; then
echo "No version bump needed"
echo "bump=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "version=$NEXT" >> $GITHUB_OUTPUT
echo "tag=v$NEXT" >> $GITHUB_OUTPUT
echo "bump=true" >> $GITHUB_OUTPUT
echo "Bumping $CURRENT -> $NEXT"
- name: Update version.go
if: steps.next.outputs.bump == 'true'
run: |
VERSION="${{ steps.next.outputs.version }}"
sed -i "s/const Version = \".*\"/const Version = \"$VERSION\"/" version.go
- name: Generate changelog
if: steps.next.outputs.bump == 'true'
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --tag ${{ steps.next.outputs.tag }}
env:
OUTPUT: CHANGELOG.md
- name: Create release PR
if: steps.next.outputs.bump == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: main
commit-message: "chore(release): bump version to ${{ steps.next.outputs.version }}"
branch: release/next
title: "chore(release): v${{ steps.next.outputs.version }}"
body: |
## Release `v${{ steps.next.outputs.version }}`
Automated release preparation.
### Changes
- Update `version.go` to `${{ steps.next.outputs.version }}`
- Refresh `CHANGELOG.md`
### After merge
A GitHub Release with tag `v${{ steps.next.outputs.version }}` will be created automatically.
add-paths: |
version.go
CHANGELOG.md
labels: release
publish-release:
name: Publish GitHub release
runs-on: ubuntu-latest
# Only run on release commits (merged release PR)
if: startsWith(github.event.head_commit.message, 'chore(release):')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version
id: release
run: |
set -euo pipefail
VERSION=$(sed -n 's/^const Version = "\(.*\)"/\1/p' version.go)
if [ -z "$VERSION" ]; then
echo "Unable to determine version" >&2
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
run: |
TAG="${{ steps.release.outputs.tag }}"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
- name: Get previous tag
id: prev_tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Generate release notes
id: changelog
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: >-
${{ steps.prev_tag.outputs.tag && format('{0}..{1}', steps.prev_tag.outputs.tag, steps.release.outputs.tag) || steps.release.outputs.tag }}
env:
OUTPUT: /tmp/RELEASE_CHANGELOG.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
body: ${{ steps.changelog.outputs.content }}
draft: false
prerelease: false
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}