-
Notifications
You must be signed in to change notification settings - Fork 0
360 lines (323 loc) · 11.4 KB
/
Copy pathrelease.yml
File metadata and controls
360 lines (323 loc) · 11.4 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
name: Build binaries
on:
push:
tags: ["*"]
workflow_dispatch:
permissions:
contents: read
env:
PROJECT_NAME: gitow
CARGO_TERM_COLOR: always
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
checks:
uses: ./.github/workflows/ci.yml
package:
name: Verify crates.io package
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- name: Checkout sources
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Validate release tag
id: version
run: |
version=$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')
if [[ "$GITHUB_REF_TYPE" == "tag" && "$GITHUB_REF_NAME" != "$version" && "$GITHUB_REF_NAME" != "v$version" ]]; then
echo "::error::The release tag must match Cargo.toml: $version or v$version" >&2
exit 1
fi
prerelease=false
if [[ "${version%%+*}" == *-* ]]; then
prerelease=true
fi
echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Verify publishable package
run: cargo publish --dry-run --locked
build:
name: Binary ${{ matrix.target }}
needs: [checks, package]
runs-on: ${{ matrix.runner }}
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
builder: cargo
- target: aarch64-unknown-linux-musl
runner: ubuntu-latest
builder: cross
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
builder: cargo
- target: x86_64-unknown-linux-musl
runner: ubuntu-latest
builder: cross
- target: i686-unknown-linux-gnu
runner: ubuntu-latest
builder: cross
- target: riscv64gc-unknown-linux-gnu
runner: ubuntu-latest
builder: cross
- target: sparc64-unknown-linux-gnu
runner: ubuntu-latest
builder: cross
- target: aarch64-apple-darwin
runner: macos-latest
builder: cargo
- target: x86_64-apple-darwin
runner: macos-latest
builder: cargo
- target: x86_64-pc-windows-msvc
runner: windows-latest
builder: cargo
- target: aarch64-pc-windows-msvc
runner: windows-latest
builder: cargo
steps:
- name: Checkout sources
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.builder == 'cargo' && matrix.target || '' }}
- name: Cache cargo build artifacts
uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
- name: Install cross
if: matrix.builder == 'cross'
uses: taiki-e/install-action@v2
with:
tool: cross@0.2.5
fallback: none
- name: Build native release binary
if: matrix.builder == 'cargo'
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Build cross-compiled release binary
if: matrix.builder == 'cross'
run: cross build --release --locked --target ${{ matrix.target }}
- name: Package Unix zip
if: runner.os != 'Windows'
shell: bash
run: |
binary="target/${{ matrix.target }}/release/${PROJECT_NAME}"
test -x "$binary"
mkdir -p artifacts
zip -j "artifacts/${PROJECT_NAME}-${{ matrix.target }}.zip" "$binary" LICENSE README.md README-RU.md
- name: Package Windows zip
if: runner.os == 'Windows'
shell: pwsh
run: |
$binary = "target/${{ matrix.target }}/release/${env:PROJECT_NAME}.exe"
if (-not (Test-Path -LiteralPath $binary -PathType Leaf)) {
throw "Binary artifact not found: $binary"
}
New-Item -ItemType Directory -Force -Path artifacts | Out-Null
Compress-Archive -LiteralPath $binary, LICENSE, README.md, README-RU.md -DestinationPath "artifacts/${env:PROJECT_NAME}-${{ matrix.target }}.zip"
- name: Upload archive
uses: actions/upload-artifact@v7
with:
name: gitow-${{ matrix.target }}
path: artifacts/*.zip
if-no-files-found: error
compression-level: 0
snap:
name: Snap package ${{ matrix.arch }}
needs: [checks, package]
runs-on: ${{ matrix.runner }}
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout sources
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install LXD and Snapcraft
run: |
sudo groupadd --force --system lxd
sudo usermod --append --groups lxd runner
sudo snap install lxd
sudo lxd init --auto
sudo iptables -P FORWARD ACCEPT
sudo snap install --channel 8.x/stable --classic snapcraft
- name: Build snap
run: sudo -u runner -E snapcraft pack --use-lxd --build-for=${{ matrix.arch }}
- name: Collect snap
run: |
shopt -s nullglob
snaps=("${PROJECT_NAME}"_*_${{ matrix.arch }}.snap)
if [ "${#snaps[@]}" -ne 1 ]; then
echo "::error::Expected exactly one Snap artifact for ${{ matrix.arch }}" >&2
exit 1
fi
mkdir -p artifacts
mv -- "${snaps[0]}" "artifacts/${PROJECT_NAME}-${{ matrix.arch }}.snap"
- name: Smoke-test installed snap
run: |
sudo snap install --dangerous --classic "artifacts/${PROJECT_NAME}-${{ matrix.arch }}.snap"
/snap/bin/gitow --help
test "$(/snap/bin/gitow --print https://github.com/WhoSowSee/gitow.git --branch main)" = "https://github.com/WhoSowSee/gitow/tree/main"
- name: Upload snap
uses: actions/upload-artifact@v7
with:
name: gitow-snap-${{ matrix.arch }}
path: artifacts/*.snap
if-no-files-found: error
compression-level: 0
nix:
name: Nix package
needs: [checks, package]
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- name: Checkout sources
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install Nix
uses: cachix/install-nix-action@v31
- name: Evaluate flake outputs
run: nix flake check --all-systems --no-build --no-update-lock-file --print-build-logs
- name: Build Nix package
run: nix build .#packages.x86_64-linux.default --no-update-lock-file --print-build-logs
- name: Smoke-test Nix binary
run: |
result/bin/gitow --help
test "$(PATH='' result/bin/gitow --print https://github.com/WhoSowSee/gitow.git --branch main)" = "https://github.com/WhoSowSee/gitow/tree/main"
release:
name: Publish GitHub release
needs: [checks, package, build, snap, nix]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
steps:
- name: Checkout sources
uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- name: Download release artifacts
uses: actions/download-artifact@v8
with:
pattern: gitow-*
path: dist
merge-multiple: true
- name: Prepare release files
run: |
shopt -s nullglob
files=(dist/"${PROJECT_NAME}"-*.zip dist/"${PROJECT_NAME}"-*.snap)
if [ "${#files[@]}" -eq 0 ]; then
echo "::error::No release artifacts found" >&2
exit 1
fi
for file in "${files[@]}"; do
base=${file##*/}
mv -- "$file" "dist/${PROJECT_NAME}-${GITHUB_REF_NAME}-${base#"${PROJECT_NAME}"-}"
done
(cd dist && sha256sum -- *.zip *.snap > SHA256SUMS)
- name: Extract release metadata
id: tag_meta
run: |
# Fallback order: changelog entry -> tag annotation -> commit message
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
COMMIT=$(git rev-list -n 1 "$TAG")
TAG_MESSAGE=$(git for-each-ref "refs/tags/$TAG" --format='%(contents)')
if [ -z "${TAG_MESSAGE//[$'\r\n\t ']/}" ]; then
TAG_MESSAGE=$(git tag -l "$TAG" --format='%(contents)')
fi
COMMIT_MESSAGE=$(git show -s --format=%B "$COMMIT")
CHANGELOG_SECTION=""
if [ -f CHANGELOG.md ]; then
CHANGELOG_SECTION=$(awk -v ver="$VERSION" '
function trim(str) {
sub(/^[[:space:]]+/, "", str)
sub(/[[:space:]]+$/, "", str)
return str
}
/^## \[/ {
if (match($0, /^## \[([^\]]+)\]/, m)) {
heading = trim(m[1])
if (found && heading != ver) {
exit
}
if (!found && heading == ver) {
found = 1
next
}
}
}
found {
if (!printed) {
if ($0 ~ /^[[:space:]]*$/) {
next
}
printed = 1
print
next
}
print
}
' CHANGELOG.md)
fi
if [ -n "$(printf '%s' "$CHANGELOG_SECTION" | tr -d $'\r\n\t ')" ]; then
MESSAGE="$CHANGELOG_SECTION"
elif [ -n "$(printf '%s' "$TAG_MESSAGE" | tr -d $'\r\n\t ')" ]; then
MESSAGE="$TAG_MESSAGE"
else
MESSAGE="$COMMIT_MESSAGE"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "commit=$COMMIT" >> "$GITHUB_OUTPUT"
printf 'message<<EOF\n%s\nEOF\n' "$MESSAGE" >> "$GITHUB_OUTPUT"
- name: Generate GitHub release notes
id: gh_notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
RESPONSE=$(gh api repos/${GITHUB_REPOSITORY}/releases/generate-notes \
-f tag_name="${{ steps.tag_meta.outputs.tag }}" \
-f target_commitish="${{ steps.tag_meta.outputs.commit }}")
BODY=$(echo "$RESPONSE" | jq -r '.body // ""')
printf 'body<<EOF\n%s\nEOF\n' "$BODY" >> "$GITHUB_OUTPUT"
- name: Compose release body
run: |
{
printf '%s\n\n' "$TAG_MESSAGE"
echo '---'
echo
printf '%s\n' "$GENERATED_NOTES"
} > release-notes.md
env:
TAG_MESSAGE: ${{ steps.tag_meta.outputs.message }}
GENERATED_NOTES: ${{ steps.gh_notes.outputs.body }}
- name: Create GitHub release
uses: softprops/action-gh-release@v3
with:
files: dist/*
body_path: release-notes.md
prerelease: ${{ needs.package.outputs.prerelease == 'true' }}
fail_on_unmatched_files: true