forked from cross-rs/cross
-
Notifications
You must be signed in to change notification settings - Fork 2
485 lines (439 loc) · 20.3 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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
on:
pull_request:
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
- name: Run ShellCheck
uses: azohra/[email protected]
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust
with:
components: rustfmt
- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
clippy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust
with:
components: clippy
toolchain: 1.58.1 # MSRV, Minimally Supported Rust Version. Make sure to update README.md
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --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
- uses: ./.github/actions/setup-rust
- uses: ./.github/actions/cargo-llvm-cov
with:
name: test-${{matrix.os}}
- name: Run unit tests
uses: actions-rs/cargo@v1
with:
command: test
args: --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
- uses: ./.github/actions/setup-rust
- run: cargo xtask ci-job check
id: check
shell: bash
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Generate matrix
id: generate-matrix
run: |
if [[ -z "${commit_message}" ]]; then
bors_args=()
else
bors_args="$(echo "${commit_message}" | sed -E 's/^Try #[0-9]+:\s+//')"
declare -a "bors_args=(${bors_args})"
fi
targets=()
index=0
while [[ "${bors_args[$index]-}" == --target ]]; do
index=$(expr $index + 1)
targets+=("${bors_args[$index]}")
index=$(expr $index + 1)
done
selects=()
for target in "${targets[@]}"; do
base=$(echo "${target}" | cut -d '.' -f 1)
sub=$(echo "${target}" | cut -d '.' -sf 2)
selects+=("select(.target | test(\"${base}\")) and if \"${sub}\" != \"\" then .sub == \"${sub}\" else .sub == null end")
done
query=$(printf " or %s" "${selects[@]}")
query="${query:4}"
if [[ "${#targets[@]}" != "0" ]]; then
echo "Only running targets matching '${targets[@]}'."
matrix=$(
yq --output-format json <<< "${matrix}" | jq '[.[] | select('"${query}"')]'
)
else
echo 'Running all targets.'
matrix="$(yq --output-format json <<< "${matrix}")"
fi
jq -C '[.[] | . += {"pretty": ([.target] + [select(.sub != null).sub]) | join(":")}]' <<< "${matrix}"
echo "::set-output name=matrix::$(jq -c '[.[] | . += {"pretty": ([.target] + [select(.sub != null).sub]) | join(":")}]' <<< "${matrix}")"
env:
commit_message: >
${{
((
startsWith(github.event.head_commit.message, 'Try #') &&
github.event.head_commit.author.username == 'bors[bot]'
) && github.event.head_commit.message) || ''
}}
matrix: |
- { target: x86_64-apple-darwin, os: macos-12, deploy: true }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: native qemu-user qemu-system, deploy: true }
- { target: x86_64-unknown-linux-musl, os: ubuntu-latest, std: 1, run: 1, deploy: true }
- { target: x86_64-pc-windows-msvc, os: windows-2019, deploy: true }
- { target: x86_64-unknown-linux-gnu, sub: centos, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: native qemu-user qemu-system }
- { target: aarch64-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: arm-unknown-linux-gnueabi, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: arm-unknown-linux-gnueabihf, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: armv7-unknown-linux-gnueabi, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user }
- { target: armv7-unknown-linux-gnueabihf, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: thumbv7neon-unknown-linux-gnueabihf, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: i586-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: i686-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: native qemu-user qemu-system }
- { target: mips-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user }
- { target: mipsel-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: mips64-unknown-linux-gnuabi64, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: mips64el-unknown-linux-gnuabi64, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: mips64-unknown-linux-muslabi64, os: ubuntu-latest, cpp:1, dylib: 1, std: 1, run: 1, runners: qemu-user }
- { target: mips64el-unknown-linux-muslabi64, os: ubuntu-latest, std: 1, run: 1 }
- { target: powerpc-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: powerpc64-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: powerpc64le-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: s390x-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: sparc64-unknown-linux-gnu, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user qemu-system }
- { target: aarch64-unknown-linux-musl, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: arm-unknown-linux-musleabihf, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: arm-unknown-linux-musleabi, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: armv5te-unknown-linux-gnueabi, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: armv5te-unknown-linux-musleabi, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: armv7-unknown-linux-musleabi, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: armv7-unknown-linux-musleabihf, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: i586-unknown-linux-musl, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user }
- { target: i686-unknown-linux-musl, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1, runners: qemu-user }
- { target: mips-unknown-linux-musl, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: mipsel-unknown-linux-musl, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, run: 1 }
- { target: aarch64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
- { target: arm-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
- { target: armv7-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
- { target: thumbv7neon-linux-androideabi, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
- { target: i686-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
- { target: x86_64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
- { target: x86_64-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
- { target: i686-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
# Disabled for now, see https://github.com/rust-lang/rust/issues/98216
#-{ target: asmjs-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
- { target: wasm32-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
- { target: x86_64-unknown-dragonfly, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, build-std: 1 }
- { target: i686-unknown-freebsd, os: ubuntu-latest, dylib: 1, std: 1 }
- { target: x86_64-unknown-freebsd, os: ubuntu-latest, dylib: 1, std: 1 }
- { target: x86_64-unknown-netbsd, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1 }
- { target: sparcv9-sun-solaris, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1 }
- { target: x86_64-sun-solaris, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1 }
- { target: x86_64-unknown-illumos, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1 }
- { target: thumbv6m-none-eabi, os: ubuntu-latest, std: 1 }
- { target: thumbv7em-none-eabi, os: ubuntu-latest, std: 1 }
- { target: thumbv7em-none-eabihf, os: ubuntu-latest, std: 1 }
- { target: thumbv7m-none-eabi, os: ubuntu-latest, std: 1 }
- { target: cross, os: ubuntu-latest }
- { target: zig, os: ubuntu-latest }
build:
name: target (${{ matrix.pretty }},${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: [shellcheck, test, generate-matrix, check]
if: github.event_name == 'push'
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
- uses: ./.github/actions/setup-rust
- name: Set up Docker Buildx
if: runner.os == 'Linux'
uses: docker/setup-buildx-action@v1
- 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}"
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 }}
image: ${{ steps.build-docker-image.outputs.image }}
- 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@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to GitHub Container Registry
if: >
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]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- 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]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- 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]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- 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]
runs-on: ubuntu-latest
if: github.actor == 'bors[bot]'
steps:
- uses: actions/checkout@v3
- 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
publish:
needs: [build, check, fmt, clippy, cargo-deny]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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]
if: always()
runs-on: ubuntu-latest
steps:
- name: Result
run: |
jq -C <<< "${needs}"
# Check if all needs were successfull 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
- uses: ./.github/actions/setup-rust
- uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/artifacts
- name: Grab PR number
run: echo "::set-output name=pr::"$(echo $commit_message | sed -ne 's/.*\#\(.*\):/\1/p')
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