-
Notifications
You must be signed in to change notification settings - Fork 8
382 lines (365 loc) · 13.1 KB
/
release.yml
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
# Just used for testing
pull_request:
branches:
- main
paths:
- ".github/workflows/release.yml"
- ".github/actions/setup/**"
workflow_dispatch:
inputs:
channel:
description: The release channel
default: beta
required: true
type: choice
options:
- alpha
- beta
- stable
publish:
description: Whether to publish a new release
default: false
required: true
type: boolean
schedule:
# Release alpha every day at 20:00 UTC (4:00 AM UTC+8)
- cron: "0 20 * * *"
defaults:
run:
shell: bash
permissions:
contents: read
jobs:
meta:
name: Meta
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
commit: ${{ steps.version.outputs.commit }}
channel: ${{ steps.version.outputs.channel }}
prerelease: ${{ steps.version.outputs.channel != 'stable' }}
publish: ${{ steps.version.outputs.publish }}
skip: ${{ steps.version.outputs.skip }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout Version Branch
uses: actions/checkout@v4
with:
ref: version
path: version
- name: Get Version
id: version
run: |
bash .github/scripts/parse_version.sh
release-note:
name: Generate Release Notes
if: ${{ !fromJson(needs.meta.outputs.skip) }}
runs-on: ubuntu-latest
needs: [meta]
outputs:
content: ${{ steps.git_cliff.outputs.content }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Release Notes
id: git_cliff
uses: orhun/git-cliff-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.meta.outputs.version }}
TAG: ${{ needs.meta.outputs.tag }}
with:
config: cliff.toml
# If the release is triggered by a tag, process commits starting
# from the latest tag, otherwise tag will be create later, so use
# unreleased commits
args: >
-v
${{ github.event_name == 'push' && '-l' || '-u' }}
${{ needs.meta.outputs.channel != 'stable' && '--tag-pattern="^v"' || '' }}
- name: Preview Release Notes
if: ${{ !fromJson(needs.meta.outputs.publish) }}
run: |
{
echo '```markdown'
cat '${{ steps.git_cliff.outputs.changelog }}'
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
build:
name: Build
needs: meta
if: ${{ !fromJson(needs.meta.outputs.skip) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
arch:
- x86_64
- aarch64
include:
- os: macos-13 # x86_64 runner
arch: x86_64
- os: macos-14 # aaarch64 runner
arch: aarch64
exclude:
# Failed to cross compile ring on Windows
- os: windows-latest
arch: aarch64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Cross Compilation Toolchains
uses: ./.github/actions/setup
with:
os: ${{ matrix.os }}
host_arch: ${{ matrix.os == 'macos-14' && 'aarch64' || 'x86_64' }}
target_arch: ${{ matrix.arch }}
- name: Build
env:
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
CARGO_PROFILE_RELEASE_LTO: true
CARGO_PROFILE_RELEASE_STRIP: true
MAA_VERSION: ${{ needs.meta.outputs.version }}
run: |
cargo build --release --package maa-cli --locked --features vendored-openssl
- name: Tar Artifact
env:
TARGET_OS: ${{ matrix.os }}
TARGET_ARCH: ${{ matrix.arch }}
run: |
target_dir="target/$CARGO_BUILD_TARGET/release"
if [[ "$TARGET_OS" == "windows"* ]]; then
exe="maa.exe"
else
exe="maa"
fi
file "$target_dir/$exe" # check file status
# dry run if not cross compiling
if [[ "$TARGET_ARCH" == "x86_64" || "$TARGET_OS" == "macos-14" ]]; then
"$target_dir/$exe" --version
fi
tar -cvf "$CARGO_BUILD_TARGET.tar" -C "$target_dir" "$exe"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: maa_cli-${{ env.CARGO_BUILD_TARGET }}
path: ${{ env.CARGO_BUILD_TARGET }}.tar
retention-days: 1
if-no-files-found: error
build-universal:
name: Build Universal Binary
if: ${{ !fromJson(needs.meta.outputs.skip) }}
runs-on: macos-14
needs: [meta, build]
steps:
# download all artifacts, even if not all are used,
# because this action don't support wildcards
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Create universal binaries
run: |
for arch in x86_64 aarch64; do
target="$arch-apple-darwin"
dir="maa_cli-$target"
tar -xvf "$dir/$target.tar" -C "$dir"
done
lipo -create -output maa maa_cli-x86_64-apple-darwin/maa maa_cli-aarch64-apple-darwin/maa
tar -cvf "universal-apple-darwin.tar" maa
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: maa_cli-universal-apple-darwin
path: universal-apple-darwin.tar
retention-days: 1
if-no-files-found: error
release:
name: Release
if: ${{ !fromJson(needs.meta.outputs.skip) }}
runs-on: ubuntu-latest
needs: [meta, build, build-universal, release-note]
permissions:
contents: write
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANNEL: ${{ needs.meta.outputs.channel }}
VERSION: ${{ needs.meta.outputs.version }}
TAG: ${{ needs.meta.outputs.tag }}
COMMIT: ${{ needs.meta.outputs.commit }}
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Checkout version branch
uses: actions/checkout@v4
with:
ref: version
path: version
- name: Extract files, Generate checksums and Update version.json
run: |
# alpha version info will be updated in all cases
version_files=(version/alpha.json)
# beta version info will be updated in non-alpha releases
[[ "$CHANNEL" != "alpha" ]] && version_files+=(version/beta.json)
# stable version info will only be updated in stable releases
[[ "$CHANNEL" == "stable" ]] && version_files+=(version/stable.json)
# target independent version info
for version_file in "${version_files[@]}"; do
yq -i -oj ".version = \"$VERSION\"" "$version_file"
yq -i -oj ".details.tag = \"$TAG\"" "$version_file"
yq -i -oj ".details.commit = \"$COMMIT\"" "$version_file"
done
targets=(
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
universal-apple-darwin
x86_64-apple-darwin
aarch64-apple-darwin
x86_64-pc-windows-msvc
)
for target in "${targets[@]}"; do
dir="maa_cli-$target"
tar -xvf "$dir/$target.tar" -C "$dir"
# use tar on linux and zip on other platforms
case "$target" in
*-linux-*)
archive_name="maa_cli-v$VERSION-$target.tar.gz"
archive_name_unversioned="maa_cli-$target.tar.gz"
tar -czvf "$archive_name" "$dir/maa"
cp "$archive_name" "$archive_name_unversioned"
;;
*-apple-darwin)
archive_name="maa_cli-v$VERSION-$target.zip"
archive_name_unversioned="maa_cli-$target.zip"
zip -vr "$archive_name" "$dir/maa"
cp "$archive_name" "$archive_name_unversioned"
;;
*-windows-msvc)
archive_name="maa_cli-v$VERSION-$target.zip"
archive_name_unversioned="maa_cli-$target.zip"
zip -vr "$archive_name" "$dir/maa.exe"
cp "$archive_name" "$archive_name_unversioned"
;;
*)
echo "Unknown target: $target"
exit 1
;;
esac
checksum=$(sha256sum "$archive_name")
checksum_hash=${checksum:0:64}
size=$(stat -c%s "$archive_name")
echo "$checksum" > "$archive_name.sha256"
sha256sum "$archive_name_unversioned" > "$archive_name_unversioned.sha256"
# old version info (deprecated)
# only update when a stable release is published
if [ "$CHANNEL" == "stable" ]; then
version_file="version/version.json"
yq -i -oj ".maa-cli.$target.version = \"$VERSION\"" "$version_file"
yq -i -oj ".maa-cli.$target.tag = \"$TAG\"" "$version_file"
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" "$version_file"
yq -i -oj ".maa-cli.$target.size = $size" $version_file
yq -i -oj ".maa-cli.$target.sha256sum = \"$checksum_hash\"" "$version_file"
fi
# target dependent version info
for version_file in "${version_files[@]}"; do
yq -i -oj ".details.assets.$target.name = \"$archive_name\"" "$version_file"
yq -i -oj ".details.assets.$target.size = $size" "$version_file"
yq -i -oj ".details.assets.$target.sha256sum = \"$checksum_hash\"" "$version_file"
done
done
- name: Check existing release
if: ${{ fromJson(needs.meta.outputs.publish) }}
run: |
if gh release view "$TAG" &> /dev/null; then
if [ "$TAG" == "nightly" ]; then
echo "Release as nightly, clear existing release and tag"
gh release delete "$TAG" --yes --cleanup-tag
else
echo "Release $TAG already exists, abort"
exit 1
fi
fi
sleep 5 # wait to avoid the release becomes draft
- name: Create Release
uses: softprops/action-gh-release@v2
if: ${{ fromJson(needs.meta.outputs.publish) }}
with:
name: v${{ needs.meta.outputs.version }}
tag_name: ${{ needs.meta.outputs.tag }}
prerelease: ${{ fromJson(needs.meta.outputs.prerelease) }}
body: ${{ needs.release-note.outputs.content }}
fail_on_unmatched_files: true
files: |
maa_cli-*-unknown-linux-gnu.tar.gz*
maa_cli-*-apple-darwin.zip*
maa_cli-*-pc-windows-msvc.zip*
- name: Commit version.json and Push
working-directory: version
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
{
echo "Commit changes to version.json"
echo '```diff'
git diff ./*.json
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
git commit ./*.json -m 'chore: bump version to v${{ needs.meta.outputs.version }}'
git push --verbose ${{ !fromJson(needs.meta.outputs.publish) && '--dry-run' || ''}}
update-stable:
name: Update Stable Tag
if: ${{ fromJson(needs.meta.outputs.publish) && needs.meta.outputs.channel == 'stable' }}
needs: [meta, release]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.meta.outputs.commit }}
- name: Update Stable Tag
run: |
git tag -f stable ${{ needs.meta.outputs.commit }}
git push --verbose --force origin stable
sync:
name: Sync to MAA Main Repository
if: ${{ fromJson(needs.meta.outputs.publish) && !fromJson(needs.meta.outputs.prerelease) }}
needs: [meta, release]
uses: ./.github/workflows/sync.yml
with:
version: ${{ needs.meta.outputs.version }}
dryrun: false
secrets:
MAA_HOMEBREW_BUMP_PR: ${{ secrets.MAA_HOMEBREW_BUMP_PR }}
publish-homebrew:
name: Publish Homebrew Formulae
needs: [meta, release]
if: ${{ fromJson(needs.meta.outputs.publish) && !fromJson(needs.meta.outputs.prerelease) }}
uses: ./.github/workflows/publish-homebrew.yml
with:
version: ${{ needs.meta.outputs.version }}
dryrun: false
secrets:
MAA_HOMEBREW_BUMP_PR: ${{ secrets.MAA_HOMEBREW_BUMP_PR }}
publish-aur:
name: Publish AUR Package
needs: [meta, release]
if: ${{ fromJson(needs.meta.outputs.publish) && !fromJson(needs.meta.outputs.prerelease) }}
uses: ./.github/workflows/publish-aur.yml
with:
pkgver: ${{ needs.meta.outputs.version }}
dryrun: false
secrets:
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}