-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add 'cargo xtask' for custom tasks
This commit implements the initial scaffolding of the 'cargo xtask' pattern for the OmniBOR Rust workspace. In particular, it defines logging, a basic CLI, a mechanism for pipelining and rollback of steps in a process, and the rough outline of a "release" subcommand which will in the future handle releasing new versions of crates in the workspace. Signed-off-by: Andrew Lilley Brinker <[email protected]>
- Loading branch information
1 parent
b03f22c
commit 4fd81ec
Showing
10 changed files
with
464 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
[alias] | ||
xtask = "run --package xtask --" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "xtask" | ||
description = "Helper tasks for the omnibor project workspace" | ||
version = "0.1.0" | ||
publish = false | ||
readme = "README.md" | ||
|
||
homepage.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
anyhow = "1.0.80" | ||
clap = "4.5.1" | ||
duct = "0.13.7" | ||
env_logger = "0.11.2" | ||
log = "0.4.20" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# `xtask` | ||
|
||
This is the `xtask` package for the OmniBOR Rust project. This implements | ||
commonly-used project-wide commands for convenience. | ||
|
||
## Design Goals | ||
|
||
This crate has a few key design goals: | ||
|
||
- __Fast compilation__: This tool will get recompiled whenever changes are | ||
made to it, and we want to empower contributors to the OmniBOR project to | ||
make changes to `xtask` when they encounter a new task for the project that | ||
they want to automate. To make this editing appealing, the write-edit-run | ||
loop needs to be fast, which means fast compilation. | ||
- __Minimal dependencies__: Related to the above, the `xtask` crate should | ||
have a minimal number of dependencies, and where possible those dependencies | ||
should be configured with the minimum number of features. | ||
- __Easy to use__: The commands exposed by `xtask` should have as simple an | ||
interface, and be as automatic, as possible. Fewer flags, fewer required | ||
arguments, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use clap::{arg, builder::PossibleValue, value_parser, ArgMatches, Command, ValueEnum}; | ||
use std::fmt::{Display, Formatter, Result as FmtResult}; | ||
|
||
pub fn args() -> ArgMatches { | ||
Command::new("xtask") | ||
.about("Task runner for the OmniBOR Rust workspace") | ||
.help_expected(true) | ||
.subcommand( | ||
Command::new("release") | ||
.about("Release a new version of a workspace crate") | ||
.arg( | ||
arg!(-c --crate <CRATE>) | ||
.required(true) | ||
.value_parser(value_parser!(Crate)) | ||
.help("the crate to release"), | ||
) | ||
.arg( | ||
arg!(-b --bump <BUMP>) | ||
.required(true) | ||
.value_parser(value_parser!(Bump)) | ||
.help("the version to bump"), | ||
) | ||
.arg( | ||
arg!(--execute) | ||
.required(false) | ||
.value_parser(value_parser!(bool)) | ||
.help("not a dry run, actually execute the release") | ||
), | ||
) | ||
.get_matches() | ||
} | ||
|
||
/// The crate to release; can be "gitoid" or "omnibor" | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum Crate { | ||
GitOid, | ||
OmniBor, | ||
} | ||
|
||
impl Display for Crate { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { | ||
match self { | ||
Crate::GitOid => write!(f, "gitoid"), | ||
Crate::OmniBor => write!(f, "omnibor"), | ||
} | ||
} | ||
} | ||
|
||
impl ValueEnum for Crate { | ||
fn value_variants<'a>() -> &'a [Self] { | ||
&[Crate::GitOid, Crate::OmniBor] | ||
} | ||
|
||
fn to_possible_value(&self) -> Option<PossibleValue> { | ||
Some(match self { | ||
Crate::GitOid => PossibleValue::new("gitoid"), | ||
Crate::OmniBor => PossibleValue::new("omnibor"), | ||
}) | ||
} | ||
} | ||
|
||
/// The version to bump; can be "major", "minor", or "patch" | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum Bump { | ||
Major, | ||
Minor, | ||
Patch, | ||
} | ||
|
||
impl Display for Bump { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { | ||
match self { | ||
Bump::Major => write!(f, "major"), | ||
Bump::Minor => write!(f, "minor"), | ||
Bump::Patch => write!(f, "patch"), | ||
} | ||
} | ||
} | ||
|
||
impl ValueEnum for Bump { | ||
fn value_variants<'a>() -> &'a [Self] { | ||
&[Bump::Major, Bump::Minor, Bump::Patch] | ||
} | ||
|
||
fn to_possible_value(&self) -> Option<PossibleValue> { | ||
Some(match self { | ||
Bump::Major => PossibleValue::new("major"), | ||
Bump::Minor => PossibleValue::new("minor"), | ||
Bump::Patch => PossibleValue::new("patch"), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
mod cli; | ||
mod pipeline; | ||
mod release; | ||
|
||
use anyhow::Result; | ||
use env_logger::{Env, Builder as LoggerBuilder}; | ||
|
||
fn main() -> Result<()> { | ||
LoggerBuilder::from_env(Env::default().default_filter_or("info")).init(); | ||
|
||
let args = cli::args(); | ||
|
||
match args.subcommand() { | ||
Some(("release", args)) => release::run(args), | ||
Some(_) | None => Ok(()), | ||
} | ||
} |
Oops, something went wrong.