generated from PlexSheep/rs-base
release to forgejo works in an early state
cargo devel CI / cargo CI (push) Failing after 1m53s
Details
cargo devel CI / cargo CI (push) Failing after 1m53s
Details
This commit is contained in:
parent
0e4d694b35
commit
1bc34011c1
|
@ -1,5 +1,5 @@
|
||||||
version:
|
version:
|
||||||
!text "echo foo"
|
!cargo
|
||||||
changelog:
|
changelog:
|
||||||
enable: true
|
enable: true
|
||||||
git-log: true
|
git-log: true
|
||||||
|
@ -13,13 +13,13 @@ uses:
|
||||||
- cscherr
|
- cscherr
|
||||||
|
|
||||||
api:
|
api:
|
||||||
github:
|
# github:
|
||||||
type: github
|
# type: github
|
||||||
repository: autocrate
|
# repository: autocrate
|
||||||
auth:
|
# auth:
|
||||||
user: PlexSheep
|
# user: PlexSheep
|
||||||
pass:
|
# pass:
|
||||||
!env TOKEN_GH
|
# !env TOKEN_GH
|
||||||
cscherr:
|
cscherr:
|
||||||
type: forgejo
|
type: forgejo
|
||||||
endpoint: https://git.cscherr.de
|
endpoint: https://git.cscherr.de
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "autocrate"
|
name = "autocrate"
|
||||||
version = "0.1.0-prealpha.3"
|
version = "0.1.0-prealpha.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = true
|
publish = true
|
||||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||||
|
@ -25,11 +25,13 @@ async-trait = "0.1.77"
|
||||||
# cargo = "0.76.0"
|
# cargo = "0.76.0"
|
||||||
clap = { version = "4.4.18", features = ["derive", "help"] }
|
clap = { version = "4.4.18", features = ["derive", "help"] }
|
||||||
clap-verbosity-flag = "2.1.2"
|
clap-verbosity-flag = "2.1.2"
|
||||||
|
forgejo-api = "0.1.0"
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
git2 = "0.18.1"
|
git2 = "0.18.1"
|
||||||
libpt = { version = "0.3.11", features = ["log"] }
|
libpt = { version = "0.3.11", features = ["log"] }
|
||||||
reqwest = "0.11.24"
|
reqwest = "0.11.24"
|
||||||
serde = { version = "1.0.195", features = ["derive"] }
|
serde = { version = "1.0.195", features = ["derive"] }
|
||||||
|
serde_json = "1.0.116"
|
||||||
serde_yaml = "0.9.30"
|
serde_yaml = "0.9.30"
|
||||||
tempfile = "3.9.0"
|
tempfile = "3.9.0"
|
||||||
thiserror = "1.0.56"
|
thiserror = "1.0.56"
|
||||||
|
|
|
@ -17,6 +17,7 @@ impl Changelog {
|
||||||
Ok(Changelog { git_log })
|
Ok(Changelog { git_log })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: use libgit2 instead of the cli interface
|
||||||
fn make_git_log(cfg: &Config) -> Result<Option<String>> {
|
fn make_git_log(cfg: &Config) -> Result<Option<String>> {
|
||||||
if !cfg.yaml.changelog.enable {
|
if !cfg.yaml.changelog.enable {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
|
|
|
@ -194,7 +194,22 @@ impl Version {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Cargo => todo!(),
|
Self::Cargo => {
|
||||||
|
match Command::new("/bin/bash")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(r#"cat Cargo.toml | rg '^\s*version\s*=\s*"([^"]*)"\s*$' -or '$1'"#)
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
Ok(output) => {
|
||||||
|
// TODO: check status
|
||||||
|
String::from_utf8(output.stdout).unwrap().trim().to_owned()
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
panic!("{err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ pub enum ServerApiError {
|
||||||
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
|
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ReqwestErr(#[from] reqwest::Error),
|
ReqwestErr(#[from] reqwest::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
ForgejoApiError(#[from] forgejo_api::ForgejoError)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
|
|
@ -22,8 +22,8 @@ pub async fn tag(cfg: &Config) -> Result<git2::Tag> {
|
||||||
let tag = cfg
|
let tag = cfg
|
||||||
.repo
|
.repo
|
||||||
.tag(
|
.tag(
|
||||||
// &cfg.yaml.version.get_version(),
|
&cfg.yaml.version.get_version(),
|
||||||
"importantversion",
|
// "importantversion",
|
||||||
&target,
|
&target,
|
||||||
&tagger,
|
&tagger,
|
||||||
&message,
|
&message,
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub async fn release(cfg: &Config, apis: &mut ApiCollection) -> Result<()> {
|
||||||
.expect("no auth but trying to publish")
|
.expect("no auth but trying to publish")
|
||||||
.user,
|
.user,
|
||||||
repository: api.get_cfg().repository.clone(),
|
repository: api.get_cfg().repository.clone(),
|
||||||
text: String::from("TODO: ADD TEXT VARIABLE SOMEHOW"),
|
text: crate::changelog::Changelog::build(cfg)?.to_string(),
|
||||||
tag: tag.clone(),
|
tag: tag.clone(),
|
||||||
commit_sig: commit_sig.clone(),
|
commit_sig: commit_sig.clone(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,35 +6,29 @@ use crate::{
|
||||||
serverapi::{PublishContext, ReleaseContext, ServerApi},
|
serverapi::{PublishContext, ReleaseContext, ServerApi},
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use forgejo_api;
|
||||||
|
use libpt::log::debug;
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
header::{HeaderMap, HeaderValue},
|
header::{HeaderMap, HeaderValue},
|
||||||
Client, Url,
|
Client, Url,
|
||||||
};
|
};
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
pub struct Forgejo {
|
pub struct Forgejo {
|
||||||
cfg: Api,
|
cfg: Api,
|
||||||
client: Client,
|
api_wrapper: forgejo_api::Forgejo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Forgejo {
|
impl Forgejo {
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
pub async fn build(api: &Api) -> Result<Self> {
|
||||||
let mut headers: HeaderMap = HeaderMap::new();
|
let api_wrapper: forgejo_api::Forgejo = forgejo_api::Forgejo::new(
|
||||||
// may be left empty if we only do reads from publically accessible urls
|
forgejo_api::Auth::Token(&api.auth.clone().unwrap().pass.get_pass()?),
|
||||||
if api.auth.is_some() {
|
api.endpoint.clone().unwrap(),
|
||||||
let _ = headers.insert(
|
)
|
||||||
"Authorization",
|
|
||||||
// HeaderValue::from_str(api.auth.clone().unwrap().pass.get_pass()?.as_str())
|
|
||||||
// .map_err(ServerApiError::from)?,
|
|
||||||
HeaderValue::from_str("hardcoded").map_err(ServerApiError::from)?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let client = super::client_builder()
|
|
||||||
.default_headers(headers)
|
|
||||||
.build()
|
|
||||||
.map_err(ServerApiError::from)?;
|
.map_err(ServerApiError::from)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
cfg: api.clone(),
|
cfg: api.clone(),
|
||||||
client,
|
api_wrapper,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,38 +39,17 @@ impl ServerApi for Forgejo {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
|
async fn push_release(&mut self, rc: ReleaseContext) -> Result<()> {
|
||||||
let url: Url = match &self.cfg.endpoint {
|
let body: forgejo_api::structs::CreateReleaseOption =
|
||||||
Some(url) => url.clone(),
|
forgejo_api::structs::CreateReleaseOption {
|
||||||
None => self
|
body: Some(rc.text),
|
||||||
.cfg
|
draft: Some(rc.draft),
|
||||||
.server_type
|
name: Some(rc.tag.clone()),
|
||||||
.default_endpoint()
|
prerelease: Some(rc.prerelease),
|
||||||
.expect("no default endpoint for this api type"),
|
tag_name: rc.tag,
|
||||||
|
target_commitish: Some(rc.commit_sig),
|
||||||
};
|
};
|
||||||
url.join("/api/v1/repos/{}/{}/releases");
|
self.api_wrapper
|
||||||
let body = format!(
|
.repo_create_release(&rc.username, &rc.repository, body)
|
||||||
r#"
|
|
||||||
{{
|
|
||||||
"body": "{}",
|
|
||||||
"draft": {},
|
|
||||||
"name": "{}",
|
|
||||||
"prerelease": {},
|
|
||||||
"tag_name": "{}",
|
|
||||||
"target_commitish": "{}"
|
|
||||||
}}
|
|
||||||
"#,
|
|
||||||
rc.text, rc.draft, rc.tag, rc.prerelease, rc.tag, rc.commit_sig
|
|
||||||
);
|
|
||||||
|
|
||||||
let request = self
|
|
||||||
.client
|
|
||||||
.post(url)
|
|
||||||
.body(body)
|
|
||||||
.build()
|
|
||||||
.map_err(ServerApiError::from)?;
|
|
||||||
let _response = self
|
|
||||||
.client
|
|
||||||
.execute(request)
|
|
||||||
.await
|
.await
|
||||||
.map_err(ServerApiError::from)?;
|
.map_err(ServerApiError::from)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue