ci: Split CI in smaller tasks

This commit is contained in:
Kévin Commaille 2022-03-21 09:49:57 +01:00 committed by GitHub
parent eef68d7d4b
commit 806606c675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 389 additions and 85 deletions

View File

@ -10,8 +10,8 @@ on:
branches: [main, next]
jobs:
check_msrv:
name: Check
all_features:
name: Check All Features
runs-on: ubuntu-latest
steps:
- name: Checkout repo
@ -38,4 +38,64 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci msrv
args: -p xtask --no-default-features ci msrv-all
client:
name: Check Client
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust 1.55 toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: '1.55'
# Used to compile xtask
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
with:
# A stable compiler update should automatically not reuse old caches.
# Add the MSRV as a stable cache key too so bumping it also gets us a
# fresh cache.
sharedKey: msrv1.55
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci msrv-client
ruma:
name: Check Ruma
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust 1.55 toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: '1.55'
# Used to compile xtask
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
with:
# A stable compiler update should automatically not reuse old caches.
# Add the MSRV as a stable cache key too so bumping it also gets us a
# fresh cache.
sharedKey: msrv1.55
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci msrv-ruma

View File

@ -10,8 +10,8 @@ on:
branches: [main, next]
jobs:
check_nightly:
name: Check
fmt:
name: Fmt
runs-on: ubuntu-latest
steps:
- name: Checkout repo
@ -22,23 +22,71 @@ jobs:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy
components: rustfmt
- uses: Swatinem/rust-cache@v1
- name: Install cargo-sort
uses: actions-rs/install@v0.1
with:
crate: cargo-sort
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci nightly
typos:
name: Spell Check with Typos
args: -p xtask --no-default-features ci fmt
check_full:
name: Check Full Features
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Check the spelling of the files in our repo
uses: crate-ci/typos@master
- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- uses: Swatinem/rust-cache@v1
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci nightly-full
clippy_default:
name: Clippy Default Features
runs-on: ubuntu-latest
needs: check_full
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy
- uses: Swatinem/rust-cache@v1
- name: Run lints
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci clippy-default
clippy_all:
name: Clippy All Features
runs-on: ubuntu-latest
needs: check_full
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy
- uses: Swatinem/rust-cache@v1
- name: Run lints
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci clippy-all

View File

@ -10,8 +10,8 @@ on:
branches: [main, next]
jobs:
check_stable:
name: Check
check_all:
name: Check All Features
runs-on: ubuntu-latest
steps:
- name: Checkout repo
@ -27,4 +27,102 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci stable
args: -p xtask --no-default-features ci stable-all
check_client:
name: Check Client
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci stable-client
check_common:
name: Check Common
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- name: Run checks
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci stable-common
test_all:
name: Run Tests
runs-on: ubuntu-latest
needs: check_all
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci test-all
test_doc:
name: Run Doc Tests
runs-on: ubuntu-latest
needs: check_all
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci test-doc
test_common:
name: Test Common Features
runs-on: ubuntu-latest
needs: check_common
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci test-common

30
.github/workflows/style.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Style
env:
CARGO_TERM_COLOR: always
on:
push:
branches: [main, next]
pull_request:
branches: [main, next]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- name: Check spelling
uses: crate-ci/typos@master
- name: Install cargo-sort
uses: actions-rs/install@v0.1
with:
crate: cargo-sort
- name: Run lints
uses: actions-rs/cargo@v1
with:
command: run
args: -p xtask --no-default-features ci lint

View File

@ -21,23 +21,41 @@ pub struct CiArgs {
pub enum CiCmd {
/// Check crates compile with the MSRV
Msrv,
/// Check all crates with all features (msrv)
MsrvAll,
/// Check ruma-client with default features (msrv)
MsrvClient,
/// Check ruma crate with default features (msrv)
MsrvRuma,
/// Run all the tasks that use the stable version
Stable,
/// Check crates compile (stable)
Check,
/// Run tests (stable)
Test,
/// Check all crates with all features (stable)
StableAll,
/// Check ruma-client without default features (stable)
StableClient,
/// Check ruma-common with only the required features (stable)
StableCommon,
/// Run all tests with almost all features (stable)
TestAll,
/// Run doc tests with almost all features (stable)
TestDoc,
/// Test ruma-common with the compat feature (stable)
TestCommon,
/// Run all the tasks that use the nightly version
Nightly,
/// Check formatting (nightly)
Fmt,
/// Check ruma crate with `full` feature (nightly)
CheckFull,
/// Lint code with clippy (nightly)
Clippy,
/// Check sorting of dependencies (nightly)
/// Check ruma crate with `full` features (nightly)
NightlyFull,
/// Lint default features with clippy (nightly)
ClippyDefault,
/// Lint almost all features with clippy (nightly)
ClippyAll,
/// Run all lints that don't need compilation
Lint,
/// Check sorting of dependencies (lint)
Dependencies,
/// Check spec links point to a recent version (nightly)
/// Check spec links point to a recent version (lint)
SpecLinks,
/// Check typos
Typos,
@ -62,19 +80,32 @@ impl CiTask {
let _p = pushd(&self.project_root)?;
match self.cmd {
Some(CiCmd::Msrv) => self.build_msrv()?,
Some(CiCmd::Stable) => self.build_stable()?,
Some(CiCmd::Check) => self.check()?,
Some(CiCmd::Test) => self.test()?,
Some(CiCmd::Nightly) => self.build_nightly()?,
Some(CiCmd::Msrv) => self.msrv()?,
Some(CiCmd::MsrvAll) => self.msrv_all()?,
Some(CiCmd::MsrvClient) => self.msrv_client()?,
Some(CiCmd::MsrvRuma) => self.msrv_ruma()?,
Some(CiCmd::Stable) => self.stable()?,
Some(CiCmd::StableAll) => self.stable_all()?,
Some(CiCmd::StableClient) => self.stable_client()?,
Some(CiCmd::StableCommon) => self.stable_common()?,
Some(CiCmd::TestAll) => self.test_all()?,
Some(CiCmd::TestDoc) => self.test_doc()?,
Some(CiCmd::TestCommon) => self.test_common()?,
Some(CiCmd::Nightly) => self.nightly()?,
Some(CiCmd::Fmt) => self.fmt()?,
Some(CiCmd::CheckFull) => self.check_full()?,
Some(CiCmd::Clippy) => self.clippy()?,
Some(CiCmd::NightlyFull) => self.nightly_full()?,
Some(CiCmd::ClippyDefault) => self.clippy_default()?,
Some(CiCmd::ClippyAll) => self.clippy_all()?,
Some(CiCmd::Lint) => self.lint()?,
Some(CiCmd::Dependencies) => self.dependencies()?,
Some(CiCmd::SpecLinks) => check_spec_links(&self.project_root.join("crates"))?,
Some(CiCmd::Typos) => self.typos()?,
None => {
self.build_msrv().and(self.build_stable()).and(self.build_nightly())?;
self.msrv()
.and(self.stable())
.and(self.nightly())
.and(self.lint())
.and(self.typos())?;
}
}
@ -82,13 +113,19 @@ impl CiTask {
}
/// Check that the crates compile with the MSRV.
fn build_msrv(&self) -> Result<()> {
// Check all crates with all features except
// * ruma (would pull in ruma-signatures)
// * ruma-client (tested only with client-api feature due to most / all optional HTTP client
// deps having less strict MSRV)
// * ruma-signatures (MSRV exception)
// * xtask (no real reason to enforce an MSRV for it)
fn msrv(&self) -> Result<()> {
self.msrv_all()?;
self.msrv_client()?;
self.msrv_ruma()
}
/// Check all crates with all features with the MSRV, except:
/// * ruma (would pull in ruma-signatures)
/// * ruma-client (tested only with client-api feature due to most / all optional HTTP client
/// deps having less strict MSRV)
/// * ruma-signatures (MSRV exception)
/// * xtask (no real reason to enforce an MSRV for it)
fn msrv_all(&self) -> Result<()> {
cmd!(
"rustup run {MSRV} cargo check --workspace --all-features
--exclude ruma
@ -96,52 +133,70 @@ impl CiTask {
--exclude ruma-signatures
--exclude xtask"
)
.run()?;
.run()
.map_err(Into::into)
}
// Check ruma-client crate with default features
cmd!("rustup run {MSRV} cargo check -p ruma-client --features client-api").run()?;
/// Check ruma-client with default features with the MSRV.
fn msrv_client(&self) -> Result<()> {
cmd!("rustup run {MSRV} cargo check -p ruma-client --features client-api")
.run()
.map_err(Into::into)
}
// Check ruma crate with default features
/// Check ruma crate with default features with the MSRV.
fn msrv_ruma(&self) -> Result<()> {
cmd!("rustup run {MSRV} cargo check -p ruma").run().map_err(Into::into)
}
/// Run all the tasks that use the stable version.
fn build_stable(&self) -> Result<()> {
self.check()?;
self.test()
fn stable(&self) -> Result<()> {
self.stable_all()?;
self.stable_client()?;
self.stable_common()?;
self.test_all()?;
self.test_doc()?;
self.test_common()
}
/// Check that the crates compile with the stable version.
fn check(&self) -> Result<()> {
cmd!("rustup run stable cargo check --workspace --all-features").run()?;
cmd!("rustup run stable cargo check -p ruma-client --no-default-features").run()?;
/// Check all crates with all features with the stable version.
fn stable_all(&self) -> Result<()> {
cmd!("rustup run stable cargo check --workspace --all-features").run().map_err(Into::into)
}
/// Check ruma-client without default features with the stable version.
fn stable_client(&self) -> Result<()> {
cmd!("rustup run stable cargo check -p ruma-client --no-default-features")
.run()
.map_err(Into::into)
}
/// Check ruma-common with onjy the required features with the stable version.
fn stable_common(&self) -> Result<()> {
cmd!("rustup run stable cargo check -p ruma-common --no-default-features --features client,server").run().map_err(Into::into)
}
/// Run tests with the stable version.
fn test(&self) -> Result<()> {
let workspace_res = cmd!("rustup run stable cargo test --features __ci").run();
let events_compat_res =
cmd!("rustup run stable cargo test -p ruma-common --features events --features compat compat").run();
/// Run tests on all crates with almost all features with the stable version.
fn test_all(&self) -> Result<()> {
cmd!("rustup run stable cargo test --tests --features __ci").run().map_err(Into::into)
}
workspace_res.and(events_compat_res).map_err(Into::into)
/// Run doctests on all crates with almost all features with the stable version.
fn test_doc(&self) -> Result<()> {
cmd!("rustup run stable cargo test --doc --features __ci").run().map_err(Into::into)
}
/// Test ruma-common with the compat feature with the stable version.
fn test_common(&self) -> Result<()> {
cmd!("rustup run stable cargo test -p ruma-common --features events --features compat compat").run().map_err(Into::into)
}
/// Run all the tasks that use the nightly version.
fn build_nightly(&self) -> Result<()> {
// Check formatting
let fmt_res = self.fmt();
// Check `ruma` crate with `full` feature (sometimes things only compile with an unstable
// flag)
let check_full_res = self.check_full();
// Lint code with clippy
let clippy_res = self.clippy();
// Check dependencies being sorted
let dependencies_res = self.dependencies();
// Check that all links point to the same version of the spec
let spec_links_res = check_spec_links(&self.project_root.join("crates"));
fmt_res.and(check_full_res).and(clippy_res).and(dependencies_res).and(spec_links_res)
fn nightly(&self) -> Result<()> {
self.fmt()?;
self.nightly_full()?;
self.clippy_default()?;
self.clippy_all()
}
/// Check the formatting with the nightly version.
@ -150,29 +205,42 @@ impl CiTask {
}
/// Check ruma crate with full feature with the nightly version.
fn check_full(&self) -> Result<()> {
fn nightly_full(&self) -> Result<()> {
cmd!("rustup run nightly cargo check -p ruma --features full").run().map_err(Into::into)
}
/// Lint the code with clippy with the nightly version.
fn clippy(&self) -> Result<()> {
// Check everything with default features with clippy
let clippy_default_res = cmd!(
/// Lint default features with clippy with the nightly version.
fn clippy_default(&self) -> Result<()> {
cmd!(
"
rustup run nightly cargo clippy
--workspace --all-targets --features=full -- -D warnings
"
)
.run();
// Check everything with almost all features with clippy
let clippy_all_res = cmd!(
.run()
.map_err(Into::into)
}
/// Lint almost all features with clippy with the nightly version.
fn clippy_all(&self) -> Result<()> {
cmd!(
"
rustup run nightly cargo clippy
--workspace --all-targets --features=__ci,compat -- -D warnings
"
)
.run();
clippy_default_res.and(clippy_all_res).map_err(Into::into)
.run()
.map_err(Into::into)
}
/// Run all lints that don't need compilation.
fn lint(&self) -> Result<()> {
// Check dependencies being sorted
let dependencies_res = self.dependencies();
// Check that all links point to the same version of the spec
let spec_links_res = check_spec_links(&self.project_root.join("crates"));
dependencies_res.and(spec_links_res)
}
/// Check the sorting of dependencies with the nightly version.