ruwuma/xtask/src/ci.rs
Jonas Platte 0e49b70d65
Raise MSRV to 1.55
Otherwise `cargo check` errors on the `-Wclippy::…` arguments from
`.cargo/config.toml`.
Usage as a dependency continues to work with 1.53 for now, but since
it's not changed this could soon change.
2021-10-19 21:36:39 +02:00

113 lines
3.8 KiB
Rust

use std::path::PathBuf;
use xshell::pushd;
use crate::{cmd, Metadata, Result};
const MSRV: &str = "1.55";
/// Task to run CI tests.
pub struct CiTask {
/// Which version of Rust to test against.
version: Option<String>,
/// The root of the workspace.
project_root: PathBuf,
}
impl CiTask {
pub(crate) fn new(version: Option<String>) -> Result<Self> {
let project_root = Metadata::load()?.workspace_root;
Ok(Self { version, project_root })
}
pub(crate) fn run(self) -> Result<()> {
let _p = pushd(&self.project_root)?;
match self.version.as_deref() {
Some("msrv") => self.build_msrv()?,
Some("stable") => self.build_stable()?,
Some("nightly") => self.build_nightly()?,
Some(_) => return Err("Wrong Rust version specified.".into()),
None => {
self.build_msrv().and(self.build_stable()).and(self.build_nightly())?;
}
}
Ok(())
}
fn build_msrv(&self) -> xshell::Result<()> {
// Check all crates with all features except
// * ruma (would pull in ruma-signatures)
// * ruma-client (tested with default features due to optional HTTP client deps)
// * ruma-signatures (MSRV exception)
// * xtask (no real reason to enforce an MSRV for it)
cmd!(
"rustup run {MSRV} cargo check --workspace --all-features
--exclude ruma
--exclude ruma-client
--exclude ruma-signatures
--exclude xtask"
)
.run()?;
// Check ruma-client crate with default features
cmd!("rustup run {MSRV} cargo check -p ruma-client").run()?;
// Check ruma crate with default features
cmd!("rustup run {MSRV} cargo check -p ruma").run()
}
fn build_stable(&self) -> xshell::Result<()> {
// 1. Make sure everything compiles
cmd!("rustup run stable cargo check --workspace --all-features").run()?;
cmd!("rustup run stable cargo check -p ruma-client --no-default-features").run()?;
cmd!("rustup run stable cargo check -p ruma-identifiers --no-default-features").run()?;
// 2. Run tests
let workspace_res =
cmd!("rustup run stable cargo test --workspace --features full,unstable-pre-spec")
.run();
let events_compat_res =
cmd!("rustup run stable cargo test -p ruma-events --features compat compat").run();
workspace_res.and(events_compat_res)
}
fn build_nightly(&self) -> xshell::Result<()> {
// Check formatting
let fmt_res = cmd!("rustup run nightly cargo fmt -- --check").run();
// Check `ruma` crate with `full` feature (sometimes things only compile with an unstable
// flag)
let check_full_res = cmd!("rustup run nightly cargo check -p ruma --features full").run();
// Check everything with default features with clippy
let clippy_default_res = 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!(
"
rustup run nightly cargo clippy
--workspace --all-targets --features=full,compat,unstable-pre-spec -- -D warnings
"
)
.run();
// Check dependencies being sorted
let sort_res = cmd!(
"
rustup run nightly cargo sort
--workspace --grouped --check
--order package,lib,features,dependencies,dev-dependencies,build-dependencies
"
)
.run();
fmt_res.and(check_full_res).and(clippy_default_res).and(clippy_all_res).and(sort_res)
}
}