-
Notifications
You must be signed in to change notification settings - Fork 8
224 lines (216 loc) · 7.51 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
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:
dryrun:
description: Don't create release
default: true
required: true
type: boolean
defaults:
run:
shell: bash
permissions:
contents: read
jobs:
meta:
runs-on: ubuntu-latest
outputs:
dryrun: ${{ steps.dryrun.outputs.dryrun }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if Dryrun
id: dryrun
run: |
if [[ "$GITHUB_EVENT_NAME" = "push" && "$GITHUB_REF" = "refs/tags/v"* ]]; then
dryrun=false
elif [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
dryrun=${{ inputs.dryrun }}
else
dryrun=true
fi
echo "dryrun=$dryrun" >> $GITHUB_OUTPUT
- name: Get Version
id: version
run: |
CARGO_VERSION=$(yq -oy ".package.version" maa-cli/Cargo.toml)
# check if version is equal to tag if not PR
if [ "$GITHUB_EVENT_NAME" != "pull_request" ]; then
REF=${{ github.ref }}
REF_VERSION=${REF#refs/tags/v}
if [ "$REF_VERSION" != "$CARGO_VERSION" ]; then
echo "Version mismatch: $REF_VERSION != $CARGO_VERSION"
fi
fi
echo "Version: $CARGO_VERSION"
echo "version=$CARGO_VERSION" >> $GITHUB_OUTPUT
build:
name: Build
needs: meta
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
# - windows-latest
arch:
- x86_64
- aarch64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Cross
if: matrix.arch == 'aarch64' && matrix.os == 'ubuntu-latest'
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Setup Environment
run: |
OS=${{ matrix.os }}
ARCH=${{ matrix.arch }}
if [ "$OS" = "macos-latest" ]; then
CARGO_CMD=cargo
CARGO_BUILD_TARGET="$ARCH-apple-darwin"
rustup target add $CARGO_BUILD_TARGET
else
if [ "$ARCH" = "aarch64" ]; then
CARGO_CMD=cross
else
CARGO_CMD=cargo
fi
CARGO_BUILD_TARGET="$ARCH-unknown-linux-gnu"
fi
echo "CARGO_CMD=$CARGO_CMD" >> $GITHUB_ENV
echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET" >> $GITHUB_ENV
- name: Build
id: build
run: |
$CARGO_CMD build --release --locked --package maa-cli
cd "target/$CARGO_BUILD_TARGET/release"
tarball="$CARGO_BUILD_TARGET.tar"
tar -cvf $tarball maa
echo "file_path=$PWD/$tarball" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: maa_cli-${{ env.CARGO_BUILD_TARGET }}
path: ${{ steps.build.outputs.file_path }}
retention-days: 1
build-universal:
name: Build Universal Binary
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
id: build
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
tarball="universal-apple-darwin.tar"
tar -cvf $tarball maa
echo "file_path=$PWD/$tarball" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: maa_cli-universal-apple-darwin
path: ${{ steps.build.outputs.file_path }}
retention-days: 1
release:
name: Release
runs-on: ubuntu-latest
needs: [meta, build, build-universal]
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 }}
for target in x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu universal-apple-darwin; do
dir="maa_cli-$target"
tar -xvf "$dir/$target.tar" -C "$dir"
if [ "$target" == "universal-apple-darwin" ]; then
archive_name="maa_cli-v$version-$target.zip"
zip -r $archive_name $dir/maa
else
archive_name="maa_cli-v$version-$target.tar.gz"
tar -czvf $archive_name $dir/maa
fi
checksum=$(sha256sum $archive_name)
size=$(stat -c%s $archive_name)
checksum_hash=$(echo $checksum | cut -d ' ' -f 1)
echo $checksum > $archive_name.sha256sum
version_file="version/version.json"
yq -i -oj ".maa-cli.$target.version = \"$version\"" $version_file
yq -i -oj ".maa-cli.$target.tag = \"v$version\"" $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 = \"$(echo $checksum | cut -d ' ' -f 1)\"" $version_file
done
- name: Create Release
uses: softprops/action-gh-release@v1
if: ${{ !fromJson(needs.meta.outputs.dryrun) }}
with:
name: v${{ needs.meta.outputs.version }}
generate_release_notes: true
fail_on_unmatched_files: true
files: |
maa_cli-v${{ needs.meta.outputs.version }}-x86_64-unknown-linux-gnu.tar.gz*
maa_cli-v${{ needs.meta.outputs.version }}-aarch64-unknown-linux-gnu.tar.gz*
maa_cli-v${{ needs.meta.outputs.version }}-universal-apple-darwin.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 '```diff' >> $GITHUB_STEP_SUMMARY
git diff version.json >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
git commit version.json -m "Update version.json"
git push --verbose ${{ fromJson(needs.meta.outputs.dryrun) && '--dry-run' || ''}}
publish-homebrew:
needs: [meta, release]
name: Publish Homebrew
uses: ./.github/workflows/publish-homebrew.yml
with:
version: v${{ needs.meta.outputs.version }}
dryrun: ${{ fromJson(needs.meta.outputs.dryrun) }}
secrets:
MAA_HOMEBREW_BUMP_PR: ${{ secrets.MAA_HOMEBREW_BUMP_PR }}
publish-aur:
needs: [meta, release]
if: ${{ !fromJson(needs.meta.outputs.dryrun) }}
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 }}