Merge pull request #2876 from ehuss/xtask-bump

Add `cargo xtask bump`
This commit is contained in:
Eric Huss 2025-09-28 23:21:34 +00:00 committed by GitHub
commit 4e41c844c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 9 deletions

View file

@ -221,12 +221,18 @@ The following are instructions for updating [highlight.js](https://highlightjs.o
Instructions for mdBook maintainers to publish a new release: Instructions for mdBook maintainers to publish a new release:
1. Create a PR to update the version and update the CHANGELOG: 1. Create a PR that bumps the version and updates the changelog:
1. Update the version in `Cargo.toml` 1. `git fetch upstream`
2. Run `cargo xtask test-all` to verify that everything is passing, and to update `Cargo.lock`. 2. `git checkout -B bump-version upstream/master`
3. Run `cargo xtask changelog` to add a new entry to the changelog. 3. `cargo xtask bump <BUMP>`
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. - This will update the version of all the crates.
4. Commit the changes, and open a PR. - `cargo set-version` must first be installed with `cargo install cargo-edit`.
- Replace `<BUMP>` 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: 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 ```bash
MDBOOK_VERS="`cargo read-manifest | jq -r .version`" ; \ MDBOOK_VERS="`cargo read-manifest | jq -r .version`" ; \

View file

@ -2,8 +2,9 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::error::Error; use std::error::Error;
use std::process::Command; use std::io::Write;
use std::process::exit; use std::process::exit;
use std::process::{Command, Stdio};
mod changelog; mod changelog;
@ -35,9 +36,14 @@ fn main() -> Result<()> {
eprintln!("error: specify a command (valid options: {keys})"); eprintln!("error: specify a command (valid options: {keys})");
exit(1); exit(1);
} }
for arg in args { while let Some(arg) = args.next() {
if let Some(cmd_fn) = cmds.get(arg.as_str()) { if let Some(cmd_fn) = cmds.get(arg.as_str()) {
cmd_fn()?; 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") { } else if matches!(arg.as_str(), "-h" | "--help") {
println!("valid options: {keys}"); println!("valid options: {keys}");
exit(0) exit(0)
@ -46,7 +52,7 @@ fn main() -> Result<()> {
exit(1); exit(1);
} }
} }
println!("all tests passed!"); println!("success!");
Ok(()) Ok(())
} }
@ -123,3 +129,37 @@ fn eslint() -> Result<()> {
} }
Ok(()) 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(())
}