Compare commits

...

8 Commits
v0.6.1 ... main

Author SHA1 Message Date
Cadey Ratio e94e032942 argh
continuous-integration/drone/push Build is passing Details
2020-10-25 16:16:56 -04:00
Cadey Ratio 5c48459414 use rust from reg.tulpa.dev
continuous-integration/drone/push Build is failing Details
2020-10-25 16:01:34 -04:00
Cadey Ratio 26999f5f2c minor parsing bug
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is passing Details
2020-10-25 15:37:16 -04:00
Cadey Ratio 1a0bd1fcc8 Merge pull request 'Read versions from Cargo.toml ref #3' (#11) from cargo-version into main
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build was killed Details
Reviewed-on: #11
2020-10-25 19:21:30 +00:00
Cadey Ratio 9ad6a78579 version bump
continuous-integration/drone/pr Build is passing Details
continuous-integration/drone/push Build is passing Details
2020-10-25 15:06:11 -04:00
Cadey Ratio a49864c419 remove VERSION file 2020-10-25 15:05:07 -04:00
Cadey Ratio 7317c2425e a few fixes for readablilty 2020-10-25 15:04:04 -04:00
Cadey Ratio 26894c7fad add support for reading version data from cargo 2020-10-25 14:53:24 -04:00
10 changed files with 128 additions and 30 deletions

View File

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

View File

@ -6,6 +6,14 @@ 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`
## 0.6.1
Fixed a logic error in release cutting.

40
Cargo.lock generated
View File

@ -98,6 +98,17 @@ version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
[[package]]
name = "cargo_toml"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "513d17226888c7b8283ac02a1c1b0d8a9d4cbf6db65dfadb79f598f5d7966fe9"
dependencies = [
"serde",
"serde_derive",
"toml",
]
[[package]]
name = "cc"
version = "1.0.54"
@ -348,9 +359,10 @@ dependencies = [
[[package]]
name = "gitea-release"
version = "0.5.2"
version = "0.7.1"
dependencies = [
"anyhow",
"cargo_toml",
"comrak",
"elfs",
"git2",
@ -365,6 +377,7 @@ dependencies = [
"structopt",
"tempfile",
"tokio",
"toml",
"url",
]
@ -881,9 +894,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.17"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101"
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
dependencies = [
"unicode-xid",
]
@ -1100,18 +1113,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.111"
version = "1.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9124df5b40cbd380080b2cc6ab894c040a3070d995f5c9dc77e18c34a8ae37d"
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.111"
version = "1.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f2c3ac8e6ca1e9c80b8be1023940162bf81ae3cffbb1809474152f2ce1eb250"
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
dependencies = [
"proc-macro2",
"quote",
@ -1209,9 +1222,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.29"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb37da98a55b1d08529362d9cbb863be17556873df2585904ab9d2bc951291d0"
checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
dependencies = [
"proc-macro2",
"quote",
@ -1353,6 +1366,15 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645"
dependencies = [
"serde",
]
[[package]]
name = "tower-service"
version = "0.3.0"

View File

@ -1,6 +1,6 @@
[package]
name = "gitea-release"
version = "0.5.2"
version = "0.7.1"
authors = ["Christine Dodrill <me@christine.website>"]
edition = "2018"
@ -8,6 +8,7 @@ edition = "2018"
[dependencies]
anyhow = "1.0"
cargo_toml = "0.8.1"
comrak = "0.7"
git2 = "0.13"
http = "0.2"
@ -19,6 +20,7 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
structopt = { version = "0.3", default-features = false }
tokio = { version = "0.2", features = ["macros"] }
toml = "0.5.7"
url = "2"
gitea = { path = "./gitea" }

View File

@ -1 +0,0 @@
0.6.1

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

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

53
src/version/cargo.rs Normal file
View File

@ -0,0 +1,53 @@
use anyhow::Result;
use cargo_toml::Manifest;
use std::fs::{self, File};
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();
let metadata = fs::metadata(&filename).expect("unable to read metadata");
let mut buffer = vec![0; metadata.len() as usize];
f.read(&mut buffer).expect("buffer overflow");
Some(buffer)
}
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))
}
}
}
None => Ok(None)
}
}
#[cfg(test)]
mod tests {
#[test]
fn read() {
use super::read;
let _ = pretty_env_logger::try_init();
read().unwrap().unwrap();
}
}

30
src/version/mod.rs Normal file
View File

@ -0,0 +1,30 @@
use anyhow::Result;
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()
}
};
Ok(version)
}
fn read_fs(fname: PathBuf) -> Result<String> {
log::debug!("reading version data from {:?}", fname);
Ok(fs::read_to_string(fname)?.trim().into())
}
#[cfg(test)]
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");
}
}

View File

@ -10,7 +10,7 @@ const TAG: &'static str = "0.1.0";
async fn cut() -> Result<()> {
let _ = pretty_env_logger::try_init();
let name = elfs::next();
let token = std::env::var("DOMO_GITEA_TOKEN")?;
let token = std::env::var("DOMO_GITEA_TOKEN").expect("wanted envvar DOMO_GITEA_TOKEN");
let cli = gitea::Client::new("https://tulpa.dev".into(), token.clone(), APP_USER_AGENT)?;
debug!("created gitea client");