Add a publish subcommand to the xtask (which performs a dry-run by default) (#2539)

* Update and reorganize xtask dependencies

* Add a publish subcommand (which performs a dry run by default)

* Update xtask/src/main.rs

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>

---------

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>
This commit is contained in:
Jesse Braham 2024-11-14 03:27:30 -08:00 committed by GitHub
parent 52c65dd149
commit d68550c485
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 15 deletions

View File

@ -5,16 +5,16 @@ edition = "2021"
publish = false
[dependencies]
anyhow = "1.0.89"
basic-toml = "0.1.9"
chrono = "0.4.38"
clap = { version = "4.5.19", features = ["derive"] }
csv = "1.3.0"
env_logger = "0.11.5"
log = "0.4.22"
minijinja = "2.3.1"
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.210", features = ["derive"] }
strum = { version = "0.26.3", features = ["derive"] }
toml_edit = "0.22.22"
anyhow = "1.0.93"
basic-toml = "0.1.9"
chrono = "0.4.38"
clap = { version = "4.5.20", features = ["derive", "wrap_help"] }
csv = "1.3.1"
env_logger = "0.11.5"
esp-metadata = { path = "../esp-metadata", features = ["clap"] }
log = "0.4.22"
minijinja = "2.5.0"
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0.215", features = ["derive"] }
strum = { version = "0.26.3", features = ["derive"] }
toml_edit = "0.22.22"

View File

@ -113,6 +113,17 @@ impl CargoArgsBuilder {
self
}
#[must_use]
pub fn args<S>(mut self, args: &[S]) -> Self
where
S: Clone + Into<String>,
{
for arg in args {
self.args.push(arg.clone().into());
}
self
}
pub fn add_arg<S>(&mut self, arg: S) -> &mut Self
where
S: Into<String>,

View File

@ -42,6 +42,8 @@ enum Cli {
GenerateEfuseFields(GenerateEfuseFieldsArgs),
/// Lint all packages in the workspace with clippy
LintPackages(LintPackagesArgs),
/// Attempt to publish the specified package.
Publish(PublishArgs),
/// Run doctests for specified chip and package.
#[clap(alias = "run-doc-test")]
RunDocTests(ExampleArgs),
@ -151,6 +153,17 @@ struct LintPackagesArgs {
fix: bool,
}
#[derive(Debug, Args)]
struct PublishArgs {
/// Package to publish (performs a dry-run by default).
#[arg(value_enum)]
package: Package,
/// Do not pass the `--dry-run` argument, actually try to publish.
#[arg(long)]
no_dry_run: bool,
}
#[derive(Debug, Args)]
struct RunElfArgs {
/// Which chip to run the tests for.
@ -164,9 +177,7 @@ struct RunElfArgs {
// Application
fn main() -> Result<()> {
env_logger::Builder::new()
.filter_module("xtask", log::LevelFilter::Info)
.init();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
let workspace = std::env::current_dir()?;
@ -180,6 +191,7 @@ fn main() -> Result<()> {
Cli::FmtPackages(args) => fmt_packages(&workspace, args),
Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args),
Cli::LintPackages(args) => lint_packages(&workspace, args),
Cli::Publish(args) => publish(&workspace, args),
Cli::RunDocTests(args) => run_doc_tests(&workspace, args),
Cli::RunElfs(args) => run_elfs(args),
Cli::RunExample(args) => examples(&workspace, args, CargoAction::Run),
@ -770,6 +782,42 @@ fn lint_package(path: &Path, args: &[&str], fix: bool) -> Result<()> {
xtask::cargo::run(&cargo_args, path)
}
fn publish(workspace: &Path, args: PublishArgs) -> Result<()> {
let package_name = args.package.to_string();
let package_path = xtask::windows_safe_path(&workspace.join(&package_name));
use Package::*;
let mut publish_args = match args.package {
Examples | HilTest => {
bail!(
"Invalid package '{}' specified, this package should not be published!",
args.package
)
}
EspBacktrace | EspHal | EspHalEmbassy | EspIeee802154 | EspLpHal | EspPrintln
| EspStorage | EspWifi | XtensaLxRt => vec!["--no-verify"],
_ => vec![],
};
if !args.no_dry_run {
publish_args.push("--dry-run");
}
let builder = CargoArgsBuilder::default()
.subcommand("publish")
.args(&publish_args);
let args = builder.build();
log::debug!("{args:#?}");
// Execute `cargo publish` command from the package root:
xtask::cargo::run(&args, &package_path)?;
Ok(())
}
fn run_elfs(args: RunElfArgs) -> Result<()> {
let mut failed: Vec<String> = Vec::new();
for elf in fs::read_dir(&args.path)? {