xtask: Add ci command

This commit is contained in:
Abhik Jain 2021-04-11 15:41:45 +05:30 committed by GitHub
parent 2803ee3721
commit 563e891a4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 1 deletions

85
xtask/src/ci.rs Normal file
View File

@ -0,0 +1,85 @@
use std::path::PathBuf;
use crate::{cmd, Result};
const MSRV: &str = "1.45";
macro_rules! cmd_in {
($dir:expr, $($c:tt),+ $(,)?) => {{
let _p = xshell::pushd($dir)?;
$(super::cmd!($c).run()?;)+
}};
}
/// 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>, project_root: PathBuf) -> Self {
Self { version, project_root }
}
pub(crate) fn run(self) -> Result<()> {
match self.version.as_deref() {
Some("msrv") => self.build_msrv(),
Some("stable") => self.build_stable(),
Some("nightly") => self.build_nightly(),
Some(_) => Err("Wrong Rust version specified.".into()),
None => {
self.build_msrv()?;
self.build_stable()?;
self.build_nightly()
}
}
}
fn build_msrv(&self) -> Result<()> {
cmd_in!(
self.project_root.join("ruma"),
"rustup run {MSRV} cargo build --features ruma-events,ruma-api,ruma-appservice-api,ruma-client-api,ruma-federation-api,ruma-identity-service-api,ruma-push-gateway-api --quiet",
);
cmd_in!(self.project_root.join("ruma-client"), "rustup run {MSRV} cargo build --quiet");
cmd_in!(
self.project_root.join("ruma-identifiers"),
"rustup run {MSRV} cargo build --no-default-features --quiet"
);
cmd_in!(
self.project_root.join("ruma-identifiers"),
"rustup run {MSRV} cargo build --all-features --quiet"
);
cmd_in!(
self.project_root.join("ruma-client-api"),
"rustup run {MSRV} cargo build --all-features --quiet"
);
Ok(())
}
fn build_stable(&self) -> Result<()> {
cmd!("cargo test --all --quiet").run()?;
{
let _p = xshell::pushd(self.project_root.join("ruma-identifiers"))?;
cmd!("cargo test --no-default-features --quiet").run()?;
cmd!("cargo test --all-features --quiet").run()?;
}
{
let _p = xshell::pushd(self.project_root.join("ruma-client-api"))?;
cmd!("cargo check --no-default-features --features http1,http2 --quiet").run()?;
cmd!("cargo check --no-default-features --features http1,http2,tls-rustls-native-roots --quiet").run()?;
cmd!("cargo check --no-default-features --features http1,http2,tls-rustls-webpki-roots --quiet").run()?;
}
Ok(())
}
fn build_nightly(&self) -> Result<()> {
cmd!("cargo fmt --all").run()?;
cmd_in!("ruma", "cargo clippy --all-targets --all-features --quiet -- -D warnings");
cmd_in!("ruma-client", "cargo clippy --all-targets --quiet -- -D warnings");
Ok(())
}
}

View File

@ -13,6 +13,11 @@ xflags::xflags! {
/// The crate to release
required name: String
{}
/// Run CI tests.
cmd ci
optional version: String
{}
}
}
// generated start
@ -27,6 +32,7 @@ pub struct Xtask {
pub enum XtaskCmd {
Help(Help),
Release(Release),
Ci(Ci),
}
#[derive(Debug)]
@ -39,11 +45,20 @@ pub struct Release {
pub name: String,
}
#[derive(Debug)]
pub struct Ci {
pub version: Option<String>,
}
impl Xtask {
pub const HELP: &'static str = Self::HELP_;
pub fn from_env() -> xflags::Result<Self> {
Self::from_env_()
}
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
Self::from_vec_(args)
}
}
// generated end

View File

@ -13,10 +13,11 @@ use serde_json::from_str as from_json_str;
use toml::from_str as from_toml_str;
use xshell::read_file;
mod ci;
mod flags;
mod release;
use self::release::ReleaseTask;
use self::{ci::CiTask, release::ReleaseTask};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
@ -40,6 +41,10 @@ fn try_main() -> Result<()> {
let task = ReleaseTask::new(cmd.name, project_root)?;
task.run()
}
flags::XtaskCmd::Ci(ci) => {
let task = CiTask::new(ci.version, project_root);
task.run()
}
}
}