pare-down-functionality #7
|
@ -86,12 +86,6 @@ version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
|
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byte-unit"
|
|
||||||
version = "3.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "55390dbbf21ce70683f3e926dace00a21da373e35e44a60cafd232e3e9bf2041"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.3.4"
|
version = "1.3.4"
|
||||||
|
@ -134,16 +128,6 @@ dependencies = [
|
||||||
"vec_map",
|
"vec_map",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cli-table"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bd782cbfda62468ed8f94f2c00496ff909ad4916f4411ab9ec7bdced5414a699"
|
|
||||||
dependencies = [
|
|
||||||
"termcolor",
|
|
||||||
"unicode-width",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "comrak"
|
name = "comrak"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -324,15 +308,24 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gitea"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gitea-release"
|
name = "gitea-release"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"byte-unit",
|
|
||||||
"cli-table",
|
|
||||||
"comrak",
|
"comrak",
|
||||||
"git2",
|
"git2",
|
||||||
|
"gitea",
|
||||||
"http",
|
"http",
|
||||||
"kankyo",
|
"kankyo",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -1138,15 +1131,6 @@ dependencies = [
|
||||||
"winapi 0.3.8",
|
"winapi 0.3.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termcolor"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
@ -1156,6 +1140,26 @@ dependencies = [
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thread_local"
|
name = "thread_local"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -1476,15 +1480,6 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-util"
|
|
||||||
version = "0.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.3.8",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
|
|
@ -8,8 +8,6 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
byte-unit = "3"
|
|
||||||
cli-table = "0.3"
|
|
||||||
comrak = "0.7"
|
comrak = "0.7"
|
||||||
git2 = "0.13"
|
git2 = "0.13"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
|
@ -21,8 +19,15 @@ structopt = { version = "0.3", default-features = false }
|
||||||
tokio = { version = "0.2", features = ["macros"] }
|
tokio = { version = "0.2", features = ["macros"] }
|
||||||
url = "2"
|
url = "2"
|
||||||
|
|
||||||
|
gitea = { path = "./gitea" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"./gitea"
|
||||||
|
]
|
||||||
|
|
|
@ -30,7 +30,8 @@ To use this as a drone plugin, add the following to your `.drone.yml` under the
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: auto-release
|
- name: auto-release
|
||||||
image: xena/gitea-release:0.3.2
|
image: xena/gitea-release:latest
|
||||||
|
pull: always
|
||||||
settings:
|
settings:
|
||||||
auth_username: cadey
|
auth_username: cadey
|
||||||
changelog_path: ./CHANGELOG.md
|
changelog_path: ./CHANGELOG.md
|
||||||
|
@ -53,7 +54,8 @@ setting like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: auto-release
|
- name: auto-release
|
||||||
image: xena/gitea-release:0.3.2
|
image: xena/gitea-release:latest
|
||||||
|
pull: always
|
||||||
settings:
|
settings:
|
||||||
auth_username: cadey
|
auth_username: cadey
|
||||||
default_branch: trunk
|
default_branch: trunk
|
||||||
|
|
|
@ -8,7 +8,7 @@ let
|
||||||
dockerImage = pkg:
|
dockerImage = pkg:
|
||||||
pkgs.dockerTools.buildLayeredImage {
|
pkgs.dockerTools.buildLayeredImage {
|
||||||
name = "xena/gitea-release";
|
name = "xena/gitea-release";
|
||||||
tag = "${gitea-release.version}";
|
tag = "latest";
|
||||||
|
|
||||||
contents = [ pkgs.cacert pkg ];
|
contents = [ pkgs.cacert pkg ];
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,17 @@ use url::Url;
|
||||||
pub(crate) async fn run(env: DroneEnv) -> Result<()> {
|
pub(crate) async fn run(env: DroneEnv) -> Result<()> {
|
||||||
let common: Common = env.clone().into();
|
let common: Common = env.clone().into();
|
||||||
|
|
||||||
let default_branch = match &env.default_branch {
|
let default_branch = {
|
||||||
None => {
|
let common = common.clone();
|
||||||
let cli = crate::client(&common)?;
|
match &env.default_branch {
|
||||||
let repo =
|
None => {
|
||||||
crate::gitea::get_repo(&cli, &common.server, &common.owner, &common.repo).await?;
|
let cli =
|
||||||
repo.default_branch
|
gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT.into())?;
|
||||||
|
let repo = cli.get_repo(common.owner, common.repo).await?;
|
||||||
|
repo.default_branch
|
||||||
|
}
|
||||||
|
Some(branch) => branch.to_string(),
|
||||||
}
|
}
|
||||||
Some(branch) => branch.to_string(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if env.branch != default_branch {
|
if env.branch != default_branch {
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
pub(crate) mod delete;
|
|
||||||
pub(crate) mod download;
|
|
||||||
pub(crate) mod drone_plugin;
|
pub(crate) mod drone_plugin;
|
||||||
pub(crate) mod edit;
|
|
||||||
pub(crate) mod info;
|
|
||||||
pub(crate) mod release;
|
pub(crate) mod release;
|
||||||
pub(crate) mod upload;
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug, Clone)]
|
#[derive(StructOpt, Debug, Clone)]
|
||||||
pub(crate) struct Common {
|
pub(crate) struct Common {
|
||||||
|
@ -90,51 +85,11 @@ pub(crate) struct ReleaseMeta {
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(about = "Gitea release assistant")]
|
#[structopt(about = "Gitea release assistant")]
|
||||||
pub(crate) enum Cmd {
|
pub(crate) enum Cmd {
|
||||||
/// Delete a given release from Gitea
|
|
||||||
Delete {
|
|
||||||
#[structopt(flatten)]
|
|
||||||
common: Common,
|
|
||||||
/// The version tag to operate on
|
|
||||||
#[structopt(short, long)]
|
|
||||||
tag: String,
|
|
||||||
},
|
|
||||||
/// Downloads release artifacts
|
|
||||||
Download {
|
|
||||||
#[structopt(flatten)]
|
|
||||||
common: Common,
|
|
||||||
/// File to download
|
|
||||||
fname: Option<PathBuf>,
|
|
||||||
/// The version tag to operate on
|
|
||||||
#[structopt(short, long)]
|
|
||||||
tag: String,
|
|
||||||
},
|
|
||||||
/// Runs the release process as a drone plugin
|
/// Runs the release process as a drone plugin
|
||||||
DronePlugin {
|
DronePlugin {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
env: DroneEnv,
|
env: DroneEnv,
|
||||||
},
|
},
|
||||||
/// Edits a release's description, name and other flags
|
|
||||||
Edit {
|
|
||||||
#[structopt(flatten)]
|
|
||||||
common: Common,
|
|
||||||
/// Release description
|
|
||||||
#[structopt(short, long)]
|
|
||||||
description: Option<String>,
|
|
||||||
#[structopt(flatten)]
|
|
||||||
release_meta: ReleaseMeta,
|
|
||||||
/// The version tag to operate on
|
|
||||||
tag: String,
|
|
||||||
},
|
|
||||||
/// Gets release info
|
|
||||||
Info {
|
|
||||||
#[structopt(flatten)]
|
|
||||||
common: Common,
|
|
||||||
#[structopt(long, short)]
|
|
||||||
json: bool,
|
|
||||||
/// The version tag to operate on
|
|
||||||
#[structopt(short, long)]
|
|
||||||
tag: Option<String>,
|
|
||||||
},
|
|
||||||
/// Create a new tag and release on Gitea
|
/// Create a new tag and release on Gitea
|
||||||
Release {
|
Release {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
|
@ -147,14 +102,4 @@ pub(crate) enum Cmd {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
release_meta: ReleaseMeta,
|
release_meta: ReleaseMeta,
|
||||||
},
|
},
|
||||||
/// Uploads release artifacts to Gitea
|
|
||||||
Upload {
|
|
||||||
#[structopt(flatten)]
|
|
||||||
common: Common,
|
|
||||||
/// The version tag to operate on
|
|
||||||
#[structopt(short, long)]
|
|
||||||
tag: String,
|
|
||||||
/// The location of the file on the disk
|
|
||||||
fname: PathBuf,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{gitea::*, *};
|
use crate::{changelog, cmd::*, git, version};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -22,8 +22,10 @@ pub(crate) async fn run(
|
||||||
}
|
}
|
||||||
|
|
||||||
let desc = changelog::read(fname, tag.clone())?;
|
let desc = changelog::read(fname, tag.clone())?;
|
||||||
let cli = client(&common)?;
|
|
||||||
let cr = CreateRelease {
|
let cli = gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT.into())?;
|
||||||
|
|
||||||
|
let cr = gitea::CreateRelease {
|
||||||
body: desc,
|
body: desc,
|
||||||
draft: rm.draft,
|
draft: rm.draft,
|
||||||
name: rm.name.or(Some(format!("Version {}", tag))).unwrap(),
|
name: rm.name.or(Some(format!("Version {}", tag))).unwrap(),
|
||||||
|
@ -32,18 +34,7 @@ pub(crate) async fn run(
|
||||||
target_commitish: "HEAD".into(),
|
target_commitish: "HEAD".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = cli
|
let _ = cli.create_release(common.owner, common.repo, cr).await?;
|
||||||
.post(&format!(
|
|
||||||
"{}/api/v1/repos/{}/{}/releases",
|
|
||||||
common.server, common.owner, common.repo
|
|
||||||
))
|
|
||||||
.json(&cr)
|
|
||||||
.send()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if !resp.status().is_success() {
|
|
||||||
return Err(anyhow!("{:?} -> {}", resp.status(), resp.text().await?));
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Created release {}", tag);
|
println!("Created release {}", tag);
|
||||||
|
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -1,29 +1,16 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::Result;
|
||||||
use reqwest::{header, Client};
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
mod changelog;
|
mod changelog;
|
||||||
mod cmd;
|
mod cmd;
|
||||||
mod git;
|
mod git;
|
||||||
mod gitea;
|
|
||||||
mod version;
|
mod version;
|
||||||
|
|
||||||
pub(crate) use cmd::*;
|
pub(crate) use cmd::*;
|
||||||
|
|
||||||
// Name your user agent after your app?
|
// Name your user agent after your app?
|
||||||
static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
pub(crate) static APP_USER_AGENT: &str =
|
||||||
|
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
pub(crate) fn client(c: &cmd::Common) -> Result<Client> {
|
|
||||||
let mut headers = header::HeaderMap::new();
|
|
||||||
let auth = format!("token {}", &c.token);
|
|
||||||
let auth = auth.as_str();
|
|
||||||
headers.insert(header::AUTHORIZATION, header::HeaderValue::from_str(auth)?);
|
|
||||||
Ok(Client::builder()
|
|
||||||
.user_agent(APP_USER_AGENT)
|
|
||||||
.default_headers(headers)
|
|
||||||
.build()?)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
@ -31,22 +18,12 @@ async fn main() -> Result<()> {
|
||||||
let cmd = cmd::Cmd::from_args();
|
let cmd = cmd::Cmd::from_args();
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
Cmd::Delete { common, tag } => cmd::delete::run(common, tag).await,
|
|
||||||
Cmd::Download { common, fname, tag } => cmd::download::run(common, fname, tag).await,
|
|
||||||
Cmd::DronePlugin { env } => cmd::drone_plugin::run(env).await,
|
Cmd::DronePlugin { env } => cmd::drone_plugin::run(env).await,
|
||||||
Cmd::Edit {
|
|
||||||
common,
|
|
||||||
description,
|
|
||||||
release_meta,
|
|
||||||
tag,
|
|
||||||
} => cmd::edit::run(common, description, release_meta, tag).await,
|
|
||||||
Cmd::Info { common, json, tag } => cmd::info::run(common, json, tag).await,
|
|
||||||
Cmd::Release {
|
Cmd::Release {
|
||||||
common,
|
common,
|
||||||
changelog,
|
changelog,
|
||||||
tag,
|
tag,
|
||||||
release_meta,
|
release_meta,
|
||||||
} => cmd::release::run(common, changelog, tag, release_meta).await,
|
} => cmd::release::run(common, changelog, tag, release_meta).await,
|
||||||
Cmd::Upload { common, fname, tag } => cmd::upload::run(common, fname, tag).await,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue