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] branches: [main, next]
jobs: jobs:
check_msrv: all_features:
name: Check name: Check All Features
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo - name: Checkout repo
@ -38,4 +38,64 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: run 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] branches: [main, next]
jobs: jobs:
check_nightly: fmt:
name: Check name: Fmt
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo - name: Checkout repo
@ -22,23 +22,71 @@ jobs:
profile: minimal profile: minimal
toolchain: nightly toolchain: nightly
override: true override: true
components: rustfmt, clippy components: rustfmt
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v1
- name: Install cargo-sort
uses: actions-rs/install@v0.1
with:
crate: cargo-sort
- name: Run checks - name: Run checks
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: run command: run
args: -p xtask --no-default-features ci nightly args: -p xtask --no-default-features ci fmt
typos: check_full:
name: Spell Check with Typos name: Check Full Features
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Check the spelling of the files in our repo - name: Install rust nightly toolchain
uses: crate-ci/typos@master 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] branches: [main, next]
jobs: jobs:
check_stable: check_all:
name: Check name: Check All Features
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repo - name: Checkout repo
@ -27,4 +27,102 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: run 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 { pub enum CiCmd {
/// Check crates compile with the MSRV /// Check crates compile with the MSRV
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 /// Run all the tasks that use the stable version
Stable, Stable,
/// Check crates compile (stable) /// Check all crates with all features (stable)
Check, StableAll,
/// Run tests (stable) /// Check ruma-client without default features (stable)
Test, 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 /// Run all the tasks that use the nightly version
Nightly, Nightly,
/// Check formatting (nightly) /// Check formatting (nightly)
Fmt, Fmt,
/// Check ruma crate with `full` feature (nightly) /// Check ruma crate with `full` features (nightly)
CheckFull, NightlyFull,
/// Lint code with clippy (nightly) /// Lint default features with clippy (nightly)
Clippy, ClippyDefault,
/// Check sorting of dependencies (nightly) /// Lint almost all features with clippy (nightly)
ClippyAll,
/// Run all lints that don't need compilation
Lint,
/// Check sorting of dependencies (lint)
Dependencies, Dependencies,
/// Check spec links point to a recent version (nightly) /// Check spec links point to a recent version (lint)
SpecLinks, SpecLinks,
/// Check typos /// Check typos
Typos, Typos,
@ -62,19 +80,32 @@ impl CiTask {
let _p = pushd(&self.project_root)?; let _p = pushd(&self.project_root)?;
match self.cmd { match self.cmd {
Some(CiCmd::Msrv) => self.build_msrv()?, Some(CiCmd::Msrv) => self.msrv()?,
Some(CiCmd::Stable) => self.build_stable()?, Some(CiCmd::MsrvAll) => self.msrv_all()?,
Some(CiCmd::Check) => self.check()?, Some(CiCmd::MsrvClient) => self.msrv_client()?,
Some(CiCmd::Test) => self.test()?, Some(CiCmd::MsrvRuma) => self.msrv_ruma()?,
Some(CiCmd::Nightly) => self.build_nightly()?, 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::Fmt) => self.fmt()?,
Some(CiCmd::CheckFull) => self.check_full()?, Some(CiCmd::NightlyFull) => self.nightly_full()?,
Some(CiCmd::Clippy) => self.clippy()?, Some(CiCmd::ClippyDefault) => self.clippy_default()?,
Some(CiCmd::ClippyAll) => self.clippy_all()?,
Some(CiCmd::Lint) => self.lint()?,
Some(CiCmd::Dependencies) => self.dependencies()?, Some(CiCmd::Dependencies) => self.dependencies()?,
Some(CiCmd::SpecLinks) => check_spec_links(&self.project_root.join("crates"))?, Some(CiCmd::SpecLinks) => check_spec_links(&self.project_root.join("crates"))?,
Some(CiCmd::Typos) => self.typos()?, Some(CiCmd::Typos) => self.typos()?,
None => { 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. /// Check that the crates compile with the MSRV.
fn build_msrv(&self) -> Result<()> { fn msrv(&self) -> Result<()> {
// Check all crates with all features except self.msrv_all()?;
// * ruma (would pull in ruma-signatures) self.msrv_client()?;
// * ruma-client (tested only with client-api feature due to most / all optional HTTP client self.msrv_ruma()
// deps having less strict MSRV) }
// * ruma-signatures (MSRV exception)
// * xtask (no real reason to enforce an MSRV for it) /// 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!( cmd!(
"rustup run {MSRV} cargo check --workspace --all-features "rustup run {MSRV} cargo check --workspace --all-features
--exclude ruma --exclude ruma
@ -96,52 +133,70 @@ impl CiTask {
--exclude ruma-signatures --exclude ruma-signatures
--exclude xtask" --exclude xtask"
) )
.run()?; .run()
.map_err(Into::into)
}
// Check ruma-client crate with default features /// Check ruma-client with default features with the MSRV.
cmd!("rustup run {MSRV} cargo check -p ruma-client --features client-api").run()?; 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) cmd!("rustup run {MSRV} cargo check -p ruma").run().map_err(Into::into)
} }
/// Run all the tasks that use the stable version. /// Run all the tasks that use the stable version.
fn build_stable(&self) -> Result<()> { fn stable(&self) -> Result<()> {
self.check()?; self.stable_all()?;
self.test() self.stable_client()?;
self.stable_common()?;
self.test_all()?;
self.test_doc()?;
self.test_common()
} }
/// Check that the crates compile with the stable version. /// Check all crates with all features with the stable version.
fn check(&self) -> Result<()> { fn stable_all(&self) -> Result<()> {
cmd!("rustup run stable cargo check --workspace --all-features").run()?; cmd!("rustup run stable cargo check --workspace --all-features").run().map_err(Into::into)
cmd!("rustup run stable cargo check -p ruma-client --no-default-features").run()?; }
/// 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) 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. /// Run tests on all crates with almost all features with the stable version.
fn test(&self) -> Result<()> { fn test_all(&self) -> Result<()> {
let workspace_res = cmd!("rustup run stable cargo test --features __ci").run(); cmd!("rustup run stable cargo test --tests --features __ci").run().map_err(Into::into)
let events_compat_res = }
cmd!("rustup run stable cargo test -p ruma-common --features events --features compat compat").run();
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. /// Run all the tasks that use the nightly version.
fn build_nightly(&self) -> Result<()> { fn nightly(&self) -> Result<()> {
// Check formatting self.fmt()?;
let fmt_res = self.fmt(); self.nightly_full()?;
// Check `ruma` crate with `full` feature (sometimes things only compile with an unstable self.clippy_default()?;
// flag) self.clippy_all()
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)
} }
/// Check the formatting with the nightly version. /// Check the formatting with the nightly version.
@ -150,29 +205,42 @@ impl CiTask {
} }
/// Check ruma crate with full feature with the nightly version. /// 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) cmd!("rustup run nightly cargo check -p ruma --features full").run().map_err(Into::into)
} }
/// Lint the code with clippy with the nightly version. /// Lint default features with clippy with the nightly version.
fn clippy(&self) -> Result<()> { fn clippy_default(&self) -> Result<()> {
// Check everything with default features with clippy cmd!(
let clippy_default_res = cmd!(
" "
rustup run nightly cargo clippy rustup run nightly cargo clippy
--workspace --all-targets --features=full -- -D warnings --workspace --all-targets --features=full -- -D warnings
" "
) )
.run(); .run()
// Check everything with almost all features with clippy .map_err(Into::into)
let clippy_all_res = cmd!( }
/// Lint almost all features with clippy with the nightly version.
fn clippy_all(&self) -> Result<()> {
cmd!(
" "
rustup run nightly cargo clippy rustup run nightly cargo clippy
--workspace --all-targets --features=__ci,compat -- -D warnings --workspace --all-targets --features=__ci,compat -- -D warnings
" "
) )
.run(); .run()
clippy_default_res.and(clippy_all_res).map_err(Into::into) .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. /// Check the sorting of dependencies with the nightly version.