Compare commits

..

No commits in common. "main" and "refactor-git-mod" have entirely different histories.

12 changed files with 40 additions and 155 deletions

View File

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

View File

@ -6,26 +6,6 @@ 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
Support reading version data from `Cargo.toml`
## 0.6.1
Fixed a logic error in release cutting.
## 0.5.2
Detect tags better.
## 0.5.1
Initialize `pretty_env_logger` on app boot. Oops.
## 0.5.0 ## 0.5.0
A lot of internals to this program were exposed to external consumers. This was A lot of internals to this program were exposed to external consumers. This was

40
Cargo.lock generated
View File

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

View File

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

1
VERSION Normal file
View File

@ -0,0 +1 @@
0.5.0

View File

@ -5,10 +5,10 @@
"homepage": "", "homepage": "",
"owner": "nmattia", "owner": "nmattia",
"repo": "naersk", "repo": "naersk",
"rev": "529e910a3f423a8211f8739290014b754b2555b6", "rev": "a82fd7dc31a58c462b6dfa9d9d886fa2cc75dfd4",
"sha256": "0bcy9nmyaan5jvp0wg80wkizc9j166ns685rdr1kbhkvdpywv46y", "sha256": "00bjwir52y6jbf0b22qy9qxramw35k5fc7kp9hymr1zgpmw9kbwg",
"type": "tarball", "type": "tarball",
"url": "https://github.com/nmattia/naersk/archive/529e910a3f423a8211f8739290014b754b2555b6.tar.gz", "url": "https://github.com/nmattia/naersk/archive/a82fd7dc31a58c462b6dfa9d9d886fa2cc75dfd4.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"nixpkgs-mozilla": { "nixpkgs-mozilla": {
@ -17,10 +17,10 @@
"homepage": null, "homepage": null,
"owner": "mozilla", "owner": "mozilla",
"repo": "nixpkgs-mozilla", "repo": "nixpkgs-mozilla",
"rev": "efda5b357451dbb0431f983cca679ae3cd9b9829", "rev": "e912ed483e980dfb4666ae0ed17845c4220e5e7c",
"sha256": "11wqrg86g3qva67vnk81ynvqyfj0zxk83cbrf0p9hsvxiwxs8469", "sha256": "08fvzb8w80bkkabc1iyhzd15f4sm7ra10jn32kfch5klgl0gj3j3",
"type": "tarball", "type": "tarball",
"url": "https://github.com/mozilla/nixpkgs-mozilla/archive/efda5b357451dbb0431f983cca679ae3cd9b9829.tar.gz", "url": "https://github.com/mozilla/nixpkgs-mozilla/archive/e912ed483e980dfb4666ae0ed17845c4220e5e7c.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
} }
} }

View File

@ -9,19 +9,16 @@ 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".into())?); let tag = tag.unwrap_or(version::read_version("VERSION".into())?);
let vtag = format!("v{}", tag);
if git::has_tag(&repo, vtag.clone())? { if git::has_tag(&repo, tag.clone())? {
println!("release {} already released", vtag); return Err(anyhow::anyhow!("what"));
return Ok(());
} }
let desc = changelog::read(fname, tag.clone())?; let desc = changelog::read(fname, tag.clone())?;
let cli = gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT)?; let cli = gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT)?;
let repo = cli let vtag = format!("v{}", tag);
.get_repo(common.owner.clone(), common.repo.clone()) let repo = cli.get_repo(common.owner.clone(), common.repo.clone()).await?;
.await?;
let cr = gitea::CreateRelease { let cr = gitea::CreateRelease {
body: desc, body: desc,

View File

@ -6,7 +6,6 @@ use ::gitea_release::{cmd::{self, Cmd}};
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
let _ = kankyo::init(); let _ = kankyo::init();
pretty_env_logger::init();
let cmd = Cmd::from_args(); let cmd = Cmd::from_args();
match cmd { match cmd {

16
src/version.rs Normal file
View File

@ -0,0 +1,16 @@
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");
}
}

View File

@ -1,53 +0,0 @@
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();
}
}

View File

@ -1,30 +0,0 @@
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<()> { async fn cut() -> Result<()> {
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let name = elfs::next(); let name = elfs::next();
let token = std::env::var("DOMO_GITEA_TOKEN").expect("wanted envvar DOMO_GITEA_TOKEN"); let token = std::env::var("DOMO_GITEA_TOKEN")?;
let cli = gitea::Client::new("https://tulpa.dev".into(), token.clone(), APP_USER_AGENT)?; let cli = gitea::Client::new("https://tulpa.dev".into(), token.clone(), APP_USER_AGENT)?;
debug!("created gitea client"); debug!("created gitea client");