22
22
id : get_msrv
23
23
run : rg '^\s*rust-version\s*=\s*"(\d+(\.\d+){0,2})"' --replace 'msrv=$1' Cargo.toml >> "$GITHUB_OUTPUT"
24
24
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
+
25
49
test :
26
- name : test
50
+ name : Test on each target
27
51
needs : get-msrv
28
52
env :
29
53
# Emit backtraces on panics.
@@ -32,11 +56,32 @@ jobs:
32
56
strategy :
33
57
fail-fast : false
34
58
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
36
65
rust :
37
66
- ${{ needs.get-msrv.outputs.msrv }}
38
67
- stable
39
68
- 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
40
85
steps :
41
86
- name : Checkout repository
42
87
uses : actions/checkout@v4
@@ -45,50 +90,48 @@ jobs:
45
90
uses : dtolnay/rust-toolchain@master
46
91
with :
47
92
toolchain : ${{ matrix.rust }}
48
- components : rustfmt, clippy
93
+ targets : ${{ matrix.target }}
94
+ components : clippy
49
95
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'
52
102
# The latest realese of `cross` is not able to build/link for `aarch64-linux-android`
53
103
# See: https://github.com/cross-rs/cross/issues/1222
54
104
# This is fixed on `main` but not yet released. To avoid a breakage somewhen in the future
55
105
# 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
61
112
62
113
- 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 }}
68
116
69
117
# This is useful for debugging problems when the expected build artifacts
70
118
# (like shell completions and man pages) aren't generated.
71
119
- name : Show build.rs stderr
72
120
shell : bash
73
121
run : |
74
122
# 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 )
76
124
for FILE in $STDERR_FILES; do
77
125
echo "::group::$FILE"
78
126
cat "$FILE"
79
127
echo "::endgroup::"
80
128
done
81
129
82
130
- 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
89
132
90
133
- 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
92
135
if : matrix.os == 'windows-latest' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
93
136
env :
94
137
NPCAP_OEM_URL : ${{ secrets.NPCAP_OEM_URL }}
@@ -98,15 +141,15 @@ jobs:
98
141
# see https://stackoverflow.com/a/1674950/5637701
99
142
& "$env:TEMP/npcap-oem.exe" /S
100
143
101
- - name : Run tests using cargo-insta
144
+ - name : Run tests
102
145
id : run_tests
103
146
# npcap is needed to run tests on Windows, so unfortunately we cannot run tests
104
147
# on PRs from other repositories
105
148
if : matrix.os != 'windows-latest' || github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
106
149
env :
107
150
# make insta generate new snapshots in CI
108
151
INSTA_UPDATE : new
109
- run : cargo insta test --color=never
152
+ run : ${{ matrix. cargo }} test --all-targets --all-features --target ${{ matrix.target }}
110
153
111
154
- name : Upload snapshots of failed tests
112
155
if : ${{ failure() && steps.run_tests.outcome == 'failure' }}
@@ -115,25 +158,12 @@ jobs:
115
158
name : ${{ matrix.os }}-${{ matrix.rust }}-failed_snapshots
116
159
path : ' **/*.snap.new'
117
160
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' }}
134
163
uses : actions/upload-artifact@v3
135
164
with :
136
- name : ${{ matrix.os }}-${{ matrix.rust }}
165
+ name : ${{ matrix.target }}-${{ matrix.rust }}
137
166
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
0 commit comments