ci: Disable irrelevant parts of xtask

This commit is contained in:
Jonas Platte 2021-04-14 19:20:45 +02:00
parent 4bc25f836a
commit 461f856b5a
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
9 changed files with 60 additions and 45 deletions

View File

@ -11,4 +11,4 @@ tasks:
rustup default stable rustup default stable
- test: | - test: |
cd ruma cd ruma
cargo xtask ci msrv cargo run -p xtask --no-default-features ci msrv

View File

@ -10,4 +10,4 @@ tasks:
rustup default nightly rustup default nightly
- test: | - test: |
cd ruma cd ruma
cargo xtask ci nightly cargo run -p xtask --no-default-features ci nightly

View File

@ -10,4 +10,4 @@ tasks:
rustup default stable rustup default stable
- test: | - test: |
cd ruma cd ruma
cargo xtask ci stable cargo run -p xtask --no-default-features ci stable

View File

@ -5,14 +5,15 @@ authors = ["Kévin Commaille <zecakeh@pm.me>"]
edition = "2018" edition = "2018"
publish = false publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features]
default = ["isahc", "semver", "toml_edit"]
[dependencies] [dependencies]
isahc = { version = "1.2.0", features = ["json"] } isahc = { version = "1.2.0", features = ["json"], optional = true }
semver = { version = "0.11.0", features = ["serde"] } semver = { version = "0.11.0", features = ["serde"], optional = true }
serde = { version = "1.0.118", features = ["derive"] } serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.60" serde_json = "1.0.60"
toml = "0.5.8" toml = "0.5.8"
toml_edit = "0.2.0" toml_edit = { version = "0.2.0", optional = true }
xflags = "0.2.1" xflags = "0.2.1"
xshell = "0.1.9" xshell = "0.1.9"

View File

@ -3,29 +3,13 @@ use std::path::PathBuf;
use isahc::{HttpClient, ReadResponseExt}; use isahc::{HttpClient, ReadResponseExt};
use semver::Version; use semver::Version;
use serde::{de::IgnoredAny, Deserialize}; use serde::{de::IgnoredAny, Deserialize};
use serde_json::from_str as from_json_str;
use toml_edit::{value, Document}; use toml_edit::{value, Document};
use xshell::{cmd, pushd, read_file, write_file}; use xshell::{cmd, pushd, read_file, write_file};
use crate::{util::ask_yes_no, Result}; use crate::{util::ask_yes_no, Metadata, Result};
const CRATESIO_API: &str = "https://crates.io/api/v1/crates"; const CRATESIO_API: &str = "https://crates.io/api/v1/crates";
/// The metadata of a cargo workspace.
#[derive(Clone, Debug, Deserialize)]
pub struct Metadata {
pub workspace_root: PathBuf,
pub packages: Vec<Package>,
}
impl Metadata {
/// Load a new `Metadata` from the command line.
pub fn load() -> Result<Metadata> {
let metadata_json = cmd!("cargo metadata --no-deps --format-version 1").read()?;
Ok(from_json_str(&metadata_json)?)
}
}
/// A cargo package. /// A cargo package.
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct Package { pub struct Package {

View File

@ -4,7 +4,7 @@ use std::path::PathBuf;
use xshell::pushd; use xshell::pushd;
use crate::{cargo::Metadata, cmd, Result}; use crate::{cmd, Metadata, Result};
const MSRV: &str = "1.45"; const MSRV: &str = "1.45";

View File

@ -1,7 +1,11 @@
#![allow(dead_code)] // silence never-used warning for from_vec in generated code #![allow(dead_code)] // silence never-used warning for from_vec in generated code
#[cfg(feature = "default")]
use semver::Version; use semver::Version;
#[cfg(not(feature = "default"))]
use std::string::String as Version;
xflags::xflags! { xflags::xflags! {
src "./src/flags.rs" src "./src/flags.rs"

View File

@ -3,19 +3,23 @@
//! This binary is integrated into the `cargo` command line by using an alias in //! This binary is integrated into the `cargo` command line by using an alias in
//! `.cargo/config`. Run commands as `cargo xtask [command]`. //! `.cargo/config`. Run commands as `cargo xtask [command]`.
use std::{env, path::Path}; use std::path::PathBuf;
use serde::Deserialize; use serde::Deserialize;
use toml::from_str as from_toml_str; use serde_json::from_str as from_json_str;
use xshell::read_file;
#[cfg(feature = "default")]
mod cargo; mod cargo;
mod ci; mod ci;
mod flags; mod flags;
#[cfg(feature = "default")]
mod release; mod release;
#[cfg(feature = "default")]
mod util; mod util;
use self::{ci::CiTask, release::ReleaseTask}; use ci::CiTask;
#[cfg(feature = "default")]
use release::ReleaseTask;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
@ -33,36 +37,63 @@ fn try_main() -> Result<()> {
println!("{}", flags::Xtask::HELP); println!("{}", flags::Xtask::HELP);
Ok(()) Ok(())
} }
flags::XtaskCmd::Release(cmd) => {
let mut task = ReleaseTask::new(cmd.name, cmd.version)?;
task.run()
}
flags::XtaskCmd::Publish(cmd) => {
let mut task = ReleaseTask::new(cmd.name, cmd.version)?;
task.run()
}
flags::XtaskCmd::Ci(ci) => { flags::XtaskCmd::Ci(ci) => {
let task = CiTask::new(ci.version)?; let task = CiTask::new(ci.version)?;
task.run() task.run()
} }
#[cfg(feature = "default")]
flags::XtaskCmd::Release(cmd) => {
let mut task = ReleaseTask::new(cmd.name, cmd.version)?;
task.run()
}
#[cfg(feature = "default")]
flags::XtaskCmd::Publish(cmd) => {
let mut task = ReleaseTask::new(cmd.name, cmd.version)?;
task.run()
}
#[cfg(not(feature = "default"))]
_ => {
Err("This command is only available when xtask is built with default features.".into())
}
} }
} }
/// The metadata of a cargo workspace.
#[derive(Clone, Debug, Deserialize)]
pub struct Metadata {
pub workspace_root: PathBuf,
#[cfg(feature = "default")]
pub packages: Vec<cargo::Package>,
}
impl Metadata {
/// Load a new `Metadata` from the command line.
pub fn load() -> Result<Metadata> {
let metadata_json = cmd!("cargo metadata --no-deps --format-version 1").read()?;
Ok(from_json_str(&metadata_json)?)
}
}
#[cfg(feature = "default")]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Config { struct Config {
/// Credentials to authenticate to GitHub. /// Credentials to authenticate to GitHub.
github: GithubConfig, github: GithubConfig,
} }
#[cfg(feature = "default")]
impl Config { impl Config {
/// Load a new `Config` from `config.toml`. /// Load a new `Config` from `config.toml`.
fn load() -> Result<Self> { fn load() -> Result<Self> {
use std::{env, path::Path};
let path = Path::new(&env!("CARGO_MANIFEST_DIR")).join("config.toml"); let path = Path::new(&env!("CARGO_MANIFEST_DIR")).join("config.toml");
let config = read_file(path)?; let config = xshell::read_file(path)?;
Ok(from_toml_str(&config)?) Ok(toml::from_str(&config)?)
} }
} }
#[cfg(feature = "default")]
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct GithubConfig { struct GithubConfig {
/// The username to use for authentication. /// The username to use for authentication.

View File

@ -14,12 +14,7 @@ use semver::{Identifier, Version};
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;
use crate::{ use crate::{cargo::Package, cmd, util::ask_yes_no, GithubConfig, Metadata, Result};
cargo::{Metadata, Package},
cmd,
util::ask_yes_no,
GithubConfig, Result,
};
const GITHUB_API_RUMA: &str = "https://api.github.com/repos/ruma/ruma"; const GITHUB_API_RUMA: &str = "https://api.github.com/repos/ruma/ruma";