Skip to content

Commit 86a17cb

Browse files
authored
CI refactor (#399)
* CI refactor * Don't error when no bandwhich stderr files are found * Specify explicit target when running tests * Fix typo * Set `--color never` correctly for tests * Unset `--color never` - because the extraneous escape characters don't seem to be related to colours * Write changelog
1 parent cc5685b commit 86a17cb

File tree

2 files changed

+75
-44
lines changed

2 files changed

+75
-44
lines changed

.github/workflows/ci.yaml

+74-44
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,32 @@ jobs:
2222
id: get_msrv
2323
run: rg '^\s*rust-version\s*=\s*"(\d+(\.\d+){0,2})"' --replace 'msrv=$1' Cargo.toml >> "$GITHUB_OUTPUT"
2424

25+
check-fmt:
26+
name: Check code formatting
27+
runs-on: ubuntu-latest
28+
needs: get-msrv
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
rust:
33+
- ${{ needs.get-msrv.outputs.msrv }}
34+
- stable
35+
- nightly
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Install Rust
41+
uses: dtolnay/rust-toolchain@master
42+
with:
43+
toolchain: ${{ matrix.rust }}
44+
components: rustfmt
45+
46+
- name: Check formatting
47+
run: cargo fmt --all -- --check
48+
2549
test:
26-
name: test
50+
name: Test on each target
2751
needs: get-msrv
2852
env:
2953
# Emit backtraces on panics.
@@ -32,11 +56,32 @@ jobs:
3256
strategy:
3357
fail-fast: false
3458
matrix:
35-
os: [ubuntu-latest, macos-latest, windows-latest]
59+
build:
60+
- android-aarch64
61+
- linux-x64-gnu
62+
- linux-x64-musl
63+
- macos-x64
64+
- windows-x64-msvc
3665
rust:
3766
- ${{ needs.get-msrv.outputs.msrv }}
3867
- stable
3968
- nightly
69+
include:
70+
- os: ubuntu-latest # default
71+
- cargo: cargo # default; overwrite with `cross` if necessary
72+
- build: android-aarch64
73+
target: aarch64-linux-android
74+
cargo: cross
75+
- build: linux-x64-gnu
76+
target: x86_64-unknown-linux-gnu
77+
- build: linux-x64-musl
78+
target: x86_64-unknown-linux-musl
79+
- build: macos-x64
80+
os: macos-latest
81+
target: x86_64-apple-darwin
82+
- build: windows-x64-msvc
83+
os: windows-latest
84+
target: x86_64-pc-windows-msvc
4085
steps:
4186
- name: Checkout repository
4287
uses: actions/checkout@v4
@@ -45,50 +90,48 @@ jobs:
4590
uses: dtolnay/rust-toolchain@master
4691
with:
4792
toolchain: ${{ matrix.rust }}
48-
components: rustfmt, clippy
93+
targets: ${{ matrix.target }}
94+
components: clippy
4995

50-
- name: Install Cross on Ubuntu
51-
if: matrix.os == 'ubuntu-latest'
96+
- name: Install musl-tools
97+
if: matrix.build == 'linux-x64-musl'
98+
run: sudo apt-get install -y --no-install-recommends musl-tools
99+
100+
- name: Install cross
101+
if: matrix.cargo == 'cross'
52102
# The latest realese of `cross` is not able to build/link for `aarch64-linux-android`
53103
# See: https://github.com/cross-rs/cross/issues/1222
54104
# This is fixed on `main` but not yet released. To avoid a breakage somewhen in the future
55105
# pin the cross revision used to the latest HEAD at 04/2024.
56-
# Remove the git source and revision once cross 0.3 is released.
57-
run: cargo install --git https://github.com/cross-rs/cross.git --rev 085092c cross
58-
59-
- name: Check formatting
60-
run: cargo fmt --all -- --check
106+
# Go back to taiki-e/install-action once cross 0.3 is released.
107+
uses: taiki-e/cache-cargo-install-action@v1
108+
with:
109+
tool: cross
110+
git: https://github.com/cross-rs/cross.git
111+
rev: 085092c
61112

62113
- name: Build
63-
run: cargo build --verbose
64-
65-
- name: Build target aarch64-linux-android
66-
if: matrix.os == 'ubuntu-latest'
67-
run: cross build --target aarch64-linux-android --verbose
114+
id: build
115+
run: ${{ matrix.cargo }} build --verbose --target ${{ matrix.target }}
68116

69117
# This is useful for debugging problems when the expected build artifacts
70118
# (like shell completions and man pages) aren't generated.
71119
- name: Show build.rs stderr
72120
shell: bash
73121
run: |
74122
# it's probably okay to assume no spaces?
75-
STDERR_FILES=$(find "./target/debug" -name stderr | grep bandwhich)
123+
STDERR_FILES=$(find "./target/debug" -name stderr | grep bandwhich || true)
76124
for FILE in $STDERR_FILES; do
77125
echo "::group::$FILE"
78126
cat "$FILE"
79127
echo "::endgroup::"
80128
done
81129
82130
- name: Run clippy
83-
run: cargo clippy --all-targets --all-features -- -D warnings
84-
85-
- name: Install cargo-insta
86-
uses: taiki-e/install-action@v2
87-
with:
88-
tool: cargo-insta
131+
run: ${{ matrix.cargo }} clippy --all-targets --all-features --target ${{ matrix.target }} -- -D warnings
89132

90133
- name: Install npcap on Windows
91-
# PRs from other repositories cannot not be trusted with repository secrets
134+
# PRs from other repositories cannot be trusted with repository secrets
92135
if: matrix.os == 'windows-latest' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
93136
env:
94137
NPCAP_OEM_URL: ${{ secrets.NPCAP_OEM_URL }}
@@ -98,15 +141,15 @@ jobs:
98141
# see https://stackoverflow.com/a/1674950/5637701
99142
& "$env:TEMP/npcap-oem.exe" /S
100143
101-
- name: Run tests using cargo-insta
144+
- name: Run tests
102145
id: run_tests
103146
# npcap is needed to run tests on Windows, so unfortunately we cannot run tests
104147
# on PRs from other repositories
105148
if: matrix.os != 'windows-latest' || github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
106149
env:
107150
# make insta generate new snapshots in CI
108151
INSTA_UPDATE: new
109-
run: cargo insta test --color=never
152+
run: ${{ matrix.cargo }} test --all-targets --all-features --target ${{ matrix.target }}
110153

111154
- name: Upload snapshots of failed tests
112155
if: ${{ failure() && steps.run_tests.outcome == 'failure' }}
@@ -115,25 +158,12 @@ jobs:
115158
name: ${{ matrix.os }}-${{ matrix.rust }}-failed_snapshots
116159
path: '**/*.snap.new'
117160

118-
- name: Upload android binary
119-
if: ${{ matrix.os == 'ubuntu-latest' && ( success() || steps.build.outcome == 'success' ) }}
120-
uses: actions/upload-artifact@v3
121-
with:
122-
name: aarch64-linux-android-${{ matrix.rust }}
123-
path: target/aarch64-linux-android/debug/bandwhich
124-
125-
- name: Upload unix binary
126-
if: ${{ matrix.os != 'windows-latest' && ( success() || steps.build.outcome == 'success' ) }}
127-
uses: actions/upload-artifact@v3
128-
with:
129-
name: ${{ matrix.os }}-${{ matrix.rust }}
130-
path: target/debug/bandwhich
131-
132-
- name: Upload windows binary
133-
if: ${{ matrix.os == 'windows-latest' && ( success() || steps.build.outcome == 'success' ) }}
161+
- name: Upload binaries
162+
if: ${{ success() || steps.build.outcome == 'success' }}
134163
uses: actions/upload-artifact@v3
135164
with:
136-
name: ${{ matrix.os }}-${{ matrix.rust }}
165+
name: ${{ matrix.target }}-${{ matrix.rust }}
137166
path: |
138-
target/debug/bandwhich.exe
139-
target/debug/bandwhich.pdb
167+
target/${{ matrix.target }}/debug/bandwhich
168+
target/${{ matrix.target }}/debug/bandwhich.exe
169+
target/${{ matrix.target }}/debug/bandwhich.pdb

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2626
* CI: strip release binaries for all targets #358 - @cyqsimon
2727
* Bump MSRV to 1.74 (required by clap 4.5; see #373)
2828
* CI: Configure dependabot grouping #395 - @cyqsimon
29+
* CI refactor #399 - @cyqsimon
2930

3031
## [0.22.2] - 2024-01-28
3132

0 commit comments

Comments
 (0)