Skip to content

Commit d3e7f73

Browse files
committed
Minor fixes to xtask bump
- check for the correct (no changes) string - insert the new version link in the correct place
1 parent 122cd75 commit d3e7f73

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

xtask/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ edition = "2018"
55

66
[dependencies]
77
cargo_toml = "0.9.1"
8+
chrono = "0.4.19"

xtask/src/bump.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! This has been copied pretty much wholesale from https://github.com/nrf-rs/nrf-hal/blob/master/xtask/src/lib.rs
22
use super::CRATES;
3+
use chrono::Local;
34
use std::fs;
45

56
fn file_replace(path: &str, from: &str, to: &str, dry_run: bool) {
@@ -33,13 +34,17 @@ pub fn bump_versions(new_version: &str, dry_run: bool) {
3334
let changelog = fs::read_to_string(changelog_path).unwrap();
3435
// (ignore empty changelog when this is a dry_run, since that runs in normal CI)
3536
assert!(
36-
dry_run || !changelog.contains("(no entries)"),
37-
"changelog contains `(no entries)`; please fill it"
37+
dry_run || !changelog.contains("(no changes)"),
38+
"changelog contains `(no changes)`; please fill it"
3839
);
3940

4041
// Prepend empty "[Unreleased]" section, promote the current one.
42+
let today = Local::today().format("%Y-%m-%d").to_string();
4143
let from = String::from("## [Unreleased]");
42-
let to = format!("## [Unreleased]\n\n(no changes)\n\n## [{}]", new_version);
44+
let to = format!(
45+
"## [Unreleased]\n\n(no changes)\n\n## [{}] - {}",
46+
new_version, today
47+
);
4348
file_replace(changelog_path, &from, &to, dry_run);
4449

4550
// Replace the Unreleased link
@@ -48,21 +53,12 @@ pub fn bump_versions(new_version: &str, dry_run: bool) {
4853
old_version = old_version,
4954
);
5055
let to = format!(
51-
r#"[Unreleased]: https://github.com/nrf-rs/microbit/compare/v{new_version}...HEAD"#,
56+
"[Unreleased]: https://github.com/nrf-rs/microbit/compare/v{new_version}...HEAD\n\
57+
[{new_version}]: https://github.com/nrf-rs/microbit/releases/tag/v{old_version}...v{new_version}",
5258
new_version = new_version,
59+
old_version = old_version,
5360
);
5461
file_replace(changelog_path, &from, &to, dry_run);
55-
56-
// Append release link at the end.
57-
let mut changelog = fs::read_to_string(changelog_path).unwrap();
58-
changelog.push_str(&format!(
59-
"[{new_version}]: https://github.com/nrf-rs/microbit/releases/tag/v{new_version}...v{old_version}\n",
60-
new_version = new_version,
61-
old_version = old_version,
62-
));
63-
if !dry_run {
64-
fs::write(changelog_path, changelog).unwrap();
65-
}
6662
}
6763

6864
{

0 commit comments

Comments
 (0)