-
Notifications
You must be signed in to change notification settings - Fork 8
170 lines (168 loc) · 7.66 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
name: Release
on:
push:
tags:
- "maa_cli-v[0-9]+.[0-9]+.[0-9]+"
- "maa_run-v[0-9]+.[0-9]+.[0-9]+"
jobs:
x86_64-unknown-linux-gnu:
runs-on: ubuntu-latest
permissions:
contents: write
env:
CARGO_BUILD_TARGET: x86_64-unknown-linux-gnu
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout version branch
uses: actions/checkout@v3
with:
ref: version
path: version
- name: Setup Rust
run: |
rustup target add $CARGO_BUILD_TARGET
- name: Build maa-cli
if: contains(github.ref, 'refs/tags/maa_cli-v')
run: cargo build --release --locked --bin maa
- name: Build maa-run
if: contains(github.ref, 'refs/tags/maa_run-v')
env:
MAA_API_URL: https://github.com/MaaAssistantArknights/MaaRelease/raw/main/MaaAssistantArknights/api/version
run: |
cargo run --locked --bin maa -- install stable
cargo build --release --locked --bin maa-run
- name: Archive binaries, generate checksums and update version.json
id: archive
run: |
version_file="$PWD/version/version.json"
target="$CARGO_BUILD_TARGET"
maa_cli_version=$(yq -oy ".package.version" maa-cli/Cargo.toml)
maa_run_version=$(yq -oy ".package.version" maa-run/Cargo.toml)
cd target/x86_64-unknown-linux-gnu/release || exit 1
if [ -f maa ]; then
version=$maa_cli_version
archive_name="maa_cli-v$version-$target.tar.gz"
tar -czvf $archive_name maa &&
checksum=$(shasum -a 256 $archive_name) &&
echo "$checksum" > $archive_name.sha256sum &&
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file &&
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file &&
yq -i -oj ".maa-cli.$target.size = \"$(stat -c %s $archive_name)\"" $version_file &&
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file &&
echo "name=maa-cli v$version" >> $GITHUB_OUTPUT &&
exit 0
fi
if [ -f maa-run ]; then
version=$maa_run_version
archive_name="maa_run-v$version-$target.tar.gz"
tar -czvf $archive_name maa-run &&
checksum=$(shasum -a 256 $archive_name) &&
echo "$checksum" > $archive_name.sha256sum &&
yq -i -oj ".maa-run.$target.version = \"$version\"" $version_file &&
yq -i -oj ".maa-run.$target.name = \"$archive_name\"" $version_file &&
yq -i -oj ".maa-run.$target.size = \"$(stat -c %s $archive_name)\"" $version_file &&
yq -i -oj ".maa-run.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file &&
echo "name=maa-run v$version" >> $GITHUB_OUTPUT &&
exit 0
fi
exit 1
- name: Upload to GitHub Releases
uses: svenstaro/upload-release-action@v2
with:
release_name: ${{ steps.archive.outputs.name }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
file_glob: true
file: target/x86_64-unknown-linux-gnu/release/maa*.tar.gz*
- name: Commit and push version.json
run: |
cd version || exit 1
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
if [ -z "$(git diff version.json)" ]; then
echo "No changes to commit"
exit 0
fi
git commit version.json -m "Update version.json" &&
git push
universal-apple-darwin:
runs-on: macos-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout version branch
uses: actions/checkout@v3
with:
ref: version
path: version
- name: Setup Rust
run: |
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
- name: Build maa-cli
if: contains(github.ref, 'refs/tags/maa_cli-v')
run: cargo build --release --locked --bin maa --target x86_64-apple-darwin --target aarch64-apple-darwin
- name: Build maa-run
if: contains(github.ref, 'refs/tags/maa_run-v')
env:
MAA_API_URL: https://github.com/MaaAssistantArknights/MaaRelease/raw/main/MaaAssistantArknights/api/version
run: |
cargo run --locked --bin maa -- install stable
cargo build --release --locked --bin maa-run --target x86_64-apple-darwin --target aarch64-apple-darwin
- name: Create universal binaries, archive, generate checksums and update version.json
id: archive
run: |
version_file="$PWD/version/version.json"
maa_cli_version=$(yq -oy ".package.version" maa-cli/Cargo.toml)
maa_run_version=$(yq -oy ".package.version" maa-run/Cargo.toml)
target="universal-apple-darwin"
cd target || exit 1
if [[ -f x86_64-apple-darwin/release/maa && -f aarch64-apple-darwin/release/maa ]]; then
version=$maa_cli_version
archive_name="maa_cli-v$version-$target.tar.gz"
lipo -create -output maa x86_64-apple-darwin/release/maa aarch64-apple-darwin/release/maa &&
tar -czvf $archive_name maa &&
checksum=$(shasum -a 256 $archive_name) &&
echo "$checksum" > $archive_name.sha256sum &&
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file &&
yq -i -oj ".maa-cli.$target.name = \"$archive_name\"" $version_file &&
yq -i -oj ".maa-cli.$target.size = \"$(stat -c %s $archive_name)\"" $version_file &&
yq -i -oj ".maa-cli.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file &&
echo "name=maa-cli v$version" >> $GITHUB_OUTPUT &&
exit 0
fi
if [[ -f x86_64-apple-darwin/release/maa-run && -f aarch64-apple-darwin/release/maa-run ]]; then
version=$maa_run_version
archive_name="maa_run-v$version-$target.tar.gz"
lipo -create -output maa-run x86_64-apple-darwin/release/maa-run aarch64-apple-darwin/release/maa-run &&
tar -czvf $archive_name maa-run &&
checksum=$(shasum -a 256 $archive_name) &&
echo "$checksum" > $archive_name.sha256sum &&
yq -i -oj ".maa-run.$target.version = \"$version\"" $version_file &&
yq -i -oj ".maa-run.$target.name = \"$archive_name\"" $version_file &&
yq -i -oj ".maa-run.$target.size = \"$(stat -c %s $archive_name)\"" $version_file &&
yq -i -oj ".maa-run.$target.sha256sum = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file &&
echo "name=maa-run v$version" >> $GITHUB_OUTPUT &&
exit 0
fi
exit 1
- name: Upload to GitHub Releases
uses: svenstaro/upload-release-action@v2
with:
release_name: ${{ steps.archive.outputs.name }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
file_glob: true
file: target/maa*.tar.gz*
make_latest: true
- name: Commit and push version.json
run: |
cd version || exit 1
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
if [ -z "$(git diff version.json)" ]; then
echo "No changes to commit"
exit 0
fi
git commit version.json -m "Update version.json" && git push