Compare commits

...

10 Commits
v0.4.0 ... main

Author SHA1 Message Date
545e8c5476 chore(deps): update rust crate serde to v1.0.214
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-10-29 01:27:46 +00:00
42f23fdfac chore(deps): update rust crate serde to v1.0.213
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-10-23 00:28:22 +00:00
249a40f1aa chore(deps): update rust crate serde to v1.0.210
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2024-10-17 00:26:58 +00:00
c1187022f2
feat: removed tests for now
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-10-16 21:40:02 +02:00
0fc1438a4a
feat: update deps
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-10-16 21:30:38 +02:00
166be0c289
feat: update
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-04-10 15:48:57 +02:00
cuddle-please
ff9f5e25d2
chore(release): 0.5.0
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore: stuff

feat: something

Signed-off-by: kjuulh <contact@kjuulh.io>
2024-04-10 15:47:28 +02:00
9ac744b39d
feat: stuff
All checks were successful
continuous-integration/drone/push Build is passing
2024-04-09 23:31:19 +02:00
9c967a0f31
feat: with rust version
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-04-09 23:10:12 +02:00
3878e6bc0a
feat: add rust actions
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-04-09 22:57:01 +02:00
14 changed files with 859 additions and 298 deletions

View File

@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.5.0] - 2024-04-09
### Added
- stuff
- with rust version
- add rust actions
## [0.4.0] - 2024-04-08
### Added

712
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,6 @@
[workspace]
members = [
"crates/cuddle-please",
"crates/cuddle-please-frontend",
"crates/cuddle-please-commands",
"crates/cuddle-please-misc",
"crates/cuddle-please-release-strategy"
"crates/*"
]
resolver = "2"
@ -14,6 +10,7 @@ cuddle-please-frontend = { path = "crates/cuddle-please-frontend", version = "0.
cuddle-please-commands = { path = "crates/cuddle-please-commands", version = "0.1.0" }
cuddle-please-misc = { path = "crates/cuddle-please-misc", version = "0.1.0" }
cuddle-please-release-strategy = { path = "crates/cuddle-please-release-strategy", version = "0.1.0" }
cuddle-please-actions = { path = "crates/cuddle-please-actions", version = "0.1.0" }
anyhow = { version = "1.0.81" }
tracing = { version = "0.1", features = ["log"] }
@ -22,6 +19,7 @@ clap = { version = "4.5.4", features = ["derive", "env"] }
dotenv = { version = "0.15.0" }
url = { version = "2.5.0" }
serde_yaml = { version = "0.9.34+deprecated" }
yaml-rust2 = {version = "0.8.0"}
serde = { version = "1", features = ["derive"] }
semver = "1.0.22"
conventional_commit_parser = "0.9.4"
@ -32,6 +30,10 @@ regex = "1.10.4"
chrono = "0.4.37"
lazy_static = "1.4.0"
parse-changelog = "0.6.6"
toml_edit = "0.22.9"
tracing-test = "0.2"
pretty_assertions = "1.4"
[workspace.package]
version = "0.5.0"

View File

@ -0,0 +1,19 @@
[package]
name = "cuddle-please-actions"
description = "A release-please inspired release manager tool, built on top of cuddle, but also useful standalone, cuddle-please supports, your ci of choice, as well as gitea, github"
repository = "https://git.front.kjuulh.io/kjuulh/cuddle-please"
readme = "../../README.md"
license-file = "../../LICENSE"
version = "0.1.0"
edition = "2021"
publishable = true
[dependencies]
anyhow.workspace = true
tracing.workspace = true
semver.workspace = true
toml_edit.workspace = true
yaml-rust2.workspace = true
[dev-dependencies]
pretty_assertions.workspace = true

View File

@ -0,0 +1,9 @@
use semver::Version;
use crate::ActionConfig;
pub trait Action {
fn enabled(&self, config: &ActionConfig) -> anyhow::Result<bool>;
fn name(&self) -> String;
fn execute(&self, version: &Version) -> anyhow::Result<()>;
}

View File

@ -0,0 +1,49 @@
use std::ops::Deref;
use anyhow::Context;
pub enum ActionConfig {
Actual { doc: yaml_rust2::Yaml },
None,
}
impl Deref for ActionConfig {
type Target = yaml_rust2::Yaml;
fn deref(&self) -> &Self::Target {
match &self {
ActionConfig::Actual { doc } => doc,
ActionConfig::None => &yaml_rust2::Yaml::BadValue,
}
}
}
impl TryFrom<&str> for ActionConfig {
type Error = anyhow::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
let mut cuddle = yaml_rust2::YamlLoader::load_from_str(value)?;
if cuddle.len() != 1 {
anyhow::bail!("cuddle.yaml can only be 1 document wide");
}
let doc = cuddle.pop().unwrap();
let doc = doc["please"]["actions"].clone();
if doc.is_badvalue() {
return Ok(Self::None);
}
Ok(Self::Actual { doc })
}
}
impl ActionConfig {
pub fn parse() -> anyhow::Result<Self> {
let cuddle_yaml =
std::fs::read_to_string("cuddle.yaml").context("failed to read cuddle.yaml")?;
Self::try_from(cuddle_yaml.as_str())
}
}

View File

@ -0,0 +1,45 @@
pub(crate) mod actions;
mod config;
mod rust_action;
use std::{ops::Deref, sync::Arc};
use catalog::RustAction;
pub use config::ActionConfig;
use semver::Version;
pub mod catalog {
pub use crate::rust_action::*;
}
pub struct Action(Arc<dyn actions::Action>);
impl Deref for Action {
type Target = Arc<dyn actions::Action>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
pub struct Actions(Vec<Action>);
impl Actions {
pub fn from_cuddle() -> anyhow::Result<Self> {
let config = ActionConfig::parse()?;
Ok(Self(
vec![Action(Arc::new(RustAction::new()))]
.into_iter()
.filter(|a| a.enabled(&config).unwrap_or_default())
.collect(),
))
}
pub fn execute(&self, version: &Version) -> anyhow::Result<()> {
for action in &self.0 {
action.execute(version)?;
}
Ok(())
}
}

View File

@ -0,0 +1,237 @@
use std::io::Write;
use anyhow::Context;
use crate::{actions::Action, ActionConfig};
#[derive(Default, Clone)]
pub struct RustAction {}
impl RustAction {
pub fn new() -> Self {
Self {}
}
fn execute_content(
&self,
version: &semver::Version,
cargo_content: &str,
) -> anyhow::Result<String> {
tracing::trace!("parsing Cargo.toml file as tolm");
let mut cargo_doc = cargo_content.parse::<toml_edit::DocumentMut>()?;
tracing::debug!(
"updating cargo workspace package version to {}",
version.to_string()
);
let workspace = if cargo_doc.contains_table("workspace") {
cargo_doc["workspace"].as_table_mut().unwrap()
} else {
let mut t = toml_edit::Table::new();
t.set_implicit(true);
cargo_doc["workspace"] = toml_edit::Item::Table(t);
cargo_doc["workspace"].as_table_mut().unwrap()
};
let package = workspace["package"].or_insert(toml_edit::table());
package["version"] = toml_edit::value(version.to_string());
Ok(cargo_doc.to_string())
}
}
impl Action for RustAction {
fn enabled(&self, config: &ActionConfig) -> anyhow::Result<bool> {
if let Ok(v) = std::env::var("CUDDLE_PLEASE_RUST_ACTION") {
if let Ok(true) = v.parse::<bool>() {
return Ok(true);
}
}
let val = &config[self.name().as_str()];
if val.is_badvalue() {
return Ok(false);
}
Ok(val.as_bool().unwrap_or(true))
}
fn name(&self) -> String {
"rust".into()
}
fn execute(&self, version: &semver::Version) -> anyhow::Result<()> {
tracing::info!(
"running rust action for version: {} and file: Cargo.toml",
version.to_string()
);
let path = std::path::PathBuf::from("Cargo.toml");
tracing::trace!("reading Cargo.toml");
let file = match std::fs::read_to_string(&path) {
Ok(file) => file,
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => {
anyhow::bail!("err: Cargo.toml was not found in dir")
}
_ => Err(e)?,
},
};
let cargo_doc = self.execute_content(version, &file)?;
let mut cargo_file = std::fs::File::create(&path)?;
cargo_file.write_all(cargo_doc.as_bytes())?;
cargo_file.sync_all()?;
tracing::debug!("finished writing cargo file");
Ok(())
}
}
#[cfg(test)]
mod test {
use semver::{BuildMetadata, Prerelease};
use crate::{actions::Action, ActionConfig};
use super::RustAction;
#[test]
fn test_is_enabled() {
let config = ActionConfig::try_from(
r#"
please:
actions:
rust: true
"#,
)
.unwrap();
let enabled = RustAction::new().enabled(&config).unwrap();
assert!(enabled)
}
#[test]
fn test_is_disabled_by_default() {
let config = ActionConfig::try_from(
r#"
please:
"#,
)
.unwrap();
let enabled = RustAction::new().enabled(&config).unwrap();
assert!(!enabled)
}
#[test]
fn test_is_disabled() {
let config = ActionConfig::try_from(
r#"
please:
actions:
rust: false
"#,
)
.unwrap();
let enabled = RustAction::new().enabled(&config).unwrap();
assert!(!enabled)
}
#[test]
fn test_missing_value_is_enabled() {
let config = ActionConfig::try_from(
r#"
please:
actions:
rust:
"#,
)
.unwrap();
let enabled = RustAction::new().enabled(&config).unwrap();
assert!(enabled)
}
#[test]
fn test_can_edit_empty_file() {
let output = RustAction::default()
.execute_content(
&semver::Version {
major: 0,
minor: 1,
patch: 0,
pre: Prerelease::default(),
build: BuildMetadata::default(),
},
"",
)
.unwrap();
pretty_assertions::assert_eq!(
r#"[workspace.package]
version = "0.1.0"
"#,
&output,
)
}
#[test]
fn test_only_edits_stuff() {
let input = r#"
[workspace]
members = ["."]
[package]
something = {some = "something"}
# Some comment
[workspace.package]
version = "0.0.0" # some comment
readme = "../../"
"#;
let output = RustAction::default()
.execute_content(
&semver::Version {
major: 0,
minor: 1,
patch: 0,
pre: Prerelease::default(),
build: BuildMetadata::default(),
},
input,
)
.unwrap();
pretty_assertions::assert_eq!(
r#"
[workspace]
members = ["."]
[package]
something = {some = "something"}
# Some comment
[workspace.package]
version = "0.1.0"
readme = "../../"
"#,
&output,
)
}
}

View File

@ -12,6 +12,7 @@ publishable = true
[dependencies]
cuddle-please-frontend.workspace = true
cuddle-please-misc.workspace = true
cuddle-please-actions.workspace = true
anyhow.workspace = true
tracing.workspace = true

View File

@ -6,6 +6,7 @@ use std::{
};
use clap::{Parser, Subcommand};
use cuddle_please_actions::Actions;
use cuddle_please_frontend::{gatheres::ConfigArgs, PleaseConfig, PleaseConfigBuilder};
use cuddle_please_misc::{
ConsoleUi, DynRemoteGitClient, DynUi, GiteaClient, GlobalArgs, LocalGitClient, StdinFn,
@ -90,26 +91,27 @@ impl Command {
}
pub fn execute(self, current_dir: Option<&Path>) -> anyhow::Result<()> {
match &self.commands {
Some(Commands::Release {}) => {
let (config, git_client, gitea_client) = self.get_deps(current_dir)?;
ReleaseCommandHandler::new(self.ui, config, git_client, gitea_client)
.execute(self.global.dry_run)?;
}
Some(Commands::Config { command }) => {
let (config, _, _) = self.get_deps(current_dir)?;
ConfigCommandHandler::new(self.ui, config).execute(command)?;
}
Some(Commands::Gitea { command }) => {
let (config, _, gitea_client) = self.get_deps(current_dir)?;
if let Some(c) = &self.commands {
match c {
Commands::Release {} => {
let (config, git_client, gitea_client, actions) = self.get_deps(current_dir)?;
ReleaseCommandHandler::new(self.ui, config, git_client, gitea_client, actions)
.execute(self.global.dry_run)?;
}
Commands::Config { command } => {
let (config, _, _, _) = self.get_deps(current_dir)?;
ConfigCommandHandler::new(self.ui, config).execute(command)?;
}
Commands::Gitea { command } => {
let (config, _, gitea_client, _) = self.get_deps(current_dir)?;
GiteaCommandHandler::new(self.ui, config, gitea_client)
.execute(command, self.global.token.expect("token to be set").deref())?;
GiteaCommandHandler::new(self.ui, config, gitea_client)
.execute(command, self.global.token.expect("token to be set").deref())?;
}
Commands::Doctor {} => {
DoctorCommandHandler::new(self.ui).execute()?;
}
}
Some(Commands::Doctor {}) => {
DoctorCommandHandler::new(self.ui).execute()?;
}
None => {}
}
Ok(())
@ -118,7 +120,7 @@ impl Command {
fn get_deps(
&self,
current_dir: Option<&Path>,
) -> anyhow::Result<(PleaseConfig, VcsClient, DynRemoteGitClient)> {
) -> anyhow::Result<(PleaseConfig, VcsClient, DynRemoteGitClient, Actions)> {
let config = self.build_config(current_dir)?;
let git_client =
self.get_git(&config, self.global.token.clone().expect("token to be set"))?;
@ -140,7 +142,9 @@ impl Command {
tracing_subscriber::fmt().with_env_filter(env_filter).init();
}
Ok((config, git_client, gitea_client))
let actions = self.get_actions()?;
Ok((config, git_client, gitea_client, actions))
}
fn build_config(&self, current_dir: Option<&Path>) -> Result<PleaseConfig, anyhow::Error> {
@ -183,6 +187,10 @@ impl Command {
)),
}
}
fn get_actions(&self) -> anyhow::Result<Actions> {
Actions::from_cuddle()
}
}
#[derive(Debug, Clone, Subcommand)]

View File

@ -1,3 +1,4 @@
use cuddle_please_actions::Actions;
use cuddle_please_frontend::PleaseConfig;
use ::semver::Version;
@ -13,6 +14,7 @@ pub struct ReleaseCommandHandler {
config: PleaseConfig,
git_client: VcsClient,
gitea_client: DynRemoteGitClient,
actions: Actions,
}
impl ReleaseCommandHandler {
@ -21,12 +23,14 @@ impl ReleaseCommandHandler {
config: PleaseConfig,
git_client: VcsClient,
gitea_client: DynRemoteGitClient,
actions: Actions,
) -> Self {
Self {
ui,
config,
git_client,
gitea_client,
actions,
}
}
@ -69,6 +73,8 @@ impl ReleaseCommandHandler {
let (changelog_placement, changelog, changelog_last_changes) =
compose_changelog(&commit_strs, &next_version, source)?;
self.actions.execute(&next_version)?;
if let Some(first_commit) = commit_strs.first() {
if first_commit.contains("chore(release): ") {
tracing::trace!("creating release");

View File

@ -77,6 +77,8 @@ impl ChangeLogBuilder {
commit_id: None,
timestamp,
previous: None,
message: None,
repository: None,
},
config: self.config,
release_link: self.release_link,
@ -180,6 +182,7 @@ fn default_commit_parsers() -> Vec<CommitParser> {
field: None,
pattern: None,
sha: None,
footer: None,
}
}
@ -201,6 +204,7 @@ fn default_commit_parsers() -> Vec<CommitParser> {
field: None,
pattern: None,
sha: None,
footer: None,
},
]
}

View File

@ -25,7 +25,6 @@ PleaseConfig
api_url: https://some-example.gitea-instance
"#;
#[test]
#[traced_test]
fn test_config_from_current_dir() {
let args = get_base_args();
@ -39,7 +38,6 @@ fn test_config_from_current_dir() {
assert_output(ui, EXPECTED_OUTPUT, "");
}
#[test]
#[traced_test]
fn test_config_from_source_dir() {
let mut args = get_base_args();
@ -55,7 +53,6 @@ fn test_config_from_source_dir() {
assert_output(ui, EXPECTED_OUTPUT, "");
}
#[test]
#[traced_test]
fn test_config_from_stdin() {
let mut args = get_base_args();
@ -75,7 +72,6 @@ settings:
assert_output(ui, EXPECTED_OUTPUT, "");
}
#[test]
#[traced_test]
fn test_config_fails_when_not_path_is_set() {
let args = get_base_args();

View File

@ -16,14 +16,18 @@ please:
branch: main
settings:
api_url: https://git.front.kjuulh.io
actions:
rust:
components:
packages:
debian:
dev:
- jq
- git
release:
- jq
- git
scripts:
"mkdocs:new":