Read versions from Cargo.toml ref #3 #11

Merged
cadey merged 4 commits from cargo-version into main 2020-10-25 19:21:31 +00:00
3 changed files with 17 additions and 4 deletions
Showing only changes of commit 7317c2425e - Show all commits

View File

@ -9,7 +9,7 @@ pub async fn run(
rm: ReleaseMeta, rm: ReleaseMeta,
) -> Result<()> { ) -> Result<()> {
let repo = git2::Repository::open(".")?; let repo = git2::Repository::open(".")?;
let tag = tag.unwrap_or(version::read_version("VERSION".into())?); let tag = tag.unwrap_or(version::read("VERSION".into())?);
let vtag = format!("v{}", tag); let vtag = format!("v{}", tag);
if git::has_tag(&repo, vtag.clone())? { if git::has_tag(&repo, vtag.clone())? {

View File

@ -27,3 +27,12 @@ pub fn read() -> Result<Option<String>> {
None => Ok(None) None => Ok(None)
} }
} }
#[cfg(test)]
mod tests {
#[test]
fn read() {
use super::read;
read().unwrap().unwrap();
}
}

View File

@ -3,18 +3,22 @@ use std::{fs, path::PathBuf};
mod cargo; mod cargo;
pub(crate) fn read_version(fname: PathBuf) -> Result<String> { pub(crate) fn read(fname: PathBuf) -> Result<String> {
let version = cargo::read() let version = cargo::read()
.unwrap() .unwrap()
.unwrap_or(fs::read_to_string(fname)?.trim().into()); .unwrap_or(read_fs(fname)?);
Ok(version) Ok(version)
} }
fn read_fs(fname: PathBuf) -> Result<String> {
Ok(fs::read_to_string(fname)?.trim().into())
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]
fn read_version() { fn read_version() {
let version = super::read_version("./testdata/VERSION".into()).unwrap(); let version = super::read_fs("./testdata/VERSION".into()).unwrap();
assert_eq!(version, "0.1.0"); assert_eq!(version, "0.1.0");
} }
} }