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
- test: |
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
- test: |
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
- test: |
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"
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]
isahc = { version = "1.2.0", features = ["json"] }
semver = { version = "0.11.0", features = ["serde"] }
isahc = { version = "1.2.0", features = ["json"], optional = true }
semver = { version = "0.11.0", features = ["serde"], optional = true }
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.60"
toml = "0.5.8"
toml_edit = "0.2.0"
toml_edit = { version = "0.2.0", optional = true }
xflags = "0.2.1"
xshell = "0.1.9"

View File

@ -3,29 +3,13 @@ use std::path::PathBuf;
use isahc::{HttpClient, ReadResponseExt};
use semver::Version;
use serde::{de::IgnoredAny, Deserialize};
use serde_json::from_str as from_json_str;
use toml_edit::{value, Document};
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";
/// 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.
#[derive(Clone, Debug, Deserialize)]
pub struct Package {

View File

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

View File

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

View File

@ -3,19 +3,23 @@
//! This binary is integrated into the `cargo` command line by using an alias in
//! `.cargo/config`. Run commands as `cargo xtask [command]`.
use std::{env, path::Path};
use std::path::PathBuf;
use serde::Deserialize;
use toml::from_str as from_toml_str;
use xshell::read_file;
use serde_json::from_str as from_json_str;
#[cfg(feature = "default")]
mod cargo;
mod ci;
mod flags;
#[cfg(feature = "default")]
mod release;
#[cfg(feature = "default")]
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>>;
@ -33,36 +37,63 @@ fn try_main() -> Result<()> {
println!("{}", flags::Xtask::HELP);
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) => {
let task = CiTask::new(ci.version)?;
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)]
struct Config {
/// Credentials to authenticate to GitHub.
github: GithubConfig,
}
#[cfg(feature = "default")]
impl Config {
/// Load a new `Config` from `config.toml`.
fn load() -> Result<Self> {
use std::{env, path::Path};
let path = Path::new(&env!("CARGO_MANIFEST_DIR")).join("config.toml");
let config = read_file(path)?;
Ok(from_toml_str(&config)?)
let config = xshell::read_file(path)?;
Ok(toml::from_str(&config)?)
}
}
#[cfg(feature = "default")]
#[derive(Debug, Deserialize)]
struct GithubConfig {
/// The username to use for authentication.

View File

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