generated from PlexSheep/rs-base
Compare commits
No commits in common. "6f70057abae664b26f384426fada0d84b13a0923" and "499bcdd4c1ca2ff5d48f0910b6f9d358b89b25bb" have entirely different histories.
6f70057aba
...
499bcdd4c1
20 changed files with 70 additions and 447 deletions
|
@ -16,13 +16,11 @@ api:
|
||||||
type: github
|
type: github
|
||||||
endpoint: https://github.com
|
endpoint: https://github.com
|
||||||
auth:
|
auth:
|
||||||
user: PlexSheep
|
user: myUserName
|
||||||
pass:
|
pass: token_superimportantsecret
|
||||||
env: TOKEN_GH
|
myserv:
|
||||||
cscherr:
|
type: gitea
|
||||||
type: forgejo
|
|
||||||
endpoint: https://git.cscherr.de
|
endpoint: https://git.cscherr.de
|
||||||
auth:
|
auth:
|
||||||
user: PlexSheep
|
user: myUserName
|
||||||
pass:
|
pass: importantsecrettoken
|
||||||
env: TOKEN_CSCHERR
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ on:
|
||||||
# - '!master'
|
# - '!master'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
format:
|
CI:
|
||||||
name: cargo CI
|
name: cargo CI
|
||||||
permissions:
|
permissions:
|
||||||
# Give the default GITHUB_TOKEN write permission to commit and push the
|
# Give the default GITHUB_TOKEN write permission to commit and push the
|
||||||
|
@ -16,11 +16,9 @@ jobs:
|
||||||
- name: get repo
|
- name: get repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: install rust
|
- name: install rust
|
||||||
uses: https://github.com/dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
- name: install additional rust things
|
- name: install additional rust things
|
||||||
run: |
|
run: rustup component add rustfmt
|
||||||
rustup component add rustfmt
|
|
||||||
rustup component add clippy
|
|
||||||
- name: config custom registry
|
- name: config custom registry
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.cargo/
|
mkdir -p ~/.cargo/
|
||||||
|
@ -30,16 +28,16 @@ jobs:
|
||||||
echo '[registries.cscherr]' >> ~/.cargo/config.toml
|
echo '[registries.cscherr]' >> ~/.cargo/config.toml
|
||||||
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
|
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
|
||||||
cat ~/.cargo/config.toml
|
cat ~/.cargo/config.toml
|
||||||
- name: cargo clippy check
|
- name: cargo check
|
||||||
run: cargo clippy --all-features --all-targets
|
run: cargo check --all-features --all-targets
|
||||||
- name: cargo clippy fix
|
- name: cargo fix
|
||||||
run: cargo clippy --fix --all-features --all-targets
|
run: cargo fix --all-features --all-targets
|
||||||
- name: cargo fmt
|
- name: cargo fmt
|
||||||
run: cargo fmt --all
|
run: cargo fmt --all
|
||||||
- name: cargo test
|
- name: cargo test
|
||||||
run: cargo test --all-features --all-targets
|
run: cargo test --all-features --all-targets
|
||||||
- name: commit back to repository
|
- name: commit back to repository
|
||||||
uses: https://github.com/stefanzweifel/git-auto-commit-action@v5
|
uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
# Optional. Commit message for the created commit.
|
# Optional. Commit message for the created commit.
|
||||||
# Defaults to "Apply automatic changes"
|
# Defaults to "Apply automatic changes"
|
||||||
|
|
12
.github/workflows/cargo.yaml
vendored
12
.github/workflows/cargo.yaml
vendored
|
@ -19,9 +19,7 @@ jobs:
|
||||||
- name: install rust
|
- name: install rust
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
- name: install additional rust things
|
- name: install additional rust things
|
||||||
run: |
|
run: rustup component add rustfmt
|
||||||
rustup component add rustfmt
|
|
||||||
rustup component add clippy
|
|
||||||
- name: config custom registry
|
- name: config custom registry
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.cargo/
|
mkdir -p ~/.cargo/
|
||||||
|
@ -31,10 +29,10 @@ jobs:
|
||||||
echo '[registries.cscherr]' >> ~/.cargo/config.toml
|
echo '[registries.cscherr]' >> ~/.cargo/config.toml
|
||||||
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
|
echo 'index = "https://git.cscherr.de/PlexSheep/_cargo-index.git"' >> ~/.cargo/config.toml
|
||||||
cat ~/.cargo/config.toml
|
cat ~/.cargo/config.toml
|
||||||
- name: cargo clippy check
|
- name: cargo check
|
||||||
run: cargo clippy --all-features --all-targets
|
run: cargo check --all-features --all-targets
|
||||||
- name: cargo clippy fix
|
- name: cargo fix
|
||||||
run: cargo clippy --fix --all-features --all-targets
|
run: cargo fix --all-features --all-targets
|
||||||
- name: cargo fmt
|
- name: cargo fmt
|
||||||
run: cargo fmt --all
|
run: cargo fmt --all
|
||||||
- name: cargo test
|
- name: cargo test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "autocrate"
|
name = "autocrate"
|
||||||
version = "0.1.0-prealpha.2"
|
version = "0.1.0-prealpha.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = true
|
publish = true
|
||||||
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
authors = ["Christoph J. Scherr <software@cscherr.de>"]
|
||||||
|
@ -21,18 +21,15 @@ keywords = [
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.79"
|
anyhow = "1.0.79"
|
||||||
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"
|
||||||
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"
|
|
||||||
serde = { version = "1.0.195", features = ["derive"] }
|
serde = { version = "1.0.195", features = ["derive"] }
|
||||||
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"
|
||||||
tokio = { version = "1.36.0", features = ["tokio-macros", "rt-multi-thread", "macros"] }
|
|
||||||
url = { version = "2.5.0", features = ["serde"] }
|
url = { version = "2.5.0", features = ["serde"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
15
README.md
15
README.md
|
@ -66,7 +66,7 @@ Create a YAML file named `.autocrate.yml` (or `.yaml`) in the root of your Git
|
||||||
repository. It should contain the following parameters (replace the placeholders):
|
repository. It should contain the following parameters (replace the placeholders):
|
||||||
|
|
||||||
| Parent | Key | Value | Explanation |
|
| Parent | Key | Value | Explanation |
|
||||||
|----------------------|--------------|----------------------------------------------------------------------------------|------------------------------------------------------------------------------|
|
|-----------------|--------------|----------------------------------------------------------------------------------|------------------------------------------------------------------------------|
|
||||||
| (root) | `changelog` | list of keys with this as parent (`git-log` etc) | information on how a changelog is generated |
|
| (root) | `changelog` | list of keys with this as parent (`git-log` etc) | information on how a changelog is generated |
|
||||||
| `changelog` | `enable` | `true`/`false` | If false, no changelog will be generated |
|
| `changelog` | `enable` | `true`/`false` | If false, no changelog will be generated |
|
||||||
| `changelog` | `git-log` | `true`/`false` | should a changelog be generated with `git log`? |
|
| `changelog` | `git-log` | `true`/`false` | should a changelog be generated with `git log`? |
|
||||||
|
@ -79,10 +79,7 @@ repository. It should contain the following parameters (replace the placeholders
|
||||||
| `api.NAME` | `endpoint` | Base URL of the target server | Let's us know which api type we are talking to |
|
| `api.NAME` | `endpoint` | Base URL of the target server | Let's us know which api type we are talking to |
|
||||||
| `api.NAME` | `auth` | list of keys with this as parent (`user` and `pass`) | We probably need authentication on the target server |
|
| `api.NAME` | `auth` | list of keys with this as parent (`user` and `pass`) | We probably need authentication on the target server |
|
||||||
| `api.NAME.auth` | `user` | a string | Which user should we try to authenticate as |
|
| `api.NAME.auth` | `user` | a string | Which user should we try to authenticate as |
|
||||||
| `api.NAME.auth` | `pass` | contains either of `text`, `env` or `file` | sets the secret for authentication with this server |
|
| `api.NAME.auth` | `pass` | a string | A secret for authentication o the server, probably a token |
|
||||||
| `api.NAME.auth.pass` | `text` | a authentication pass as clear text | A secret for authentication of the server, probably a token |
|
|
||||||
| `api.NAME.auth.pass` | `env` | env var which contains the token | A secret for authentication of the server, probably a token |
|
|
||||||
| `api.NAME.auth.pass` | `file` | file var which contains the token | A secret for authentication of the server, probably a token |
|
|
||||||
|
|
||||||
An example `.autocrate.yaml` could look like this:
|
An example `.autocrate.yaml` could look like this:
|
||||||
|
|
||||||
|
@ -105,18 +102,16 @@ api:
|
||||||
endpoint: https://github.com
|
endpoint: https://github.com
|
||||||
auth:
|
auth:
|
||||||
user: PlexSheep
|
user: PlexSheep
|
||||||
pass:
|
pass: token_superimportantsecret
|
||||||
text: token_superimportantsecret
|
|
||||||
cscherr:
|
cscherr:
|
||||||
type: gitea
|
type: gitea
|
||||||
endpoint: https://git.cscherr.de
|
endpoint: https://git.cscherr.de
|
||||||
auth:
|
auth:
|
||||||
user: PlexSheep
|
user: PlexSheep
|
||||||
pass:
|
pass: Bearer importantsecrettoken
|
||||||
file: secrettoken.txt
|
|
||||||
```
|
```
|
||||||
|
|
||||||
After Autocrate has been bootstrapped, it will be released and published
|
After Autocrate has been bootstrapped, you it will be released and published
|
||||||
with itself, so you can take a look at this repositories
|
with itself, so you can take a look at this repositories
|
||||||
[`.autocrate.yaml`](./.autocrate.yaml).
|
[`.autocrate.yaml`](./.autocrate.yaml).
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ BODY="
|
||||||
$(git log $(git describe --tags --abbrev=0)..HEAD --pretty="- %s" --oneline --decorate)
|
$(git log $(git describe --tags --abbrev=0)..HEAD --pretty="- %s" --oneline --decorate)
|
||||||
"
|
"
|
||||||
USER=PlexSheep
|
USER=PlexSheep
|
||||||
git tag "v$NEW_VERSION" || echo "could not tag"
|
git tag "v$NEW_VERSION-test" || echo "could not tag"
|
||||||
curl -X 'POST' \
|
curl -X 'POST' \
|
||||||
'https://git.cscherr.de/api/v1/repos/PlexSheep/'$REPO'/releases' \
|
'https://git.cscherr.de/api/v1/repos/PlexSheep/'$REPO'/releases' \
|
||||||
-H 'accept: application/json' \
|
-H 'accept: application/json' \
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl Changelog {
|
||||||
let out = cmd.output()?;
|
let out = cmd.output()?;
|
||||||
// FIXME: this does not catch fancy colors, those are from the shell as it seems? I don't
|
// FIXME: this does not catch fancy colors, those are from the shell as it seems? I don't
|
||||||
// get it.
|
// get it.
|
||||||
let buf = String::from_utf8(out.stdout).map_err(ChangelogError::GitUTF8Error)?;
|
let buf = String::from_utf8(out.stdout).map_err(|err| ChangelogError::GitUTF8Error(err))?;
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
// TODO: get the stderr for error reporting
|
// TODO: get the stderr for error reporting
|
||||||
// TODO: Make the error more understandable for the user
|
// TODO: Make the error more understandable for the user
|
||||||
|
@ -43,14 +43,14 @@ impl Changelog {
|
||||||
let mut cmd = Command::new("git");
|
let mut cmd = Command::new("git");
|
||||||
cmd.arg("describe").arg("--tags").arg("--abbrev=0");
|
cmd.arg("describe").arg("--tags").arg("--abbrev=0");
|
||||||
let out = cmd.output()?;
|
let out = cmd.output()?;
|
||||||
let buf = String::from_utf8(out.stdout).map_err(ChangelogError::GitUTF8Error)?;
|
let buf = String::from_utf8(out.stdout).map_err(|err| ChangelogError::GitUTF8Error(err))?;
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
// TODO: get the stderr for error reporting
|
// TODO: get the stderr for error reporting
|
||||||
// TODO: Make the error more understandable for the user
|
// TODO: Make the error more understandable for the user
|
||||||
return Err(ChangelogError::GitBadStatus(out.status, buf).into());
|
return Err(ChangelogError::GitBadStatus(out.status, buf).into());
|
||||||
}
|
}
|
||||||
let buf = buf.replace('\n', "");
|
let buf = buf.replace("\n", "");
|
||||||
Ok(buf)
|
return Ok(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ pub struct Cli {
|
||||||
#[derive(Debug, Clone, Subcommand)]
|
#[derive(Debug, Clone, Subcommand)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
Changelog {},
|
Changelog {},
|
||||||
/// Create a new release on the server
|
|
||||||
Release {
|
Release {
|
||||||
// FIXME: allow taking a message like this:
|
// FIXME: allow taking a message like this:
|
||||||
// `autocrate changelog -m arg1 arg2 arg3`
|
// `autocrate changelog -m arg1 arg2 arg3`
|
||||||
|
@ -53,29 +52,14 @@ pub enum Commands {
|
||||||
//
|
//
|
||||||
// TODO:
|
// TODO:
|
||||||
// find a way to make this a global option but only usable with specific subcommands
|
// find a way to make this a global option but only usable with specific subcommands
|
||||||
//
|
|
||||||
// TODO:
|
|
||||||
// integrate a CHANGELOG.md file
|
|
||||||
//
|
|
||||||
/// Message body of the release
|
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
message: Option<Vec<String>>,
|
message: Option<Vec<String>>,
|
||||||
|
|
||||||
/// generate and add a changelog
|
|
||||||
changelog: bool,
|
|
||||||
|
|
||||||
/// publish after releasing
|
|
||||||
publish: bool,
|
|
||||||
},
|
},
|
||||||
/// Publish to a package registry
|
|
||||||
Publish {
|
Publish {
|
||||||
// see Commands::Release { message }
|
// see Commands::Release { message }
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
message: Option<Vec<String>>,
|
message: Option<Vec<String>>,
|
||||||
},
|
},
|
||||||
///
|
|
||||||
Version {},
|
|
||||||
Init {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Commands {
|
impl Display for Commands {
|
||||||
|
@ -87,8 +71,6 @@ impl Display for Commands {
|
||||||
Self::Changelog { .. } => "Changelog",
|
Self::Changelog { .. } => "Changelog",
|
||||||
Self::Release { .. } => "Release",
|
Self::Release { .. } => "Release",
|
||||||
Self::Publish { .. } => "Publish",
|
Self::Publish { .. } => "Publish",
|
||||||
Self::Version { .. } => "Version",
|
|
||||||
Self::Init { .. } => "Init",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -113,6 +95,6 @@ impl Cli {
|
||||||
// less verbose version
|
// less verbose version
|
||||||
Logger::init_mini(Some(ll)).expect("could not initialize Logger");
|
Logger::init_mini(Some(ll)).expect("could not initialize Logger");
|
||||||
}
|
}
|
||||||
cli
|
return cli;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use url::Url;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod packages;
|
|
||||||
use cli::Cli;
|
use cli::Cli;
|
||||||
|
|
||||||
pub trait YamlConfigSection: Debug + Clone + for<'a> Deserialize<'a> {
|
pub trait YamlConfigSection: Debug + Clone + for<'a> Deserialize<'a> {
|
||||||
|
@ -49,60 +48,32 @@ impl YamlConfigSection for Uses {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub enum Pass {
|
|
||||||
/// pass specified as plainext
|
|
||||||
Text(String),
|
|
||||||
/// pass to be loaded from an env var
|
|
||||||
Env(String),
|
|
||||||
/// pass to be loaded from a file
|
|
||||||
File(PathBuf),
|
|
||||||
}
|
|
||||||
impl Pass {
|
|
||||||
/// Get the pass, extracting from the underlying source
|
|
||||||
pub fn get_pass(&self) -> Result<String> {
|
|
||||||
self.check()?;
|
|
||||||
Ok(match self {
|
|
||||||
Self::Text(pass) => pass.clone(),
|
|
||||||
Self::Env(key) => std::env::var(key).map_err(ConfigError::from)?,
|
|
||||||
Self::File(file) => std::fs::read_to_string(file)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl YamlConfigSection for Pass {
|
|
||||||
fn check(&self) -> Result<()> {
|
|
||||||
match self {
|
|
||||||
Self::Text(_) => (),
|
|
||||||
Self::Env(envvar) => {
|
|
||||||
if !std::env::var(envvar).map_err(ConfigError::from)?.is_empty() {
|
|
||||||
} else {
|
|
||||||
return Err(ConfigError::EnvNotSet(envvar.clone()).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Self::File(file) => {
|
|
||||||
if !file.exists() {
|
|
||||||
return Err(ConfigError::PassFileDoesNotExist(file.clone()).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct ApiAuth {
|
pub struct ApiAuth {
|
||||||
pub user: String,
|
pub user: String,
|
||||||
pub pass: Pass,
|
pub pass: Option<String>,
|
||||||
|
pub pass_file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
impl YamlConfigSection for ApiAuth {
|
impl YamlConfigSection for ApiAuth {
|
||||||
fn check(&self) -> Result<()> {
|
fn check(&self) -> Result<()> {
|
||||||
self.pass.check()?;
|
if self.pass.is_some() && self.pass_file.is_some() {
|
||||||
|
let err = ConfigError::YamlApiAuthBothPass(self.clone()).into();
|
||||||
|
error!("{err}");
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
if self.pass_file.is_some() {
|
||||||
|
let file = self.pass_file.clone().unwrap();
|
||||||
|
if !file.exists() {
|
||||||
|
return Err(ConfigError::PassFileDoesNotExist(file).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct Api {
|
pub struct Api {
|
||||||
pub server_type: ApiType,
|
pub r#type: ApiType,
|
||||||
pub endpoint: Url,
|
pub endpoint: Url,
|
||||||
/// May be left empty if the Api does not need auth or the auth is part of the
|
/// May be left empty if the Api does not need auth or the auth is part of the
|
||||||
/// [endpoint](Api::endpoint) [Url].
|
/// [endpoint](Api::endpoint) [Url].
|
||||||
|
@ -110,7 +81,7 @@ pub struct Api {
|
||||||
}
|
}
|
||||||
impl YamlConfigSection for Api {
|
impl YamlConfigSection for Api {
|
||||||
fn check(&self) -> Result<()> {
|
fn check(&self) -> Result<()> {
|
||||||
self.server_type.check()?;
|
self.r#type.check()?;
|
||||||
match self.endpoint.socket_addrs(|| None) {
|
match self.endpoint.socket_addrs(|| None) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
|
@ -130,8 +101,6 @@ pub enum ApiType {
|
||||||
Gitlab,
|
Gitlab,
|
||||||
#[serde(alias = "github", alias = "GitHub")]
|
#[serde(alias = "github", alias = "GitHub")]
|
||||||
Github,
|
Github,
|
||||||
#[serde(alias = "forgejo")]
|
|
||||||
Forgejo,
|
|
||||||
}
|
}
|
||||||
impl YamlConfigSection for ApiType {
|
impl YamlConfigSection for ApiType {
|
||||||
fn check(&self) -> Result<()> {
|
fn check(&self) -> Result<()> {
|
||||||
|
@ -178,7 +147,7 @@ impl Debug for Config {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}",
|
"{}",
|
||||||
format_args!(
|
format!(
|
||||||
"Config {{yaml: {:?}, repo_path: {:?}}}",
|
"Config {{yaml: {:?}, repo_path: {:?}}}",
|
||||||
self.yaml, self.path
|
self.yaml, self.path
|
||||||
)
|
)
|
||||||
|
@ -187,7 +156,7 @@ impl Debug for Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load(cli: &Cli) -> Result<Self> {
|
pub fn load(cli: Cli) -> Result<Self> {
|
||||||
let repo = match git2::Repository::open_from_env() {
|
let repo = match git2::Repository::open_from_env() {
|
||||||
Ok(repo) => repo,
|
Ok(repo) => repo,
|
||||||
Err(_err) => {
|
Err(_err) => {
|
||||||
|
@ -228,7 +197,7 @@ impl Config {
|
||||||
yaml,
|
yaml,
|
||||||
repo,
|
repo,
|
||||||
path,
|
path,
|
||||||
cli: cli.clone(),
|
cli,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
pub enum PackageType {
|
|
||||||
Cargo,
|
|
||||||
}
|
|
18
src/error.rs
18
src/error.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::{env::VarError, path::PathBuf, process::ExitStatus, string::FromUtf8Error};
|
use std::{path::PathBuf, process::ExitStatus, string::FromUtf8Error};
|
||||||
|
|
||||||
use anyhow;
|
use anyhow;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -20,18 +20,6 @@ pub enum Error {
|
||||||
SerdeYaml(#[from] serde_yaml::Error),
|
SerdeYaml(#[from] serde_yaml::Error),
|
||||||
#[error("Could not generate the changelog")]
|
#[error("Could not generate the changelog")]
|
||||||
ChangelogError(#[from] ChangelogError),
|
ChangelogError(#[from] ChangelogError),
|
||||||
#[error("Server Api error")]
|
|
||||||
ServerApiError(#[from] ServerApiError),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum ServerApiError {
|
|
||||||
#[error(transparent)]
|
|
||||||
ParseUrl(#[from] url::ParseError),
|
|
||||||
#[error(transparent)]
|
|
||||||
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
|
|
||||||
#[error(transparent)]
|
|
||||||
ReqwestErr(#[from] reqwest::Error),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
@ -57,8 +45,4 @@ pub enum ConfigError {
|
||||||
YamlApiAuthBothPass(ApiAuth),
|
YamlApiAuthBothPass(ApiAuth),
|
||||||
#[error("password provided as file, but does not exist: {0}")]
|
#[error("password provided as file, but does not exist: {0}")]
|
||||||
PassFileDoesNotExist(PathBuf),
|
PassFileDoesNotExist(PathBuf),
|
||||||
#[error("config requires environment variable {0}, but {0} is not set")]
|
|
||||||
EnvNotSet(String),
|
|
||||||
#[error("Bad value for environment variable: {0}")]
|
|
||||||
BadEnv(#[from] VarError),
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
pub mod changelog;
|
pub mod changelog;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod publish;
|
|
||||||
pub mod release;
|
|
||||||
pub mod serverapi;
|
|
||||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -5,37 +5,22 @@ use autocrate::{
|
||||||
Config,
|
Config,
|
||||||
},
|
},
|
||||||
error::*,
|
error::*,
|
||||||
publish::publish,
|
|
||||||
release::release,
|
|
||||||
serverapi::init_servers,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
fn main() -> Result<()> {
|
||||||
async fn main() -> Result<()> {
|
|
||||||
let cli = Cli::cli_parse();
|
let cli = Cli::cli_parse();
|
||||||
let cfg = Config::load(&cli)?;
|
let cfg = Config::load(cli.clone())?;
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::Changelog { .. } => {
|
Commands::Changelog { .. } => {
|
||||||
println!("{}", Changelog::build(&cfg)?);
|
println!("{}", Changelog::build(&cfg)?.to_string());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Commands::Release { .. } => {
|
Commands::Release { .. } => {
|
||||||
let mut apis = init_servers(&cfg).await?;
|
todo!()
|
||||||
release(&cfg, &mut apis).await?;
|
|
||||||
}
|
}
|
||||||
Commands::Publish { .. } => {
|
Commands::Publish { .. } => {
|
||||||
publish(&cfg).await?;
|
|
||||||
}
|
|
||||||
Commands::Version {} => {
|
|
||||||
// TODO: version bump
|
|
||||||
// TODO: version select interactive
|
|
||||||
// TODO: version select automated
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
Commands::Init { .. } => {
|
|
||||||
// TODO: create a basic autocrate yaml
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
use crate::{config::Config, error::*};
|
|
||||||
|
|
||||||
pub struct PublishContext;
|
|
||||||
|
|
||||||
pub async fn publish(_cfg: &Config) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
use crate::{config::Config, error::*, serverapi::ApiCollection};
|
|
||||||
|
|
||||||
pub struct ReleaseContext {
|
|
||||||
pub draft: bool,
|
|
||||||
pub prerelease: bool,
|
|
||||||
pub username: String,
|
|
||||||
pub repository: String,
|
|
||||||
pub text: String,
|
|
||||||
pub tag: String,
|
|
||||||
pub commit_sig: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn release(cfg: &Config, _apis: &mut ApiCollection) -> Result<()> {
|
|
||||||
// TODO: git tag
|
|
||||||
// TODO: push to each server
|
|
||||||
|
|
||||||
// TODO: release to each server
|
|
||||||
tag(cfg).await?;
|
|
||||||
todo!();
|
|
||||||
|
|
||||||
// TODO: check that the release is made
|
|
||||||
// TODO: generate artifacts
|
|
||||||
// TODO: upload artifacts
|
|
||||||
// TODO: upload artifact signatures
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn tag(_cfg: &Config) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
use crate::{
|
|
||||||
config::{Api, Config},
|
|
||||||
error::*,
|
|
||||||
serverapi::{PublishContext, ReleaseContext, ServerApi},
|
|
||||||
};
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use reqwest::{
|
|
||||||
header::{HeaderMap, HeaderValue},
|
|
||||||
Client, Url,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Forgejo {
|
|
||||||
cfg: Api,
|
|
||||||
client: Client,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Forgejo {
|
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
|
||||||
let mut headers: HeaderMap = HeaderMap::new();
|
|
||||||
// may be left empty if we only do reads from publically accessible urls
|
|
||||||
if api.auth.is_some() {
|
|
||||||
let _ = headers.insert(
|
|
||||||
"Authorization",
|
|
||||||
HeaderValue::from_str(api.auth.clone().unwrap().pass.get_pass()?.as_str())
|
|
||||||
.map_err(ServerApiError::from)?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let client = super::client_builder()
|
|
||||||
.default_headers(headers)
|
|
||||||
.build()
|
|
||||||
.map_err(ServerApiError::from)?;
|
|
||||||
Ok(Self {
|
|
||||||
cfg: api.clone(),
|
|
||||||
client,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ServerApi for Forgejo {
|
|
||||||
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release(&mut self, rc: &ReleaseContext) -> Result<()> {
|
|
||||||
let raw_url = format!(
|
|
||||||
"{}/api/v1/repos/{}/{}/releases",
|
|
||||||
self.cfg.endpoint, rc.username, rc.repository
|
|
||||||
);
|
|
||||||
let url = Url::parse(&raw_url).map_err(ServerApiError::from)?;
|
|
||||||
let body = format!(
|
|
||||||
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
|
|
||||||
.map_err(ServerApiError::from)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn push_release_artifact(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_pkg(&mut self, _pc: &PublishContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
use async_trait::async_trait;
|
|
||||||
|
|
||||||
use super::{PublishContext, ReleaseContext, ServerApi};
|
|
||||||
use crate::{
|
|
||||||
config::{Api, Config},
|
|
||||||
error::*,
|
|
||||||
};
|
|
||||||
pub struct Gitea {
|
|
||||||
cfg: Api,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ServerApi for Gitea {
|
|
||||||
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release_artifact(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_pkg(&mut self, _pc: &PublishContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Gitea {
|
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
|
||||||
Ok(Self { cfg: api.clone() })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
use async_trait::async_trait;
|
|
||||||
|
|
||||||
use super::{PublishContext, ReleaseContext, ServerApi};
|
|
||||||
use crate::{
|
|
||||||
config::{Api, Config},
|
|
||||||
error::*,
|
|
||||||
};
|
|
||||||
pub struct Github {
|
|
||||||
cfg: Api,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ServerApi for Github {
|
|
||||||
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release_artifact(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_pkg(&mut self, _pc: &PublishContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Github {
|
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
|
||||||
Ok(Self { cfg: api.clone() })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
use async_trait::async_trait;
|
|
||||||
|
|
||||||
use super::{PublishContext, ReleaseContext, ServerApi};
|
|
||||||
use crate::{
|
|
||||||
config::{Api, Config},
|
|
||||||
error::*,
|
|
||||||
};
|
|
||||||
pub struct Gitlab {
|
|
||||||
cfg: Api,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ServerApi for Gitlab {
|
|
||||||
async fn init(&mut self, _cfg: &Config) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_release_artifact(&mut self, _rc: &ReleaseContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
async fn push_pkg(&mut self, _pc: &PublishContext) -> Result<()> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Gitlab {
|
|
||||||
pub async fn build(api: &Api) -> Result<Self> {
|
|
||||||
Ok(Self { cfg: api.clone() })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
use async_trait::async_trait;
|
|
||||||
use reqwest::ClientBuilder;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
config::{ApiType, Config},
|
|
||||||
error::*,
|
|
||||||
publish::PublishContext,
|
|
||||||
release::ReleaseContext,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub mod forgejo;
|
|
||||||
pub mod gitea;
|
|
||||||
pub mod github;
|
|
||||||
pub mod gitlab;
|
|
||||||
use forgejo::*;
|
|
||||||
use gitea::*;
|
|
||||||
use github::*;
|
|
||||||
use gitlab::*;
|
|
||||||
|
|
||||||
pub static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
|
|
||||||
pub type ApiCollection = Vec<Box<dyn ServerApi>>;
|
|
||||||
|
|
||||||
// NOTE: in stable rust, traits can normally not contain async methods,
|
|
||||||
// see [here](https://stackoverflow.com/questions/65921581/how-can-i-define-an-async-method-in-a-trait).
|
|
||||||
// The `async_trait` crate can be used to work around this limitation.
|
|
||||||
#[async_trait]
|
|
||||||
pub trait ServerApi {
|
|
||||||
async fn init(&mut self, cfg: &Config) -> Result<()>;
|
|
||||||
async fn push_release(&mut self, rc: &ReleaseContext) -> Result<()>;
|
|
||||||
async fn push_release_artifact(&mut self, rc: &ReleaseContext) -> Result<()>;
|
|
||||||
async fn push_pkg(&mut self, pc: &PublishContext) -> Result<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn client_builder() -> ClientBuilder {
|
|
||||||
ClientBuilder::new().user_agent(USER_AGENT)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn init_servers(cfg: &Config) -> Result<ApiCollection> {
|
|
||||||
let mut collection: ApiCollection = ApiCollection::new();
|
|
||||||
for api in &cfg.yaml.api {
|
|
||||||
match api.1.server_type {
|
|
||||||
ApiType::Gitea => {
|
|
||||||
collection.push(Box::new(Gitea::build(api.1).await?));
|
|
||||||
}
|
|
||||||
ApiType::Gitlab => {
|
|
||||||
collection.push(Box::new(Gitlab::build(api.1).await?));
|
|
||||||
}
|
|
||||||
ApiType::Github => {
|
|
||||||
collection.push(Box::new(Github::build(api.1).await?));
|
|
||||||
}
|
|
||||||
ApiType::Forgejo => {
|
|
||||||
collection.push(Box::new(Forgejo::build(api.1).await?));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for api in collection.iter_mut() {
|
|
||||||
api.init(cfg).await?;
|
|
||||||
}
|
|
||||||
Ok(collection)
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue