-
Notifications
You must be signed in to change notification settings - Fork 0
255 lines (221 loc) · 8.5 KB
/
release.yml
File metadata and controls
255 lines (221 loc) · 8.5 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
jobs:
build-binaries:
strategy:
fail-fast: false
matrix:
include:
- goarch: amd64
- goarch: arm64
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Extract app version from tag
run: |
if ! [[ "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release tag must match vX.Y.Z; got: $GITHUB_REF_NAME" >&2
exit 1
fi
app_version="${GITHUB_REF_NAME#v}"
if [ -z "$app_version" ] || [ "$app_version" = "$GITHUB_REF_NAME" ]; then
echo "Unable to extract app version from tag: $GITHUB_REF_NAME" >&2
exit 1
fi
echo "APP_VERSION=$app_version" >> "$GITHUB_ENV"
- name: Build Linux binary
env:
GOOS: linux
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
mkdir -p dist
go build -trimpath -ldflags "-s -w -X main.version=${APP_VERSION}" -o "dist/gen-commit-msg_linux_${GOARCH}" ./cmd/gen-commit-msg
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: gen-commit-msg-linux-${{ matrix.goarch }}
path: dist/gen-commit-msg_linux_${{ matrix.goarch }}
if-no-files-found: error
publish-release:
needs: build-binaries
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Download binary artifacts
uses: actions/download-artifact@v4
with:
pattern: gen-commit-msg-linux-*
merge-multiple: true
path: dist
- name: Ensure binaries are executable
run: chmod +x dist/gen-commit-msg_linux_amd64 dist/gen-commit-msg_linux_arm64
- name: Generate release notes from tags and commits
run: |
current_tag="$GITHUB_REF_NAME"
# Get the last published GitHub release tag, not the last git tag.
# This handles cases where a previous tag failed to release.
previous_tag="$(gh release list --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null || true)"
if [ -n "$previous_tag" ] && [ "$previous_tag" != "$current_tag" ]; then
commit_range="$previous_tag..$current_tag"
range_label="$previous_tag -> $current_tag"
else
previous_git_tag="$(git describe --tags --abbrev=0 --match 'v*.*.*' "${current_tag}^" 2>/dev/null || true)"
if [ -n "$previous_git_tag" ]; then
commit_range="$previous_git_tag..$current_tag"
range_label="$previous_git_tag -> $current_tag"
else
commit_range="$current_tag"
range_label="initial release"
fi
fi
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
touch \
"$tmp_dir/features.txt" \
"$tmp_dir/fixes.txt" \
"$tmp_dir/performance.txt" \
"$tmp_dir/refactoring.txt" \
"$tmp_dir/docs.txt" \
"$tmp_dir/tests.txt" \
"$tmp_dir/build.txt" \
"$tmp_dir/ci.txt" \
"$tmp_dir/chore.txt" \
"$tmp_dir/other.txt"
git log --no-merges --pretty=format:'%s|%h' "$commit_range" > "$tmp_dir/commits.txt"
awk -F'|' -v tmp_dir="$tmp_dir" '
function append(file_name, line) {
print line >> (tmp_dir "/" file_name)
}
{
subject = $1
short_sha = $2
if (subject == "") {
next
}
entry = "- " subject " (" short_sha ")"
if (subject ~ /^feat(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("features.txt", entry)
} else if (subject ~ /^fix(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("fixes.txt", entry)
} else if (subject ~ /^perf(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("performance.txt", entry)
} else if (subject ~ /^refactor(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("refactoring.txt", entry)
} else if (subject ~ /^docs(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("docs.txt", entry)
} else if (subject ~ /^test(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("tests.txt", entry)
} else if (subject ~ /^build(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("build.txt", entry)
} else if (subject ~ /^ci(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("ci.txt", entry)
} else if (subject ~ /^chore(\([[:alnum:]_.\/-]+\))?!?:[[:space:]]/) {
append("chore.txt", entry)
} else {
append("other.txt", entry)
}
}
' "$tmp_dir/commits.txt"
append_section() {
section_title="$1"
section_file="$2"
if [ -s "$section_file" ]; then
echo
echo "#### $section_title"
cat "$section_file"
fi
}
{
echo "## Release $current_tag"
echo
echo "### Changelog"
echo "Range: $range_label"
if [ -s "$tmp_dir/commits.txt" ]; then
append_section "Features" "$tmp_dir/features.txt"
append_section "Fixes" "$tmp_dir/fixes.txt"
append_section "Performance" "$tmp_dir/performance.txt"
append_section "Refactoring" "$tmp_dir/refactoring.txt"
append_section "Documentation" "$tmp_dir/docs.txt"
append_section "Tests" "$tmp_dir/tests.txt"
append_section "Build" "$tmp_dir/build.txt"
append_section "CI" "$tmp_dir/ci.txt"
append_section "Chore" "$tmp_dir/chore.txt"
append_section "Other" "$tmp_dir/other.txt"
else
echo "- No commits found in this range"
fi
echo
echo "### Checksums (SHA256)"
echo '```text'
for file in dist/*; do
[ -f "$file" ] || continue
read -r checksum _ < <(sha256sum "$file")
printf '%s %s\n' "$checksum" "$(basename "$file")"
done
echo '```'
} > RELEASE_NOTES.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Show generated release notes
run: cat RELEASE_NOTES.md
- name: Verify release artifacts exist
run: |
for file in dist/*; do
[ -f "$file" ] || continue
exit 0
done
echo "No release artifacts found in dist/" >&2
exit 1
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
files: dist/*
body_path: RELEASE_NOTES.md
deploy-aur:
needs: publish-release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate AUR package files
run: |
app_version="${GITHUB_REF_NAME#v}"
./dist/scripts/generate-aur-packages.sh "$app_version"
- name: Deploy gen-commit-msg to AUR
uses: KSXGitHub/github-actions-deploy-aur@v4.1.3
with:
pkgname: gen-commit-msg
pkgbuild: target/aur/gen-commit-msg/PKGBUILD
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
commit_message: "Update to ${{ github.ref_name }}"
updpkgsums: true
test: true
test_flags: --clean --syncdeps --noconfirm
- name: Deploy gen-commit-msg-git to AUR
uses: KSXGitHub/github-actions-deploy-aur@v4.1.3
with:
pkgname: gen-commit-msg-git
pkgbuild: target/aur/gen-commit-msg-git/PKGBUILD
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
commit_message: "Update PKGBUILD for ${{ github.ref_name }}"
test: true
test_flags: --clean --syncdeps --noconfirm