Skip to content

Commit

Permalink
Merge pull request #74 from NobodyXu/speedup-ci
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
weihanglo authored Mar 11, 2024
2 parents 2059bac + 696077d commit 0d10b47
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 47 deletions.
54 changes: 43 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
name: CI
on: [push, pull_request]

env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust: ["1.63", stable, beta, nightly]
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, beta, nightly]
os: [ubuntu-latest, macos-14, windows-latest]
steps:
- uses: actions/checkout@master
- name: Install Rust (rustup)
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
run: |
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal
rustup default ${{ matrix.rust }}
shell: bash

- run: cargo test
- uses: Swatinem/rust-cache@v2

- run: cargo test --locked

- name: Cache make compiled
if: ${{ !startsWith(matrix.os, 'windows') }}
id: cache-make
uses: actions/cache@v4
with:
path: /usr/local/bin/make
key: ${{ runner.os }}-make-4.4.1

# Compile it from source (temporarily)
- name: Make GNU Make from source
if: ${{ !startsWith(matrix.os, 'windows') }}
if: ${{ !startsWith(matrix.os, 'windows') && steps.cache-make.outputs.cache-hit != 'true' }}
env:
VERSION: "4.4.1"
shell: bash
run: |
wget -q "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz"
tar zxf "make-${VERSION}.tar.gz"
curl "https://ftp.gnu.org/gnu/make/make-${VERSION}.tar.gz" | tar xz
pushd "make-${VERSION}"
./configure
make
make -j 4
popd
cp -rp "make-${VERSION}/make" .
cp -p "make-${VERSION}/make" /usr/local/bin
- name: Test against GNU Make from source
if: ${{ !startsWith(matrix.os, 'windows') }}
shell: bash
run:
MAKE="${PWD}/make" cargo test
run: cargo test --locked
env:
MAKE: /usr/local/bin/make

rustfmt:
name: Rustfmt
Expand Down Expand Up @@ -63,3 +79,19 @@ jobs:
git -c user.name='ci' -c user.email='ci' commit -m init
git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'

msrv:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
steps:
- uses: actions/checkout@master
- name: Install Rust (rustup)
run: rustup toolchain install nightly --no-self-update --profile minimal
shell: bash

- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2

- run: cargo hack check --lib --rust-version --ignore-private --locked
142 changes: 142 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ edition = "2021"
rust-version = "1.63"

[target.'cfg(unix)'.dependencies]
libc = "0.2.50"
libc = "0.2.72"

[dev-dependencies]
futures = "0.1"
num_cpus = "1.0"
tempfile = "3"
tokio-core = "0.1"
tokio-process = "0.2"
tempfile = "3.10.1"

[[test]]
name = "client"
Expand Down
54 changes: 24 additions & 30 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ use std::sync::mpsc;
use std::sync::Arc;
use std::thread;

use futures::future::{self, Future};
use futures::stream::{self, Stream};
use jobserver::Client;
use tokio_core::reactor::Core;
use tokio_process::CommandExt;

macro_rules! t {
($e:expr) => {
Expand All @@ -24,9 +20,9 @@ macro_rules! t {

struct Test {
name: &'static str,
f: &'static dyn Fn(),
f: &'static (dyn Fn() + Send + Sync),
make_args: &'static [&'static str],
rule: &'static dyn Fn(&str) -> String,
rule: &'static (dyn Fn(&str) -> String + Send + Sync),
}

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

let mut core = t!(Core::new());

let futures = TESTS
let join_handles = TESTS
.iter()
.filter(|test| match filter {
Some(ref s) => test.name.contains(s),
Expand All @@ -138,33 +132,33 @@ all:
(test.rule)(me)
);
t!(t!(File::create(td.path().join("Makefile"))).write_all(makefile.as_bytes()));
let prog = env::var("MAKE").unwrap_or_else(|_| "make".to_string());
let mut cmd = Command::new(prog);
cmd.args(test.make_args);
cmd.current_dir(td.path());
future::lazy(move || {
cmd.output_async().map(move |e| {
drop(td);
(test, e)
})
thread::spawn(move || {
let prog = env::var("MAKE").unwrap_or_else(|_| "make".to_string());
let mut cmd = Command::new(prog);
cmd.args(test.make_args);
cmd.current_dir(td.path());

(test, cmd.output().unwrap())
})
})
.collect::<Vec<_>>();

println!("\nrunning {} tests\n", futures.len());
println!("\nrunning {} tests\n", join_handles.len());

let stream = stream::iter(futures.into_iter().map(Ok)).buffer_unordered(num_cpus::get());
let failures = join_handles
.into_iter()
.filter_map(|join_handle| {
let (test, output) = join_handle.join().unwrap();

let mut failures = Vec::new();
t!(core.run(stream.for_each(|(test, output)| {
if output.status.success() {
println!("test {} ... ok", test.name);
} else {
println!("test {} ... FAIL", test.name);
failures.push((test, output));
}
Ok(())
})));
if output.status.success() {
println!("test {} ... ok", test.name);
None
} else {
println!("test {} ... FAIL", test.name);
Some((test, output))
}
})
.collect::<Vec<_>>();

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

0 comments on commit 0d10b47

Please sign in to comment.