Compare commits

..

No commits in common. "main" and "cargo-version" have entirely different histories.

6 changed files with 8 additions and 33 deletions

View File

@ -3,7 +3,7 @@ name: tests/release
steps:
- name: rust tests
image: "reg.tulpa.dev/rust:1"
image: "rust:1"
pull: always
commands:
- cargo test --all

View File

@ -6,10 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
## 0.7.1
Fix a minor parsing bug
## 0.7.0
Support reading version data from `Cargo.toml`

2
Cargo.lock generated
View File

@ -359,7 +359,7 @@ dependencies = [
[[package]]
name = "gitea-release"
version = "0.7.1"
version = "0.7.0"
dependencies = [
"anyhow",
"cargo_toml",

View File

@ -1,6 +1,6 @@
[package]
name = "gitea-release"
version = "0.7.1"
version = "0.7.0"
authors = ["Christine Dodrill <me@christine.website>"]
edition = "2018"

View File

@ -6,7 +6,6 @@ use std::io::Read;
fn get_file_as_byte_vec(filename: &str) -> Option<Vec<u8>> {
let f = File::open(&filename);
if f.is_err() {
log::debug!("can't read from Cargo.toml: {:?}", f.unwrap_err());
return None;
}
let mut f = f.unwrap();
@ -18,25 +17,12 @@ fn get_file_as_byte_vec(filename: &str) -> Option<Vec<u8>> {
}
pub fn read() -> Result<Option<String>> {
log::debug!("reading version from Cargo.toml");
let bytes = get_file_as_byte_vec("Cargo.toml");
log::debug!("{:?}", bytes);
match bytes {
Some(bytes) => {
log::trace!("reading toml");
let pkg : Result<Manifest, _> = toml::from_slice(&bytes);
match pkg {
Err(why) => {
log::error!("error parsing Cargo.toml: {:?}", why);
Err(why.into())
}
Ok(pkg) => {
let version = pkg.package.unwrap().version;
log::trace!("got version {}", version);
Ok(Some(version))
}
}
let pkg: Manifest = toml::from_slice(&bytes)?;
Ok(Some(pkg.package.unwrap().version))
}
None => Ok(None)
}
@ -47,7 +33,6 @@ mod tests {
#[test]
fn read() {
use super::read;
let _ = pretty_env_logger::try_init();
read().unwrap().unwrap();
}
}

View File

@ -4,18 +4,13 @@ use std::{fs, path::PathBuf};
mod cargo;
pub(crate) fn read(fname: PathBuf) -> Result<String> {
let version = match read_fs(fname.clone()) {
Ok(version) => version,
Err(why) => {
log::debug!("can't read {:?}: {:?}", fname, why);
cargo::read().unwrap().unwrap()
}
};
let version = cargo::read()
.unwrap()
.unwrap_or(read_fs(fname)?);
Ok(version)
}
fn read_fs(fname: PathBuf) -> Result<String> {
log::debug!("reading version data from {:?}", fname);
Ok(fs::read_to_string(fname)?.trim().into())
}
@ -23,7 +18,6 @@ fn read_fs(fname: PathBuf) -> Result<String> {
mod tests {
#[test]
fn read_version() {
let _ = pretty_env_logger::try_init();
let version = super::read_fs("./testdata/VERSION".into()).unwrap();
assert_eq!(version, "0.1.0");
}