-
Notifications
You must be signed in to change notification settings - Fork 3
260 lines (215 loc) · 7.44 KB
/
release.yaml
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
name: Release
on:
push:
branches:
- workflow_release
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-alpha'
- 'v[0-9]+.[0-9]+.[0-9]+-beta'
env:
# Emit backtraces on panics.
RUST_BACKTRACE: full
# Enable colors in cargo output.
CARGO_TERM_COLOR: always
# Use sparse index if supported
# (probably no longer required, but cargo-culted)
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
jobs:
check_release:
name: check_release
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install toolchain
run: rustup show
shell: bash
- name: Run cargo fmt
run: cargo fmt --all -- --check
shell: bash
- name: Run cargo check
run: RUSTFLAGS="-D warnings" cargo check --workspace --locked --all-targets
shell: bash
- name: Run cargo test
run: cargo test --workspace --locked --all-targets --no-fail-fast
shell: bash
- name: Run cargo clippy
run: cargo clippy --workspace --locked --all-targets -- -Dwarnings
shell: bash
- name: Gather release info
id: info
run: |
ref_name='${{ github.ref_name }}'
echo "ref_name: $ref_name"
# is this a test release, or a real release?
if [[ "$ref_name" == 'workflow_release' ]]; then
version='v0.0.0-test'
else
version="$ref_name"
fi
echo "version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
shell: bash
outputs:
version: ${{ steps.info.outputs.version }}
build_release:
name: build_release
needs: ['check_release']
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
# Disable incremental compilation.
CARGO_INCREMENTAL: 0
MECH3AX_VERSION: ${{ needs.check_release.outputs.version }}
TARGET_DIR: target/${{ matrix.target }}/release
STAGING_DIR: mech3ax-${{ needs.check_release.outputs.version }}-${{ matrix.target }}
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
- aarch64-apple-darwin
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-13
- target: aarch64-apple-darwin
os: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install toolchain
run: |
set -x
rustup show
rustup target add '${{ matrix.target }}'
shell: bash
- name: Create staging
run: |
set -x
echo "MECH3AX_VERSION: $MECH3AX_VERSION"
echo "TARGET_DIR: $TARGET_DIR"
echo "STAGING_DIR: $STAGING_DIR"
# create archive staging directory
mkdir "$STAGING_DIR"
# copy supporting files
cp README.md LICENSE "$STAGING_DIR/"
shell: bash
- name: Build release binary (Linux)
if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }}
run: |
cargo build --release --target='${{ matrix.target }}'
set -x
check_version=$("$TARGET_DIR/unzbd" --version | cut -d' ' -f2)
if [[ "$MECH3AX_VERSION" != "$check_version" ]]; then
echo "version mismatch: >$MECH3AX_VERSION< != >$check_version<"
exit 1
fi
cp "$TARGET_DIR/unzbd" "$TARGET_DIR/rezbd" "$STAGING_DIR/"
cp "$TARGET_DIR/libmech3ax.so" "$STAGING_DIR/libmech3ax-$MECH3AX_VERSION.so"
shell: bash
- name: Build release binary (Windows)
if: ${{ matrix.target == 'x86_64-pc-windows-msvc' }}
run: |
cargo build --release --target='${{ matrix.target }}'
set -x
check_version=$("$TARGET_DIR/unzbd.exe" --version | cut -d' ' -f2)
if [[ "$MECH3AX_VERSION" != "$check_version" ]]; then
echo "version mismatch: >$MECH3AX_VERSION< != >$check_version<"
exit 1
fi
cp "$TARGET_DIR/unzbd.exe" "$TARGET_DIR/rezbd.exe" "$STAGING_DIR/"
cp "$TARGET_DIR/mech3ax.dll" "$STAGING_DIR/mech3ax-$MECH3AX_VERSION.dll"
shell: bash
- name: Build release binary (macOS)
if: ${{ matrix.target == 'aarch64-apple-darwin' || matrix.target == 'x86_64-apple-darwin' }}
env:
MACOSX_DEPLOYMENT_TARGET: "12.0"
run: |
set -x
echo "MACOSX_DEPLOYMENT_TARGET: $MACOSX_DEPLOYMENT_TARGET"
xcodebuild -showsdks
set +x
cargo build --release --target='${{ matrix.target }}'
set -x
file "$TARGET_DIR/unzbd"
file "$TARGET_DIR/rezbd"
file "$TARGET_DIR/libmech3ax.dylib"
check_version=$("$TARGET_DIR/unzbd" --version | cut -d' ' -f2)
if [[ "$MECH3AX_VERSION" != "$check_version" ]]; then
echo "version mismatch: >$MECH3AX_VERSION< != >$check_version<"
exit 1
fi
cp "$TARGET_DIR/unzbd" "$TARGET_DIR/rezbd" "$STAGING_DIR/"
cp "$TARGET_DIR/libmech3ax.dylib" "$STAGING_DIR/libmech3ax-$MECH3AX_VERSION.dylib"
shell: bash
- name: Build archive
id: build
run: |
set -x
ls -1 "$STAGING_DIR/"
7z -mx=9 a "$STAGING_DIR.zip" "$STAGING_DIR"
shell: bash
- name: Upload the release assets
uses: actions/upload-artifact@v4
with:
name: mech3ax-${{ needs.check_release.outputs.version }}-${{ matrix.target }}
path: mech3ax-${{ needs.check_release.outputs.version }}-${{ matrix.target }}.zip
if-no-files-found: error
retention-days: 3
compression-level: 0
overwrite: false
create_release:
name: create_release
needs: ['check_release', 'build_release']
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
# IMPORTANT: mandatory for making GitHub Releases
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#overview
contents: write
steps:
- name: Download the release assets
uses: actions/download-artifact@v4
with:
pattern: mech3ax-*
merge-multiple: true
path: assets/
- name: List the release assets
run: ls -1R assets/*
shell: bash
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
version='${{ needs.check_release.outputs.version }}'
echo "version: $version"
# empty arguments
set --
# is this a test release, or a real release?
if [[ "$version" == 'v0.0.0-test' ]]; then
set -- "$@" --target '${{ github.sha }}'
fi
# is this a pre-release (-rc*, -alpha, -beta, -test)?
if [[ "$version" == *"-"* ]]; then
set -- "$@" --prerelease
fi
date=$(env TZ=':America/Los_Angeles' date +'%Y-%m-%d')
echo "date: $date"
echo "args: $@"
set -x
gh release create \
"$version" \
assets/* \
--title "$version ($date)" \
--draft \
--repo '${{ github.repository }}' \
"$@"
shell: bash