Skip to content

Commit 4e41c84

Browse files
authored
Merge pull request #2876 from ehuss/xtask-bump
Add `cargo xtask bump`
2 parents 7108314 + 0ae202e commit 4e41c84

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,18 @@ The following are instructions for updating [highlight.js](https://highlightjs.o
221221

222222
Instructions for mdBook maintainers to publish a new release:
223223

224-
1. Create a PR to update the version and update the CHANGELOG:
225-
1. Update the version in `Cargo.toml`
226-
2. Run `cargo xtask test-all` to verify that everything is passing, and to update `Cargo.lock`.
227-
3. Run `cargo xtask changelog` to add a new entry to the changelog.
228-
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.
229-
4. Commit the changes, and open a PR.
224+
1. Create a PR that bumps the version and updates the changelog:
225+
1. `git fetch upstream`
226+
2. `git checkout -B bump-version upstream/master`
227+
3. `cargo xtask bump <BUMP>`
228+
- This will update the version of all the crates.
229+
- `cargo set-version` must first be installed with `cargo install cargo-edit`.
230+
- Replace `<BUMP>` with the kind of bump (patch, alpha, etc.)
231+
4. `cargo xtask changelog`
232+
- 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.
233+
5. `git add --update .`
234+
6. `git commit`
235+
7. `git push`
230236
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:
231237
```bash
232238
MDBOOK_VERS="`cargo read-manifest | jq -r .version`" ; \

crates/xtask/src/main.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
33
use std::collections::BTreeMap;
44
use std::error::Error;
5-
use std::process::Command;
5+
use std::io::Write;
66
use std::process::exit;
7+
use std::process::{Command, Stdio};
78

89
mod changelog;
910

@@ -35,9 +36,14 @@ fn main() -> Result<()> {
3536
eprintln!("error: specify a command (valid options: {keys})");
3637
exit(1);
3738
}
38-
for arg in args {
39+
while let Some(arg) = args.next() {
3940
if let Some(cmd_fn) = cmds.get(arg.as_str()) {
4041
cmd_fn()?;
42+
} else if arg == "bump" {
43+
let bump_arg = args
44+
.next()
45+
.expect("the next argument should be one of major, minor, patch, rc, beta, alpha");
46+
bump(&bump_arg)?;
4147
} else if matches!(arg.as_str(), "-h" | "--help") {
4248
println!("valid options: {keys}");
4349
exit(0)
@@ -46,7 +52,7 @@ fn main() -> Result<()> {
4652
exit(1);
4753
}
4854
}
49-
println!("all tests passed!");
55+
println!("success!");
5056
Ok(())
5157
}
5258

@@ -123,3 +129,37 @@ fn eslint() -> Result<()> {
123129
}
124130
Ok(())
125131
}
132+
133+
fn bump(bump: &str) -> Result<()> {
134+
// Grab all the publishable crate names.
135+
let metadata = Command::new("cargo")
136+
.args(["metadata", "--format-version=1", "--no-deps"])
137+
.output()?;
138+
let mut jq = Command::new("jq")
139+
.args(["-r", ".packages[] | select(.publish == null) | .name"])
140+
.stdin(Stdio::piped())
141+
.stdout(Stdio::piped())
142+
.spawn()?;
143+
jq.stdin.as_mut().unwrap().write_all(&metadata.stdout)?;
144+
let jq_out = jq.wait_with_output()?;
145+
if !jq_out.status.success() {
146+
eprintln!("jq failed");
147+
exit(1);
148+
}
149+
let names = std::str::from_utf8(&jq_out.stdout).unwrap();
150+
let mut names: Vec<_> = names.split_whitespace().collect();
151+
for i in (0..names.len()).rev() {
152+
names.insert(i, "-p");
153+
}
154+
155+
let status = Command::new("cargo")
156+
.args(["set-version", "--bump"])
157+
.arg(bump)
158+
.args(names)
159+
.status()?;
160+
if !status.success() {
161+
eprintln!("cargo set-version failed");
162+
exit(1);
163+
}
164+
Ok(())
165+
}

0 commit comments

Comments
 (0)