-
-
Notifications
You must be signed in to change notification settings - Fork 60
392 lines (350 loc) · 11.7 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
name: CI
on:
workflow_dispatch:
workflow_call:
inputs:
additional_key:
required: true
type: string
default: ""
merge_group:
pull_request:
types:
- opened
- reopened
- synchronize
schedule:
- cron: "0 3 * * 6"
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number || github.sha }}-${{ inputs.additional_key }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
JUST_ENABLE_H3: true
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 4
CARGO_PROFILE_DEV_CODEGEN_UNITS: 4
CARGO_PROFILE_CHECK_ONLY_CODEGEN_UNITS: 4
jobs:
changed-files:
runs-on: ubuntu-latest
name: Test changed-files
permissions:
pull-requests: read
outputs:
crates_changed: ${{ steps.list-changed-files.outputs.crates_changed }}
has_detect_target_changed: ${{ steps.list-changed-files.outputs.has_detect_target_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
dir_names: true
dir_names_exclude_current_dir: true
dir_names_max_depth: 2
- name: List all changed files
id: list-changed-files
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
set -euxo pipefail
crates_changed="$(for file in $ALL_CHANGED_FILES; do echo $file; done | grep crates | cut -d / -f 2 | sed 's/^bin$/cargo-binstall/' || echo)"
has_detect_target_changed="$(echo "$crates_changed" | grep -q detect-targets && echo true || echo false)"
echo "crates_changed=${crates_changed//$'\n'/ }" | tee -a "$GITHUB_OUTPUT"
echo "has_detect_target_changed=$has_detect_target_changed" | tee -a "$GITHUB_OUTPUT"
unit-tests:
needs: changed-files
runs-on: ubuntu-latest
env:
CARGO_BUILD_TARGET: x86_64-unknown-linux-gnu
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/just-setup
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
with:
tools: cargo-nextest
- name: Decide crates to test
shell: bash
env:
CRATES_CHANGED: ${{ needs.changed-files.outputs.crates_changed }}
run: |
ARGS=""
for crate in $CRATES_CHANGED; do
ARGS="$ARGS -p $crate"
done
echo "CARGO_NEXTEST_ADDITIONAL_ARGS=$ARGS" | tee -a "$GITHUB_ENV"
- run: just unit-tests
if: env.CARGO_NEXTEST_ADDITIONAL_ARGS != ''
env:
GITHUB_TOKEN: ${{ secrets.CI_TEST_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
CI_UNIT_TEST_GITHUB_TOKEN: ${{ secrets.CI_UNIT_TEST_GITHUB_TOKEN }}
e2e-tests:
if: github.event_name != 'pull_request'
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/just-setup
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN }}
- run: just build
- run: just e2e-tests
env:
GITHUB_TOKEN: ${{ secrets.CI_TEST_GITHUB_TOKEN }}
cross-check:
strategy:
fail-fast: false
matrix:
include:
- target: armv7-unknown-linux-musleabihf
os: ubuntu-latest
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- name: Enable cargo-zigbuild
if: matrix.os == 'ubuntu-latest'
run: echo JUST_USE_CARGO_ZIGBUILD=true >> "$GITHUB_ENV"
- uses: ./.github/actions/just-setup
with:
tools: [email protected]
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
- run: just avoid-dev-deps
- run: just check
lint:
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/just-setup
env:
# just-setup use binstall to install sccache,
# which works better when we provide it with GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.CI_RELEASE_TEST_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
- run: just toolchain rustfmt,clippy
- run: just avoid-dev-deps
- run: just lint
pr-info:
outputs:
is-release: ${{ steps.meta.outputs.is-release }}
crate: ${{ steps.meta.outputs.crates-names }}
runs-on: ubuntu-latest
steps:
- id: meta
if: github.event_name == 'pull_request'
uses: cargo-bins/release-meta@v1
with:
event-data: ${{ toJSON(github.event) }}
extract-notes-under: "### Release notes"
release-dry-run:
needs: pr-info
uses: ./.github/workflows/release-cli.yml
if: github.event_name != 'pull_request'
secrets: inherit
with:
info: |
{
"is-release": false,
"crate": "${{ needs.pr-info.outputs.crate }}",
"version": "0.0.0",
"notes": ""
}
CARGO_PROFILE_RELEASE_LTO: no
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 4
detect-targets-build:
needs: changed-files
if: needs.changed-files.outputs.has_detect_target_changed == 'true'
runs-on: ubuntu-latest
env:
CARGO_BUILD_TARGET: x86_64-unknown-linux-musl
steps:
- uses: actions/checkout@v4
- name: Install ${{ env.CARGO_BUILD_TARGET }} target
run: |
rustup target add $CARGO_BUILD_TARGET
pip3 install -r zigbuild-requirements.txt
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Build detect-targets
run: |
cargo zigbuild --features cli-logging --target $CARGO_BUILD_TARGET
# Set working directory here, otherwise `cargo-zigbuild` would download
# and build quite a few unused dependencies.
working-directory: crates/detect-targets
- uses: actions/upload-artifact@v4
with:
name: detect-targets
path: target/${{ env.CARGO_BUILD_TARGET }}/debug/detect-targets
detect-targets-alpine-test:
runs-on: ubuntu-latest
needs:
- detect-targets-build
- changed-files
if: needs.changed-files.outputs.has_detect_target_changed == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: detect-targets
- run: chmod +x detect-targets
- name: Run test in alpine
run: |
docker run --rm \
--mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
--mount src="$PWD/.github/scripts/test-detect-targets-musl.sh",dst=/usr/local/bin/test.sh,type=bind \
alpine /bin/ash -c "apk update && apk add bash && test.sh x86_64-unknown-linux-musl"
detect-targets-ubuntu-test:
needs:
- detect-targets-build
- changed-files
if: needs.changed-files.outputs.has_detect_target_changed == 'true'
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/download-artifact@v4
with:
name: detect-targets
- run: chmod +x detect-targets
- name: Run test in ubuntu
run: |
set -exuo pipefail
[ "$(./detect-targets)" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ]
detect-targets-more-glibc-test:
needs:
- detect-targets-build
- changed-files
if: needs.changed-files.outputs.has_detect_target_changed == 'true'
strategy:
fail-fast: false
matrix:
container:
- archlinux
- fedora:37
- fedora:38
- fedora:39
- fedora
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: detect-targets
- run: chmod +x detect-targets
- name: Run test
run: |
set -exuo pipefail
[ "$(docker run --rm \
--mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
${{ matrix.container }} detect-targets )" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ]
detect-targets-nix-test:
needs:
- detect-targets-build
- changed-files
if: needs.changed-files.outputs.has_detect_target_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: detect-targets
- run: chmod +x detect-targets
- name: Run test
run: |
set -exuo pipefail
[ "$(docker run --rm \
--mount src="$PWD/detect-targets",dst=/detect-targets,type=bind \
nixos/nix /detect-targets )" = x86_64-unknown-linux-musl ]
detect-targets-android-check:
needs: changed-files
if: needs.changed-files.outputs.has_detect_target_changed == 'true'
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-linux-android
runs-on: ubuntu-latest
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- name: Add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Build detect-targets
run: |
cargo check --target ${{ matrix.target }}
# Set working directory here, otherwise `cargo-check` would download
# and build quite a few unused dependencies.
working-directory: crates/detect-targets
# Dummy job to have a stable name for the "all tests pass" requirement
tests-pass:
name: Tests pass
needs:
- unit-tests
- e2e-tests
- cross-check
- lint
- release-dry-run
- detect-targets-build
- detect-targets-alpine-test
- detect-targets-ubuntu-test
- detect-targets-more-glibc-test
- detect-targets-nix-test
- detect-targets-android-check
if: always() # always run even if dependencies fail
runs-on: ubuntu-latest
steps:
# fail if ANY dependency has failed or cancelled
- if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')"
run: exit 1
- run: exit 0