implement automagic tagging, uploading and the like for release

This commit is contained in:
Cadey Ratio 2020-05-31 14:13:14 -04:00
parent c960a07ec2
commit 508a100268
4 changed files with 32 additions and 11 deletions

View File

@ -5,9 +5,18 @@ use std::path::PathBuf;
pub(crate) async fn run(
common: Common,
fname: PathBuf,
tag: String,
tag: Option<String>,
rm: ReleaseMeta,
) -> Result<()> {
let repo = git2::Repository::open(".")?;
let tag = tag.unwrap_or(version::read_version("VERSION".into())?);
let desc = changelog::read(fname.clone(), tag.clone())?;
if !git::has_tag(&repo, tag.clone())? {
git::tag_version(&repo, tag.clone(), desc.clone())?;
let _ = git::push_tags(&repo);
}
let desc = changelog::read(fname, tag.clone())?;
let cli = client(&common)?;
let cr = CreateRelease {

View File

@ -1,9 +1,22 @@
use anyhow::Result;
use git2::Repository;
use std::path::PathBuf;
use git2::{Repository, Signature};
pub(crate) fn has_tag(repo_path: PathBuf, tag: String) -> Result<bool> {
let repo = Repository::init(repo_path)?;
pub(crate) fn push_tags(repo: &Repository) -> Result<()> {
let mut remote = repo.find_remote("origin")?;
remote.connect(git2::Direction::Push)?;
remote.push(&["refs/tags/*:refs/tags/*"], None)?;
Ok(())
}
pub(crate) fn tag_version(repo: &Repository, tag: String, desc: String) -> Result<()> {
let sig = &Signature::now("Gitea Release Tool", "gitea-release@tulpa.dev")?;
let obj = repo.revparse_single("HEAD")?;
repo.tag(&tag, &obj, &sig, &desc, false)?;
Ok(())
}
pub(crate) fn has_tag(repo: &Repository, tag: String) -> Result<bool> {
let tags = repo.tag_names(Some(&tag))?;
for tag_obj in tags.iter() {
@ -40,7 +53,7 @@ mod tests {
let oid = index.write_tree()?;
let tree = repo.find_tree(oid)?;
let sig = Signature::now("Testificate", "test@ifica.te")?;
let sig = &Signature::now("Gitea Release Tool", "gitea-release@tulpa.dev")?;
repo.commit(
Some("HEAD"),
&sig,
@ -50,9 +63,8 @@ mod tests {
&[],
)?;
let obj = repo.revparse_single("HEAD")?;
repo.tag(TAG, &obj, &sig, &format!("version {}", TAG), false)?;
assert!(super::has_tag(dir.path().into(), TAG.into())?);
super::tag_version(&repo, TAG.into(), format!("version {}", TAG))?;
assert!(super::has_tag(&repo, TAG.into())?);
Ok(())
}

View File

@ -106,7 +106,7 @@ pub(crate) enum Cmd {
#[structopt(short, long, default_value = "./CHANGELOG.md")]
changelog: PathBuf,
/// The version tag to operate on
tag: String,
tag: Option<String>,
#[structopt(flatten)]
release_meta: ReleaseMeta,
},

View File

@ -1,7 +1,7 @@
use anyhow::Result;
use std::{fs, path::PathBuf};
fn read_version(fname: PathBuf) -> Result<String> {
pub(crate) fn read_version(fname: PathBuf) -> Result<String> {
let version = fs::read_to_string(fname)?;
Ok(version.trim().into())
}