Skip to content

Commit 0d10b47

Browse files
authored
Merge pull request #74 from NobodyXu/speedup-ci
CI: Improve msrv checking and speedup CI Improve msrv CI: - Include a lockfile `Cargo.lock` created using `cargo +nightly -Zminimal-versions update` and used in msrv job to make sure it tests against the minimal version of dependencies. - Run `cargo-check` to check for msrv (in a new job), running `cargo-test` would also pull in test dependencies and test code This PR also speeds up the CI from 5m down to 1m (when make and dependencies are cached).
2 parents 2059bac + 696077d commit 0d10b47

File tree

4 files changed

+211
-47
lines changed

4 files changed

+211
-47
lines changed

.github/workflows/main.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,57 @@
11
name: CI
22
on: [push, pull_request]
33

4+
env:
5+
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
6+
47
jobs:
58
test:
69
name: Test
710
runs-on: ${{ matrix.os }}
811
strategy:
912
matrix:
10-
rust: ["1.63", stable, beta, nightly]
11-
os: [ubuntu-latest, macos-latest, windows-latest]
13+
rust: [stable, beta, nightly]
14+
os: [ubuntu-latest, macos-14, windows-latest]
1215
steps:
1316
- uses: actions/checkout@master
1417
- name: Install Rust (rustup)
15-
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
18+
run: |
19+
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal
20+
rustup default ${{ matrix.rust }}
1621
shell: bash
1722

18-
- run: cargo test
23+
- uses: Swatinem/rust-cache@v2
24+
25+
- run: cargo test --locked
26+
27+
- name: Cache make compiled
28+
if: ${{ !startsWith(matrix.os, 'windows') }}
29+
id: cache-make
30+
uses: actions/cache@v4
31+
with:
32+
path: /usr/local/bin/make
33+
key: ${{ runner.os }}-make-4.4.1
1934

2035
# Compile it from source (temporarily)
2136
- name: Make GNU Make from source
22-
if: ${{ !startsWith(matrix.os, 'windows') }}
37+
if: ${{ !startsWith(matrix.os, 'windows') && steps.cache-make.outputs.cache-hit != 'true' }}
2338
env:
2439
VERSION: "4.4.1"
2540
shell: bash
2641
run: |
27-
wget -q "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz"
28-
tar zxf "make-${VERSION}.tar.gz"
42+
curl "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz" | tar xz
2943
pushd "make-${VERSION}"
3044
./configure
31-
make
45+
make -j 4
3246
popd
33-
cp -rp "make-${VERSION}/make" .
47+
cp -p "make-${VERSION}/make" /usr/local/bin
48+
3449
- name: Test against GNU Make from source
3550
if: ${{ !startsWith(matrix.os, 'windows') }}
3651
shell: bash
37-
run:
38-
MAKE="${PWD}/make" cargo test
52+
run: cargo test --locked
53+
env:
54+
MAKE: /usr/local/bin/make
3955

4056
rustfmt:
4157
name: Rustfmt
@@ -63,3 +79,19 @@ jobs:
6379
git -c user.name='ci' -c user.email='ci' commit -m init
6480
git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
6581
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
82+
83+
msrv:
84+
runs-on: ${{ matrix.os }}
85+
strategy:
86+
matrix:
87+
os: [ubuntu-latest, macos-14, windows-latest]
88+
steps:
89+
- uses: actions/checkout@master
90+
- name: Install Rust (rustup)
91+
run: rustup toolchain install nightly --no-self-update --profile minimal
92+
shell: bash
93+
94+
- uses: taiki-e/install-action@cargo-hack
95+
- uses: Swatinem/rust-cache@v2
96+
97+
- run: cargo hack check --lib --rust-version --ignore-private --locked

Cargo.lock

Lines changed: 142 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ edition = "2021"
1313
rust-version = "1.63"
1414

1515
[target.'cfg(unix)'.dependencies]
16-
libc = "0.2.50"
16+
libc = "0.2.72"
1717

1818
[dev-dependencies]
19-
futures = "0.1"
20-
num_cpus = "1.0"
21-
tempfile = "3"
22-
tokio-core = "0.1"
23-
tokio-process = "0.2"
19+
tempfile = "3.10.1"
2420

2521
[[test]]
2622
name = "client"

tests/client.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ use std::sync::mpsc;
77
use std::sync::Arc;
88
use std::thread;
99

10-
use futures::future::{self, Future};
11-
use futures::stream::{self, Stream};
1210
use jobserver::Client;
13-
use tokio_core::reactor::Core;
14-
use tokio_process::CommandExt;
1511

1612
macro_rules! t {
1713
($e:expr) => {
@@ -24,9 +20,9 @@ macro_rules! t {
2420

2521
struct Test {
2622
name: &'static str,
27-
f: &'static dyn Fn(),
23+
f: &'static (dyn Fn() + Send + Sync),
2824
make_args: &'static [&'static str],
29-
rule: &'static dyn Fn(&str) -> String,
25+
rule: &'static (dyn Fn(&str) -> String + Send + Sync),
3026
}
3127

3228
const TESTS: &[Test] = &[
@@ -118,9 +114,7 @@ fn main() {
118114
let me = me.to_str().unwrap();
119115
let filter = env::args().nth(1);
120116

121-
let mut core = t!(Core::new());
122-
123-
let futures = TESTS
117+
let join_handles = TESTS
124118
.iter()
125119
.filter(|test| match filter {
126120
Some(ref s) => test.name.contains(s),
@@ -138,33 +132,33 @@ all:
138132
(test.rule)(me)
139133
);
140134
t!(t!(File::create(td.path().join("Makefile"))).write_all(makefile.as_bytes()));
141-
let prog = env::var("MAKE").unwrap_or_else(|_| "make".to_string());
142-
let mut cmd = Command::new(prog);
143-
cmd.args(test.make_args);
144-
cmd.current_dir(td.path());
145-
future::lazy(move || {
146-
cmd.output_async().map(move |e| {
147-
drop(td);
148-
(test, e)
149-
})
135+
thread::spawn(move || {
136+
let prog = env::var("MAKE").unwrap_or_else(|_| "make".to_string());
137+
let mut cmd = Command::new(prog);
138+
cmd.args(test.make_args);
139+
cmd.current_dir(td.path());
140+
141+
(test, cmd.output().unwrap())
150142
})
151143
})
152144
.collect::<Vec<_>>();
153145

154-
println!("\nrunning {} tests\n", futures.len());
146+
println!("\nrunning {} tests\n", join_handles.len());
155147

156-
let stream = stream::iter(futures.into_iter().map(Ok)).buffer_unordered(num_cpus::get());
148+
let failures = join_handles
149+
.into_iter()
150+
.filter_map(|join_handle| {
151+
let (test, output) = join_handle.join().unwrap();
157152

158-
let mut failures = Vec::new();
159-
t!(core.run(stream.for_each(|(test, output)| {
160-
if output.status.success() {
161-
println!("test {} ... ok", test.name);
162-
} else {
163-
println!("test {} ... FAIL", test.name);
164-
failures.push((test, output));
165-
}
166-
Ok(())
167-
})));
153+
if output.status.success() {
154+
println!("test {} ... ok", test.name);
155+
None
156+
} else {
157+
println!("test {} ... FAIL", test.name);
158+
Some((test, output))
159+
}
160+
})
161+
.collect::<Vec<_>>();
168162

169163
if failures.is_empty() {
170164
println!("\ntest result: ok\n");

0 commit comments

Comments
 (0)