-
Notifications
You must be signed in to change notification settings - Fork 6
427 lines (363 loc) · 12.4 KB
/
ci.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
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
name: "CI"
on:
pull_request:
paths-ignore:
- "release-plz.toml"
push:
paths-ignore:
- "docs/**"
- "**.md"
- "LICENSE"
- "release-plz.toml"
branches:
- main
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
CLICOLOR: 1
CLICOLOR_FORCE: 1
permissions:
actions: read
contents: read
jobs:
# Build and upload release binaries for all relevant architectures.
build:
strategy:
fail-fast: false
matrix:
include:
# Build for x86_64/linux target on native host.
- host: "ubuntu-latest"
target: ""
os: "linux"
arch: "x86_64"
binary_name: "brush"
extra_build_args: ""
# Build for aarch64/macos target on native host.
- host: "macos-latest"
target: ""
os: "macos"
arch: "aarch64"
required_tools: ""
binary_name: "brush"
extra_build_args: ""
# Build for aarch64/linux target on x86_64/linux host.
- host: "ubuntu-latest"
target: "aarch64-unknown-linux-gnu"
os: "linux"
arch: "aarch64"
required_tools: "gcc-aarch64-linux-gnu"
binary_name: "brush"
extra_build_args: ""
# Build for WASI-0.2 target on x86_64/linux host.
- host: "ubuntu-latest"
target: "wasm32-wasip2"
os: "wasi-0.2"
arch: "wasm32"
required_tools: ""
binary_name: "brush.wasm"
extra_build_args: "--no-default-features --features minimal"
# Build for x86_64/windows target on x86_64/linux host.
- host: "ubuntu-latest"
target: "x86_64-pc-windows-gnu"
os: "windows"
arch: "x86_64"
required_tools: ""
binary_name: "brush.exe"
extra_build_args: ""
name: "Build (${{ matrix.arch }}/${{ matrix.os }})"
runs-on: ${{ matrix.host }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Enable cargo cache
uses: Swatinem/rust-cache@v2
with:
key: "${{ matrix.target }}"
- name: Install additional prerequisite tools
if: ${{ matrix.required_tools != '' }}
run: sudo apt-get update -y && sudo apt-get install -y ${{ matrix.required_tools }}
- name: Install cross-compilation toolchain
if: ${{ matrix.target != '' }}
uses: taiki-e/install-action@v2
with:
tool: cross
- name: "Build (native)"
if: ${{ matrix.target == '' }}
run: cargo build --release --all-targets ${{ matrix.extra_build_args }}
- name: "Build (cross)"
if: ${{ matrix.target != '' }}
run: cross build --release --target=${{ matrix.target }} ${{ matrix.extra_build_args }}
- name: "Upload binaries"
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.arch }}-${{ matrix.os }}
path: target/${{ matrix.target }}/release/${{ matrix.binary_name }}
- name: "Upload integration test binaries"
if: ${{ matrix.target == '' }}
uses: actions/upload-artifact@v4
with:
name: integration-tests-${{ matrix.arch }}-${{ matrix.os }}
path: |
target/${{ matrix.target }}/release/deps/brush_*_tests-*
!**/*.d
# Test functional correctness
test:
strategy:
fail-fast: false
matrix:
include:
- host: "ubuntu-latest"
variant: "linux"
artifact_suffix: ""
name_suffix: "(linux)"
- host: "macos-latest"
variant: "macos"
artifact_suffix: "-macos"
name_suffix: "(macOS)"
name: "Test ${{ matrix.name_suffix }}"
runs-on: ${{ matrix.host }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: llvm-tools-preview
- name: Enable cargo cache
uses: Swatinem/rust-cache@v2
with:
# Needed to make sure cargo-deny is correctly cached.
cache-all-crates: true
- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
stable: true
- name: "Install recent bash for tests"
run: |
brew install bash
BASH_PATH="$(brew --prefix bash)/bin/bash"
echo "Using bash from: ${BASH_PATH}"
echo "bash version:"
${BASH_PATH} --version
echo "BASH_PATH=${BASH_PATH}">>$GITHUB_ENV
- name: "Download recent bash-completion sources for tests"
uses: actions/checkout@v4
with:
repository: "scop/bash-completion"
ref: "2.14.0"
path: "bash-completion"
- name: "Setup bash-completion"
run: |
echo "BASH_COMPLETION_PATH=${GITHUB_WORKSPACE}/bash-completion/bash_completion">>$GITHUB_ENV
- name: Test
run: |
set -euxo pipefail
# Set us up to use cargo-llvm-cov
source <(cargo llvm-cov show-env --export-prefix)
cargo llvm-cov clean --workspace
# Run the tests
result=0
cargo nextest run --workspace --no-fail-fast || result=$?
# Generate code coverage report
cargo llvm-cov report --cobertura --output-path ./codecov-${{ matrix.variant }}.xml || result=$?
# Rename test results.
mv target/nextest/default/test-results.xml ./test-results-${{ matrix.variant }}.xml
# Report the actual test results
exit ${result}
- name: "Upload test results"
uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports${{ matrix.artifact_suffix }}
path: test-results-*.xml
- name: "Generate code coverage report"
uses: clearlyip/code-coverage-report-action@v5
if: always()
id: "code_coverage_report"
with:
artifact_download_workflow_names: "CI"
artifact_name: coverage-%name%${{ matrix.artifact_suffix }}
filename: codecov-${{ matrix.variant }}.xml
overall_coverage_fail_threshold: 70
only_list_changed_files: ${{ github.event_name == 'pull_request' }}
fail_on_negative_difference: true
negative_difference_by: "overall"
negative_difference_threshold: 5
- name: "Upload code coverage report"
uses: actions/upload-artifact@v4
if: always()
with:
name: codecov-reports${{ matrix.artifact_suffix }}
path: code-coverage-results.md
# Static analysis of the code.
check:
name: "Source code checks"
runs-on: ubuntu-latest
strategy:
matrix:
# Test latest stable as well as MSRV.
rust-version: ["stable", "1.75.0"]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up rust toolchain (${{ matrix.rust-version }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust-version }}
components: clippy, rustfmt
- name: Enable cargo cache
uses: Swatinem/rust-cache@v2
with:
# Needed to make sure cargo-deny is correctly cached.
cache-all-crates: true
- name: Format check
run: cargo fmt --check --all
- name: Check
run: cargo check --all-features --all-targets
- name: Install cargo-deny
uses: taiki-e/install-action@v2
with:
tool: cargo-deny
- name: Deny check
run: cargo deny --all-features check all
- name: Clippy check
if: matrix.rust-version == 'stable'
run: cargo clippy --all-features --all-targets
# Check for unneeded dependencies.
check-deps:
name: "Check for unneeded dependencies"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up nightly rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: Install cargo-udeps
uses: taiki-e/install-action@v2
with:
tool: cargo-udeps
- name: Check for unused dependencies
run: cargo udeps --workspace --all-targets --all-features
# Performance analysis of the code.
benchmark:
if: github.event_name == 'pull_request'
name: "Benchmarks"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: pr
- name: Checkout
uses: actions/checkout@v4
with:
path: main
ref: main
- name: Set up rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Enable cargo cache
uses: Swatinem/rust-cache@v2
with:
workspaces: |
./pr
./main
- name: Performance analysis on PR
run: cargo bench --workspace -- --output-format bencher | tee benchmarks.txt
working-directory: pr
- name: Performance analysis on main
run: cargo bench --workspace -- --output-format bencher | tee benchmarks.txt
working-directory: main
- name: Compare benchmark results
run: |
./pr/scripts/compare-benchmark-results.py -b main/benchmarks.txt -t pr/benchmarks.txt >benchmark-results.md
- name: Upload performance results
uses: actions/upload-artifact@v4
with:
name: perf-reports
path: |
pr/benchmarks.txt
main/benchmarks.txt
benchmark-results.md
# Test release binary on a variety of OS platforms.
os-tests:
strategy:
fail-fast: false
matrix:
include:
# N.B. We don't include Ubuntu because it's already covered by the initial test job.
- container: "fedora:latest"
description: "Fedora/latest"
prereqs_command: "dnf install -y bash-completion iputils grep less sed util-linux"
- container: "debian:latest"
description: "Debian/latest"
prereqs_command: "apt-get update -y && apt-get install -y bash-completion bsdmainutils iputils-ping grep less sed"
- container: "archlinux:latest"
description: "Arch Linux/latest"
prereqs_command: "pacman -Sy --noconfirm bash-completion iputils grep less sed util-linux"
name: "OS target tests (${{ matrix.description }})"
runs-on: ubuntu-latest
container: ${{ matrix.container }}
needs: build
steps:
# Checkout sources for YAML-based test cases
- name: Checkout
uses: actions/checkout@v4
with:
path: sources
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries-x86_64-linux
path: binaries
- name: Download integration test binaries
uses: actions/download-artifact@v4
with:
name: integration-tests-x86_64-linux
path: binaries
- name: Setup downloads
run: |
# N.B. Can't use -o pipefail because it's not supported on Debian.
set -eux
chmod +x binaries/*
ls -l -R sources/brush-shell/tests
ls -l binaries
- name: Install prerequisites
if: ${{ matrix.prereqs_command != '' }}
run: ${{ matrix.prereqs_command }}
- name: Run tests
run: |
export BRUSH_PATH=$PWD/binaries/brush
export BRUSH_COMPAT_TEST_CASES=$PWD/sources/brush-shell/tests/cases
export BRUSH_VERBOSE=true
result=0
for test_name in binaries/*tests*; do
# TODO: Re-enable interactive tests.
if [[ ${test_name} == *interactive* ]]; then
echo "WARNING: skipping interactive test: ${test_name}"
continue
fi
echo "Running test: ${test_name}"
chmod +x ${test_name}
${test_name} || result=$?
done
exit ${result}