-
Notifications
You must be signed in to change notification settings - Fork 378
453 lines (408 loc) · 14.2 KB
/
ci.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
on:
workflow_call:
inputs:
matrix-args:
required: false
type: string
description: Arguments to pass to `cargo xtask ci-job target-matrix`
checkout-ref:
required: false
type: string
description: Used to checkout a specific ref, instead of the default ref with `actions/checkout` action
pull_request:
merge_group:
push:
branches: [main, staging, trying]
tags:
- "v*.*.*"
name: CI
env:
CARGO_NET_RETRY: 3
CARGO_HTTP_CHECK_REVOKE: false
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- name: Run ShellCheck
uses: azohra/[email protected]
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: EmbarkStudios/cargo-deny-action@v1
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
with:
components: rustfmt
- name: Run rustfmt
run: cargo fmt -- --check
clippy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
with:
components: clippy
toolchain: 1.77.2 # MSRV, Minimally Supported Rust Version. Make sure to update README.md and clippy.toml
- name: Run clippy
run: cargo clippy --locked --all-targets --all-features --workspace -- -D warnings
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- uses: ./.github/actions/cargo-llvm-cov
with:
name: test-${{matrix.os}}
- name: Run unit tests
run: cargo test --locked --all-targets --workspace --all-features
timeout-minutes: 10
check:
runs-on: ubuntu-latest
outputs:
is-latest: ${{ steps.check.outputs.is-latest }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- run: cargo xtask ci-job check
id: check
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
tests: ${{ steps.generate-matrix.outputs.tests }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: Generate matrix
id: generate-matrix
run: cargo xtask ci-job target-matrix ${{ github.event_name == 'merge_group' && format('--merge-group {0}', github.ref) || '' }} ${{ inputs.matrix-args || '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
name: target (${{ matrix.pretty }},${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: [shellcheck, test, generate-matrix, check]
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' || github.event_name == 'issue_comment' || github.event_name == 'schedule') && needs.generate-matrix.outputs.matrix != '{}' && needs.generate-matrix.outputs.matrix != '[]' && needs.generate-matrix.outputs.matrix != ''
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.pretty }}
cancel-in-progress: false
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
outputs:
has-image: ${{ steps.prepare-meta.outputs.has-image }}
images: ${{ steps.build-docker-image.outputs.images && fromJSON(steps.build-docker-image.outputs.images) }}
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: Set up Docker Buildx
if: runner.os == 'Linux'
uses: docker/setup-buildx-action@v2
- name: Build xtask
run: cargo build -p xtask
- name: Prepare Meta
id: prepare-meta
timeout-minutes: 60
run: cargo xtask ci-job prepare-meta "${TARGET}${SUB:+.$SUB}"
env:
TARGET: ${{ matrix.target }}
SUB: ${{ matrix.sub }}
shell: bash
- name: LLVM instrument coverage
id: cov
uses: ./.github/actions/cargo-llvm-cov
if: steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant != 'zig'
with:
name: cross-${{matrix.pretty}}
- name: Install cross
if: matrix.deploy
run: cargo install --path . --force --debug
- name: Docker Meta
if: steps.prepare-meta.outputs.has-image
id: docker-meta
uses: docker/metadata-action@v4
with:
images: |
name=${{ steps.prepare-meta.outputs.image }}
labels: |
${{ fromJSON(steps.prepare-meta.outputs.labels) }}
- name: Build Docker image
id: build-docker-image
if: steps.prepare-meta.outputs.has-image
timeout-minutes: 120
run: cargo xtask build-docker-image -v "${TARGET}${SUB:+.$SUB}" ${{ matrix.verbose && '-v' || '' }}
env:
TARGET: ${{ matrix.target }}
SUB: ${{ matrix.sub }}
LABELS: ${{ steps.docker-meta.outputs.labels }}
LATEST: ${{ needs.check.outputs.is-latest || 'false' }}
shell: bash
- name: Set Docker image for test
if: steps.prepare-meta.outputs.has-image
run: |
TARGET_VAR="cross_target_${TARGET//-/_}_image"
echo "${TARGET_VAR^^}=${IMAGE}" | tee -a "${GITHUB_ENV}"
env:
TARGET: ${{ matrix.target }}
IMAGE: ${{ steps.build-docker-image.outputs.image }}
shell: bash
- name: Test Image
if: steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'default'
run: ./ci/test.sh
env:
TARGET: ${{ matrix.target }}
CPP: ${{ matrix.cpp }}
DYLIB: ${{ matrix.dylib }}
STD: ${{ matrix.std }}
BUILD_STD: ${{ matrix.build-std }}
RUN: ${{ matrix.run }}
RUNNERS: ${{ matrix.runners }}
shell: bash
- uses: ./.github/actions/cargo-install-upload-artifacts
if: matrix.deploy
with:
target: ${{ matrix.target }}
- name: Test Zig Image
if: steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'zig'
run: ./ci/test-zig-image.sh
shell: bash
- name: Test Cross Image
if: steps.prepare-meta.outputs.has-image && steps.prepare-meta.outputs.test-variant == 'cross'
run: ./ci/test-cross-image.sh
env:
TARGET: 'aarch64-unknown-linux-gnu'
IMAGE: 'ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main'
shell: bash
- name: Login to GitHub Container Registry
if: steps.prepare-meta.outputs.has-image
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to GitHub Container Registry
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') &&
steps.prepare-meta.outputs.has-image && (
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
startsWith(github.ref, 'refs/tags/v')
)
run: cargo xtask build-docker-image -v --push "${TARGET}${SUB:+.$SUB}"
env:
TARGET: ${{ matrix.target }}
SUB: ${{ matrix.sub }}
LABELS: ${{ steps.docker-meta.outputs.labels }}
LATEST: ${{ needs.check.outputs.is-latest || 'false' }}
shell: bash
# we should always have an artifact from a previous build.
remote:
needs: [test, check, generate-matrix]
if: fromJson(needs.generate-matrix.outputs.tests).remote
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: LLVM instrument coverage
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-remote
- name: Run Remote Test
env:
TARGET: aarch64-unknown-linux-gnu
run: ./ci/test-remote.sh
shell: bash
bisect:
needs: [test, check, generate-matrix]
if: fromJson(needs.generate-matrix.outputs.tests).bisect
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: LLVM instrument coverage
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-bisect
- name: Run Bisect Test
env:
TARGET: aarch64-unknown-linux-gnu
run: ./ci/test-bisect.sh
shell: bash
foreign:
needs: [test, check, generate-matrix]
if: fromJson(needs.generate-matrix.outputs.tests).foreign
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: LLVM instrument coverage
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-bisect
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Set up docker buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
- name: Run Foreign toolchain test
run: ./ci/test-foreign-toolchain.sh
shell: bash
docker-in-docker:
needs: [test, check, generate-matrix]
if: fromJson(needs.generate-matrix.outputs.tests).docker-in-docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: LLVM instrument coverage
uses: ./.github/actions/cargo-llvm-cov
with:
name: integration-docker-in-docker
- name: Run Docker-in-Docker Test
env:
TARGET: aarch64-unknown-linux-gnu
IMAGE: 'ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main'
run: ./ci/test-docker-in-docker.sh
shell: bash
podman:
name: podman
runs-on: ubuntu-latest
needs: [shellcheck, test, check, generate-matrix]
if: fromJson(needs.generate-matrix.outputs.tests).podman
strategy:
fail-fast: false
outputs:
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- name: Install Podman
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt-get install podman --no-install-recommends --assume-yes
- name: LLVM instrument coverage
id: cov
uses: ./.github/actions/cargo-llvm-cov
with:
name: cross-podman-aarch64-unknown-linux-gnu
- name: Install cross
run: cargo install --path . --force --debug
- name: Run Podman Test
run: ./ci/test-podman.sh
env:
CROSS_CONTAINER_ENGINE: podman
TARGET: aarch64-unknown-linux-gnu
shell: bash
publish:
needs: [build, check, fmt, clippy, cargo-deny]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- uses: ./.github/actions/cargo-publish
with:
cargo-registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
conclusion:
needs: [shellcheck, fmt, clippy, test, generate-matrix, build, publish, check, remote, bisect, docker-in-docker, foreign, podman]
if: always()
runs-on: ubuntu-latest
steps:
- name: Result
run: |
jq -C <<< "${needs}"
# Check if all needs were successful or skipped.
"$(jq -r 'all(.result as $result | (["success", "skipped"] | contains([$result])))' <<< "${needs}")"
env:
needs: ${{ toJson(needs) }}
code-cov:
name: Coverage
needs: [test, build, conclusion, generate-matrix]
# should check that there are any artifacts, if not skip
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.test.result == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-ref }}
- uses: ./.github/actions/setup-rust
- uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/artifacts
- name: Grab PR number
run: echo "pr=$(echo ${commit_message} | sed -ne 's/.*#\(.*\):/\1/p')" >> $GITHUB_OUTPUT
id: pr-number
if: ${{ !github.event.pull_request.number }}
env:
commit_message: >
${{
((
startsWith(github.event.head_commit.message, 'Try #') &&
github.event.head_commit.author.username == 'bors[bot]'
) && github.event.head_commit.message) || ''
}}
- name: Upload to codecov.io
run: |
set -x
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
sha_rev=$(git rev-parse HEAD)
for file in $(find ${artifacts} -name "lcov.*.info" -exec ls {} +); do
name=$(echo $file | awk -F'.' '{print $2}');
./codecov -F $name ${pr:+-P ${pr}} -f $file --sha ${sha_rev} -n $name;
done
env:
pr: ${{ steps.pr-number.outputs.pr }}
artifacts: ${{ runner.temp }}/artifacts