From 0ae202ea85d007357ff066277fa858abbc259710 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 28 Sep 2025 16:07:55 -0700 Subject: [PATCH] Add `cargo xtask bump` This is a simple script to assist with bumping the version. --- CONTRIBUTING.md | 18 ++++++++++------ crates/xtask/src/main.rs | 46 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a91481bab..1fdb589df9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -221,12 +221,18 @@ The following are instructions for updating [highlight.js](https://highlightjs.o Instructions for mdBook maintainers to publish a new release: -1. Create a PR to update the version and update the CHANGELOG: - 1. Update the version in `Cargo.toml` - 2. Run `cargo xtask test-all` to verify that everything is passing, and to update `Cargo.lock`. - 3. Run `cargo xtask changelog` to add a new entry to the changelog. - 1. This will add a list of all changes at the top. You will need to move those into the appropriate categories. Most changes that are generally not relevant to a user should be removed. Rewrite the descriptions so that a user can reasonably figure out what it means. - 4. Commit the changes, and open a PR. +1. Create a PR that bumps the version and updates the changelog: + 1. `git fetch upstream` + 2. `git checkout -B bump-version upstream/master` + 3. `cargo xtask bump ` + - This will update the version of all the crates. + - `cargo set-version` must first be installed with `cargo install cargo-edit`. + - Replace `` with the kind of bump (patch, alpha, etc.) + 4. `cargo xtask changelog` + - This will update `CHANGELOG.md` to add a list of all changes at the top. You will need to move those into the appropriate categories. Most changes that are generally not relevant to a user should be removed. Rewrite the descriptions so that a user can reasonably figure out what it means. + 5. `git add --update .` + 6. `git commit` + 7. `git push` 2. After the PR has been merged, create a release in GitHub. This can either be done in the GitHub web UI, or on the command-line: ```bash MDBOOK_VERS="`cargo read-manifest | jq -r .version`" ; \ diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 26aea306ba..edcfac957f 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -2,8 +2,9 @@ use std::collections::BTreeMap; use std::error::Error; -use std::process::Command; +use std::io::Write; use std::process::exit; +use std::process::{Command, Stdio}; mod changelog; @@ -35,9 +36,14 @@ fn main() -> Result<()> { eprintln!("error: specify a command (valid options: {keys})"); exit(1); } - for arg in args { + while let Some(arg) = args.next() { if let Some(cmd_fn) = cmds.get(arg.as_str()) { cmd_fn()?; + } else if arg == "bump" { + let bump_arg = args + .next() + .expect("the next argument should be one of major, minor, patch, rc, beta, alpha"); + bump(&bump_arg)?; } else if matches!(arg.as_str(), "-h" | "--help") { println!("valid options: {keys}"); exit(0) @@ -46,7 +52,7 @@ fn main() -> Result<()> { exit(1); } } - println!("all tests passed!"); + println!("success!"); Ok(()) } @@ -123,3 +129,37 @@ fn eslint() -> Result<()> { } Ok(()) } + +fn bump(bump: &str) -> Result<()> { + // Grab all the publishable crate names. + let metadata = Command::new("cargo") + .args(["metadata", "--format-version=1", "--no-deps"]) + .output()?; + let mut jq = Command::new("jq") + .args(["-r", ".packages[] | select(.publish == null) | .name"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn()?; + jq.stdin.as_mut().unwrap().write_all(&metadata.stdout)?; + let jq_out = jq.wait_with_output()?; + if !jq_out.status.success() { + eprintln!("jq failed"); + exit(1); + } + let names = std::str::from_utf8(&jq_out.stdout).unwrap(); + let mut names: Vec<_> = names.split_whitespace().collect(); + for i in (0..names.len()).rev() { + names.insert(i, "-p"); + } + + let status = Command::new("cargo") + .args(["set-version", "--bump"]) + .arg(bump) + .args(names) + .status()?; + if !status.success() { + eprintln!("cargo set-version failed"); + exit(1); + } + Ok(()) +}