diff options
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/release.rs | 12 | ||||
-rw-r--r-- | xtask/src/release/bump.rs | 15 |
2 files changed, 16 insertions, 11 deletions
diff --git a/xtask/src/release.rs b/xtask/src/release.rs index acb8888..b53c838 100644 --- a/xtask/src/release.rs +++ b/xtask/src/release.rs @@ -85,11 +85,11 @@ impl Step { pub fn bump(level: Level) -> Result<Bump> { let mut bump = Bump::from(level); - bump.bump_file("Cargo.toml", bump::replace_cargo)?; - bump.bump_file("README.md", bump::replace)?; - bump.bump_file("pkg/archlinux/projectr/PKGBUILD", bump::replace)?; - bump.bump_file("pkg/archlinux/projectr-bin/PKGBUILD", bump::replace)?; - bump.bump_file("pkg/archlinux/projectr-git/PKGBUILD", |buf, _| { + bump.bump_file("./Cargo.toml", bump::replace_cargo)?; + bump.bump_file("./README.md", bump::replace)?; + bump.bump_file("./pkg/archlinux/projectr/PKGBUILD", bump::replace)?; + bump.bump_file("./pkg/archlinux/projectr-bin/PKGBUILD", bump::replace)?; + bump.bump_file("./pkg/archlinux/projectr-git/PKGBUILD", |buf, _| { let stdout = std::process::Command::new("git") .arg("describe") .arg("--long") @@ -111,7 +111,7 @@ impl Step { } })?; - bump.bump_file("CHANGELOG.md", |buf, Bump { version: _, next }| { + bump.bump_file("./CHANGELOG.md", |buf, Bump { version: _, next }| { let date = chrono::Utc::now().format("%Y-%m-%d"); Ok(buf .replace( diff --git a/xtask/src/release/bump.rs b/xtask/src/release/bump.rs index 617cfd6..7a817e7 100644 --- a/xtask/src/release/bump.rs +++ b/xtask/src/release/bump.rs @@ -1,7 +1,7 @@ use std::{ fmt::Display, fs::File, - io::{Read, Write}, + io::{BufRead, BufReader, BufWriter, Read, Write}, path::Path, process::Command, str::FromStr, @@ -83,9 +83,10 @@ impl Bump { path.display() ); - let file = File::open(path)?; + let reader = File::options().read(true).open(path)?; + let writer = File::options().write(true).open(path)?; - self.bump(&file, &file, mutator)?; + self.bump(reader, writer, mutator)?; let git_added = Command::new("git").arg("add").arg(path).status()?; @@ -94,18 +95,22 @@ impl Bump { Ok(()) } - fn bump<R, W, F>(&self, mut reader: R, mut writer: W, mutator: F) -> Result<()> + fn bump<R, W, F>(&self, reader: R, writer: W, mutator: F) -> Result<()> where R: Read, W: Write, F: Fn(String, &Self) -> Result<String>, { + let mut reader = BufReader::new(reader); + let mut writer = BufWriter::new(writer); let mut buf = String::new(); + reader.read_to_string(&mut buf)?; let buf = mutator(buf, self)?; - writer.write_all(buf.as_bytes()).map_err(Into::into) + writer.write_all(buf.as_bytes())?; + writer.flush().map_err(Into::into) } } |