-
Notifications
You must be signed in to change notification settings - Fork 8
287 lines (272 loc) · 9.6 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
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"
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
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@v2
with:
config: cliff.toml
args: -vv ${{ fromJson(needs.meta.outputs.prerelease) && '-u' || '-l' }}
build:
name: Build
needs: meta
if: ${{ !fromJson(needs.meta.outputs.skip) }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
- x86_64
- aarch64
exclude:
# Failed to cross compile ring on Windows
- os: windows-latest
arch: aarch64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: ./.github/actions/setup
with:
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
- name: Patch Cargo.toml (macOS only)
if: ${{ startsWith(matrix.os, 'macos') }}
working-directory: maa-cli
run: |
sed -i "" '1,6 s/^version = .*/version = "${{ needs.meta.outputs.version }}"/' Cargo.toml
- name: Patch Cargo.tom (GNU sed)
if: ${{ !startsWith(matrix.os, 'macos') }}
working-directory: maa-cli
run: |
sed -i '1,6 s/^version = .*/version = "${{ needs.meta.outputs.version }}"/' Cargo.toml
- name: Build
env:
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
CARGO_PROFILE_RELEASE_LTO: true
CARGO_PROFILE_RELEASE_STRIP: true
run: |
cargo build --release --package maa-cli
- name: Tar Artifact
run: |
tar -cvf "$CARGO_BUILD_TARGET.tar" -C "target/$CARGO_BUILD_TARGET/release" maa
- name: Upload Artifact
uses: actions/upload-artifact@v3
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-latest
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@v3
- 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@v3
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
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
- name: Checkout version branch
uses: actions/checkout@v4
with:
ref: version
path: version
- name: Extract files, Generate checksums and Update version.json
run: |
VERSION=${{ needs.meta.outputs.version }}
TAG=${{ needs.meta.outputs.tag }}
COMMIT=${{ needs.meta.outputs.commit }}
CHANNEL=${{ needs.meta.outputs.channel }}
version_files=(
version/alpha.json
)
[ "$CHANNEL" != "alpha" ] && version_files+=(version/beta.json)
[ "$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-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
if [[ "$target" == *"linux"* ]]; then
archive_name="maa_cli-v$VERSION-$target.tar.gz"
tar -czvf "$archive_name" "$dir/maa"
else
archive_name="maa_cli-v$VERSION-$target.zip"
zip -r "$archive_name" "$dir/maa"
fi
checksum=$(sha256sum "$archive_name")
checksum_hash=${checksum:0:64}
size=$(stat -c%s "$archive_name")
echo "$checksum" > "$archive_name.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: Create Release
uses: softprops/action-gh-release@v1
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-v${{ needs.meta.outputs.version }}-*-unknown-linux-gnu.tar.gz*
maa_cli-v${{ needs.meta.outputs.version }}-universal-apple-darwin.zip*
maa_cli-v${{ needs.meta.outputs.version }}-*-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' || ''}}
publish-homebrew:
needs: [meta, release]
if: ${{ fromJson(needs.meta.outputs.publish) && !fromJson(needs.meta.outputs.prerelease) }}
name: Publish Homebrew
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:
needs: [meta, release]
if: ${{ fromJson(needs.meta.outputs.publish) && !fromJson(needs.meta.outputs.prerelease) }}
name: Publish AUR Package
uses: ./.github/workflows/publish-aur.yml
with:
pkgver: ${{ needs.meta.outputs.version }}
dryrun: false
secrets:
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}