Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Cadey Ratio | e94e032942 | |
Cadey Ratio | 5c48459414 | |
Cadey Ratio | 26999f5f2c |
|
@ -3,7 +3,7 @@ name: tests/release
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: rust tests
|
- name: rust tests
|
||||||
image: "rust:1"
|
image: "reg.tulpa.dev/rust:1"
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- cargo test --all
|
- cargo test --all
|
||||||
|
|
|
@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## 0.7.1
|
||||||
|
|
||||||
|
Fix a minor parsing bug
|
||||||
|
|
||||||
## 0.7.0
|
## 0.7.0
|
||||||
|
|
||||||
Support reading version data from `Cargo.toml`
|
Support reading version data from `Cargo.toml`
|
||||||
|
|
|
@ -359,7 +359,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gitea-release"
|
name = "gitea-release"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gitea-release"
|
name = "gitea-release"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
authors = ["Christine Dodrill <me@christine.website>"]
|
authors = ["Christine Dodrill <me@christine.website>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::io::Read;
|
||||||
fn get_file_as_byte_vec(filename: &str) -> Option<Vec<u8>> {
|
fn get_file_as_byte_vec(filename: &str) -> Option<Vec<u8>> {
|
||||||
let f = File::open(&filename);
|
let f = File::open(&filename);
|
||||||
if f.is_err() {
|
if f.is_err() {
|
||||||
|
log::debug!("can't read from Cargo.toml: {:?}", f.unwrap_err());
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut f = f.unwrap();
|
let mut f = f.unwrap();
|
||||||
|
@ -17,12 +18,25 @@ fn get_file_as_byte_vec(filename: &str) -> Option<Vec<u8>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read() -> Result<Option<String>> {
|
pub fn read() -> Result<Option<String>> {
|
||||||
|
log::debug!("reading version from Cargo.toml");
|
||||||
let bytes = get_file_as_byte_vec("Cargo.toml");
|
let bytes = get_file_as_byte_vec("Cargo.toml");
|
||||||
|
log::debug!("{:?}", bytes);
|
||||||
|
|
||||||
match bytes {
|
match bytes {
|
||||||
Some(bytes) => {
|
Some(bytes) => {
|
||||||
let pkg: Manifest = toml::from_slice(&bytes)?;
|
log::trace!("reading toml");
|
||||||
Ok(Some(pkg.package.unwrap().version))
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => Ok(None)
|
None => Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +47,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn read() {
|
fn read() {
|
||||||
use super::read;
|
use super::read;
|
||||||
|
let _ = pretty_env_logger::try_init();
|
||||||
read().unwrap().unwrap();
|
read().unwrap().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,18 @@ use std::{fs, path::PathBuf};
|
||||||
mod cargo;
|
mod cargo;
|
||||||
|
|
||||||
pub(crate) fn read(fname: PathBuf) -> Result<String> {
|
pub(crate) fn read(fname: PathBuf) -> Result<String> {
|
||||||
let version = cargo::read()
|
let version = match read_fs(fname.clone()) {
|
||||||
.unwrap()
|
Ok(version) => version,
|
||||||
.unwrap_or(read_fs(fname)?);
|
Err(why) => {
|
||||||
|
log::debug!("can't read {:?}: {:?}", fname, why);
|
||||||
|
cargo::read().unwrap().unwrap()
|
||||||
|
}
|
||||||
|
};
|
||||||
Ok(version)
|
Ok(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_fs(fname: PathBuf) -> Result<String> {
|
fn read_fs(fname: PathBuf) -> Result<String> {
|
||||||
|
log::debug!("reading version data from {:?}", fname);
|
||||||
Ok(fs::read_to_string(fname)?.trim().into())
|
Ok(fs::read_to_string(fname)?.trim().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +23,7 @@ fn read_fs(fname: PathBuf) -> Result<String> {
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn read_version() {
|
fn read_version() {
|
||||||
|
let _ = pretty_env_logger::try_init();
|
||||||
let version = super::read_fs("./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");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue