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,
) -> Result<()> {
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);
if git::has_tag(&repo, vtag.clone())? {

View File

@ -27,3 +27,12 @@ pub fn read() -> Result<Option<String>> {
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;
pub(crate) fn read_version(fname: PathBuf) -> Result<String> {
pub(crate) fn read(fname: PathBuf) -> Result<String> {
let version = cargo::read()
.unwrap()
.unwrap_or(fs::read_to_string(fname)?.trim().into());
.unwrap_or(read_fs(fname)?);
Ok(version)
}
fn read_fs(fname: PathBuf) -> Result<String> {
Ok(fs::read_to_string(fname)?.trim().into())
}
#[cfg(test)]
mod tests {
#[test]
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");
}
}