xtask: Get release changes after the commit

In case they were modified right before being committed.
This commit is contained in:
Kévin Commaille 2025-02-06 14:27:13 +01:00 committed by strawberry
parent f4bb2b713c
commit 9d9633895f
2 changed files with 26 additions and 10 deletions

View file

@ -154,10 +154,21 @@ impl Package {
Ok(())
}
/// Get the changes for the version.
/// Update the changelog for the release of the current version, if needed.
pub fn update_changelog(&self, sh: &Shell) -> Result<()> {
self.changes_inner(sh, true)?;
Ok(())
}
/// Get the changes for the current version.
pub fn changes(&self, sh: &Shell) -> Result<String> {
self.changes_inner(sh, false)
}
/// Get the changes for the current version.
///
/// If `update` is `true`, update the changelog for the release of the given version.
pub fn changes(&self, sh: &Shell, update: bool) -> Result<String> {
/// If `update` is `true`, the changelog is updated if needed.
fn changes_inner(&self, sh: &Shell, update: bool) -> Result<String> {
if self.name == "ruma-macros" {
// ruma-macros doesn't have a changelog and won't create a tag.
return Ok(String::new());
@ -175,10 +186,11 @@ impl Package {
let (update, title_start) = if let Some(pos) = changelog.find(&format!("# {version}\n")) {
(false, pos)
} else if changelog.starts_with(&format!("# {version} (unreleased)\n"))
|| changelog.starts_with("# [unreleased]\n")
} else if update
&& (changelog.starts_with(&format!("# {version} (unreleased)\n"))
|| changelog.starts_with("# [unreleased]\n"))
{
(update, 0)
(true, 0)
} else {
return Err("Could not find version title in changelog".into());
};

View file

@ -122,16 +122,20 @@ impl ReleaseTask {
false
};
let changes = &self.package.changes(&self.sh, !prerelease && !self.dry_run)?;
if self.dry_run {
println!("Changes:\n{changes}");
if !prerelease && !self.dry_run {
self.package.update_changelog(&self.sh)?;
}
if create_commit {
self.commit()?;
}
let changes = &self.package.changes(&self.sh)?;
if self.dry_run {
println!("Changes:\n{changes}");
}
self.package.publish(&self.sh, &self.http_client, self.dry_run)?;
let branch = cmd!(&self.sh, "git rev-parse --abbrev-ref HEAD").read()?;