-
Notifications
You must be signed in to change notification settings - Fork 4
357 lines (305 loc) · 11.1 KB
/
workflow.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
name: Build and Release
on:
push:
branches: [ "release/**", "develop", "staging/**" ]
tags: [ "samedec-*" ]
pull_request:
branches: [ "develop" ]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# perform basic code quality checks,
# then run `cargo vendor` and cache it
check_and_vendor:
runs-on: ubuntu-latest
container:
image: ghcr.io/cbs228/sameold/builder/x86_64-unknown-linux-gnu:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checking for whitespace errors (PRs only)
if: github.event.pull_request.base.sha
run: |
git diff --check "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" || {
echo \
'::error title={Failed git diff --check}::Your pull request introduces whitespace errors, which is not allowed. Please run:%0A%0A'\
' git rebase --whitespace=fix%0A'\
' git push -f%0A%0Ato correct and resubmit.'
exit 1;
}
- name: Checking for cargo-fmt errors (PRs only)
if: github.event.pull_request.base.sha
run: |
cargo fmt --check || { \
echo \
'::error title={Failed cargo-fmt --check}::Your pull request does not conform to cargo-fmt, which is not allowed. Please run:%0A%0A' \
' cargo fmt%0A' \
' git commit -a --amend%0A' \
' git push -f%0A%0Ato correct and resubmit. If the `cargo fmt` touches code which is not part of your original PR, please let us know in the comments.'
exit 1;
}
- uses: actions/cache@v4
name: Update crate cargo-vendor cache
id: vendor_cache
with:
path: |
.cargo
vendor
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-vendor
enableCrossOsArchive: true
- uses: actions/cache@v4
name: Update cargo registry cache
if: steps.vendor_cache.outputs.cache-hit != 'true'
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-cache-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-cache
- name: Vendor sources
if: steps.vendor_cache.outputs.cache-hit != 'true'
run: |
mkdir -p .cargo
mkdir -p vendor
cargo vendor --versioned-dirs --locked >.cargo/config.toml
- name: Check Rust lints (PRs only)
if: github.event.pull_request.base.sha
run: |
cargo check --frozen --locked --workspace || { \
echo \
'::error title={Failed cargo-check}::`cargo check` must pass without errors. Please correct Rust compiler lints. When you are finished, please run:%0A%0A' \
' cargo fmt%0A' \
' git commit -a --amend%0A' \
' git push -f%0A%0Ato correct and resubmit. If this requires you to touch code which is not part of your original PR, please let us know in the comments.'
exit 1;
}
- name: Check documentation build (PRs only)
if: github.event.pull_request.base.sha
run: |
cargo doc --frozen --locked --no-deps --workspace || { \
echo \
'::error title={Failed cargo-doc build}::Documentation failed to build. `cargo doc` must be able to generate crate documentation without errors. Please fix. When you are finished, please run:%0A%0A' \
' cargo fmt%0A' \
' git commit -a --amend%0A' \
' git push -f%0A%0Ato correct and resubmit. If this requires you to touch code which is not part of your original PR, please let us know in the comments.'
exit 1;
}
# test sameold with all crate feature combinations,
# in our Linux container
test_sameold:
strategy:
matrix:
features: ['', 'chrono']
runs-on: ubuntu-latest
needs: check_and_vendor
container:
image: ghcr.io/cbs228/sameold/builder/x86_64-unknown-linux-gnu:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
CARGO_NET_OFFLINE: "true"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
steps:
- uses: actions/checkout@v3
- name: Record environment
run: cargo version
- uses: actions/cache/restore@v4
name: Restore crate cargo-vendor cache
with:
path: |
.cargo
vendor
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: Build and test sameold
shell: bash
run: |
cargo test --frozen -p sameold --verbose --no-default-features --features "${{ matrix.features }}"
# Test and release samedec on Linux, via containers
release_samedec_linux:
runs-on: ubuntu-latest
needs: check_and_vendor
name: linux-${{ matrix.target }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
- target: aarch64-unknown-linux-gnu
- target: armv7-unknown-linux-gnueabihf
- target: i686-unknown-linux-gnu
container:
image: ghcr.io/cbs228/sameold/builder/${{ matrix.target }}:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
CARGO_NET_OFFLINE: "true"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
RUSTFLAGS: '-C strip=symbols'
steps:
- uses: actions/checkout@v3
- uses: actions/cache/restore@v4
name: Restore crate cargo-vendor cache
with:
path: |
.cargo
vendor
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: "debug: cross-compile and cross-test"
run: |
cargo test --offline --frozen --workspace
- name: "release: cross-compile, cross-test, and install"
run: |
cargo test --offline --frozen --release --workspace &&
cargo install --offline --frozen --path=crates/samedec
- name: Run integration tests on release-mode build
run: |
qemu-run-maybe samedec --version &&
./sample/test.sh qemu-run-maybe samedec
- name: Copy artifact
run: |
cp /install/bin/samedec /install/bin/samedec-${{ matrix.target }}
- name: Store artifact
uses: actions/upload-artifact@v4
with:
name: samedec-${{ matrix.target }}
path: /install/bin/samedec-${{ matrix.target }}
retention-days: 3
- name: Upload tagged release (tags only)
uses: svenstaro/upload-release-action@v2
if: startsWith(github.ref, 'refs/tags/samedec-')
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: /install/bin/samedec-${{ matrix.target }}
overwrite: true
- name: Update tag for nightly release (develop-branch only)
uses: richardsimko/update-tag@v1
if: github.ref == 'refs/heads/develop'
with:
tag_name: latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload nightly release (develop-branch only)
uses: svenstaro/upload-release-action@v2
if: github.ref == 'refs/heads/develop'
with:
tag: "latest"
release_name: "Nightly Release"
body: "This is a rolling release built from the latest `develop` branch."
prerelease: true
file: /install/bin/samedec-${{ matrix.target }}
overwrite: true
# MacOS and Windows builds
release_samedec_nonlinux:
strategy:
matrix:
include:
- os: windows-latest
os_short: windows
target: x86_64-pc-windows-msvc
rustflags: '-C strip=symbols -C target-feature=+crt-static'
dotexe: '.exe'
- os: macos-latest
os_short: macos
target: aarch64-apple-darwin
rustflags: '-C strip=symbols'
dotexe: ''
- os: macos-latest
os_short: macos
target: x86_64-apple-darwin
rustflags: '-C strip=symbols'
dotexe: ''
runs-on: ${{ matrix.os }}
name: ${{ matrix.os_short }}-${{ matrix.target }}
needs: check_and_vendor
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
CARGO_NET_OFFLINE: "true"
CARGO_INSTALL_ROOT: "install/"
RUSTFLAGS: ${{ matrix.rustflags }}
samedec_exe: "install/bin/samedec${{ matrix.dotexe }}"
samedec_target_exe: "install/bin/samedec-${{ matrix.target}}${{ matrix.dotexe }}"
steps:
- uses: actions/checkout@v3
- name: Record environment
shell: bash
run: cargo version
- uses: actions/cache/restore@v4
name: Restore crate cargo-vendor cache
with:
path: |
.cargo
vendor
key: cargo-vendor-${{ hashFiles('**/Cargo.lock') }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: "debug: compile and test"
shell: bash
run: |
rustup target add "${CARGO_BUILD_TARGET}" &&
cargo test --offline --frozen --workspace
- name: "release: cross-compile, cross-test, and install"
shell: bash
run: |
mkdir -p "${CARGO_INSTALL_ROOT}" &&
export PATH="$(realpath ${CARGO_INSTALL_ROOT})/bin:${PATH}"
cargo test --offline --frozen --release --workspace &&
cargo install --offline --frozen --path=crates/samedec
- name: Run integration tests on release-mode build
shell: bash
run: |
export PATH="$(realpath ${CARGO_INSTALL_ROOT})/bin:${PATH}"
samedec --version &&
pushd ./sample && ./test.sh samedec && popd
- name: Copy artifact
shell: bash
run: |
cp "$samedec_exe" "$samedec_target_exe"
- name: Store artifact
uses: actions/upload-artifact@v4
with:
name: samedec-${{ env.CARGO_BUILD_TARGET }}
path: ${{ env.samedec_target_exe }}
retention-days: 3
- name: Upload tagged release (tags only)
uses: svenstaro/upload-release-action@v2
if: startsWith(github.ref, 'refs/tags/samedec-')
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.samedec_target_exe }}
overwrite: true
- name: Update tag for nightly release (develop-branch only)
uses: richardsimko/update-tag@v1
if: github.ref == 'refs/heads/develop'
with:
tag_name: latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload nightly release (develop-only)
uses: svenstaro/upload-release-action@v2
if: github.ref == 'refs/heads/develop'
with:
tag: "latest"
release_name: "Nightly Release"
body: "This is a rolling release built from the latest `develop` branch."
prerelease: true
file: ${{ env.samedec_target_exe }}
overwrite: true