15 Commits

Author SHA1 Message Date
b711258790 feat: with rust workspaces
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-07 13:34:58 +02:00
56b44cf2e2 fix(json-edit): with actual arg instead of stupid str replace
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 18:56:43 +02:00
2919ca9a04 chore: remove cr
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 18:38:11 +02:00
ff2b59dd02 chore(json-edit): clarify errors
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 18:37:32 +02:00
19dd0ff636 fix(ci): without token
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 18:36:03 +02:00
c08918ad6f feat(json-edit): added json-edit to update some json content with next global version
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 18:32:09 +02:00
19e7adfedb fix(docs): check fix version
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 15:20:05 +02:00
27cb31f433 chore(docs): remove 0.2 checklist
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 13:05:03 +00:00
113e5282ef fix(crate): initial pr always included the entire changelog
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 15:01:32 +02:00
fa67dfeee3 fix(crate): always prefix with 'v' when creating prs, or releases (#9)
All checks were successful
continuous-integration/drone/push Build is passing
We don't want rust versions to include the 'v',

however, many languages and tools require it. As such we're choosing when to do it, in this case at the api layer.

Signed-off-by: kjuulh <contact@kjuulh.io>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/cuddle-please/pulls/9
Co-authored-by: kjuulh <contact@kjuulh.io>
Co-committed-by: kjuulh <contact@kjuulh.io>
2023-08-04 12:41:31 +00:00
8a8d309ddf chore(release): 0.2.1 (#8)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
### Docs
- *(check)* 0.2 milestone, forgot for 0.2.0

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/cuddle-please/pulls/8
2023-08-04 12:33:10 +00:00
09508ec986 docs(check): 0.2 milestone, forgot for 0.2.0
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 14:22:41 +02:00
0967e35fbf chore(release): 0.2.0 (#7)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
### Added
- *(ci)* with pr
- *(ci)* on pr only
- *(ci)* with ci:pr.sh file
- *(ci)* update ci with best settings
- *(ci)* pr ignore master
- *(ci)* ignore pr for master
- add git init
- with actual docker login
- with docker login
- back to default
- with ldd
- only ci
- with musl instead
- with some debug stuff
- with shared volume
- with shared volume
- without going into module
- set to use prefix when in ci
- only master
- with working main
- ci:main script for ci
- with run script
- fixed stuff
- with ultra caching
- with ci
- with set -e for abort
- with drone yml
- add mkdocs build
- add basic version
- update with repository
- add publishable to rest
- hack get in control of log level

### Docs
- fix admonitions
- add docs
- remove 0.1 milestone

### Fixed
- with actual install

### Other
- *(rust)* fmt
- *(rust)* clippy fix
- *(ci)* no please for pr
- *(ci)* rename pr -> pull-request in ci:pr
- remove faulty test
- add git (alpine)
- add git
- musl
- remember package name
- rename variable
- openssl-src
- with openssl-dev
- with pkg config sysroot
- with musl dev
- with build-essential
- with libssl-dev
- with token
- add mit license
- add logging to stdout
- update versions
- add docs

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/cuddle-please/pulls/7
2023-08-03 23:23:05 +00:00
67c2c0c0c5 chore(rust): fmt
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 01:19:15 +02:00
78307ec8a3 chore(rust): clippy fix
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-04 01:18:58 +02:00
16 changed files with 525 additions and 81 deletions

View File

@@ -6,6 +6,78 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.2.1] - 2023-08-04
### Docs
- *(check)* 0.2 milestone, forgot for 0.2.0
## [0.2.0] - 2023-08-03
### Added
- *(ci)* with pr
- *(ci)* on pr only
- *(ci)* with ci:pr.sh file
- *(ci)* update ci with best settings
- *(ci)* pr ignore master
- *(ci)* ignore pr for master
- add git init
- with actual docker login
- with docker login
- back to default
- with ldd
- only ci
- with musl instead
- with some debug stuff
- with shared volume
- with shared volume
- without going into module
- set to use prefix when in ci
- only master
- with working main
- ci:main script for ci
- with run script
- fixed stuff
- with ultra caching
- with ci
- with set -e for abort
- with drone yml
- add mkdocs build
- add basic version
- update with repository
- add publishable to rest
- hack get in control of log level
### Docs
- fix admonitions
- add docs
- remove 0.1 milestone
### Fixed
- with actual install
### Other
- *(rust)* fmt
- *(rust)* clippy fix
- *(ci)* no please for pr
- *(ci)* rename pr -> pull-request in ci:pr
- remove faulty test
- add git (alpine)
- add git
- musl
- remember package name
- rename variable
- openssl-src
- with openssl-dev
- with pkg config sysroot
- with musl dev
- with build-essential
- with libssl-dev
- with token
- add mit license
- add logging to stdout
- update versions
- add docs
## [0.1.0] - 2023-08-01
### Added

50
Cargo.lock generated
View File

@@ -201,6 +201,38 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
[[package]]
name = "camino"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c"
dependencies = [
"serde",
]
[[package]]
name = "cargo-platform"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479"
dependencies = [
"serde",
]
[[package]]
name = "cargo_metadata"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592"
dependencies = [
"camino",
"cargo-platform",
"semver",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "cc"
version = "1.0.79"
@@ -520,6 +552,21 @@ dependencies = [
"url",
]
[[package]]
name = "cuddle-please-release-strategy"
version = "0.1.0"
dependencies = [
"anyhow",
"cargo_metadata",
"pretty_assertions",
"semver",
"serde",
"serde_json",
"tempdir",
"tracing",
"tracing-test",
]
[[package]]
name = "dagger-core"
version = "0.2.11"
@@ -2184,6 +2231,9 @@ name = "semver"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
dependencies = [
"serde",
]
[[package]]
name = "serde"

View File

@@ -4,6 +4,7 @@ members = [
"crates/cuddle-please-frontend",
"crates/cuddle-please-commands",
"crates/cuddle-please-misc",
"crates/cuddle-please-release-strategy",
"ci"
]
resolver = "2"
@@ -13,6 +14,7 @@ cuddle-please = { path = "crates/cuddle-please", version = "0.1.0" }
cuddle-please-frontend = { path = "crates/cuddle-please-frontend", version = "0.1.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" }
anyhow = { version = "1.0.72" }
tracing = { version = "0.1", features = ["log"] }
@@ -21,6 +23,7 @@ clap = { version = "4.3.19", features = ["derive", "env"] }
dotenv = { version = "0.15.0" }
url = { version = "2.4.0" }
serde_yaml = { version = "0.9.25" }
serde_json = { version = "*" }
serde = { version = "1", features = ["derive"] }
semver = "1.0.18"
conventional_commit_parser = "0.9.4"

View File

@@ -36,22 +36,14 @@ See docs for more information about installation and some such
## Checklist
### 0.2 Milestone
- [ ] Add docs
- [ ] Add asciinema
- [ ] Create docker image
- [ ] Add examples
- [ ] Fx drone config
- [ ] Releaser
- [ ] On main/master
- [ ] Add reporter for PR and Repositories
- [ ] tbd...
### 0.3 Milestone
- [x] Fix: 0.0.0 -> **v**0.0.0
- [ ] Add release strategies
- [ ] Add reporter for PR and Repositories
- [ ] Add inquire for missing values when needed (when not running in ci or have a proper tty)
- [ ] Break down cuddle-please-misc
- [ ] ci(release): Add cuddle-please release artifacts for the different os and so on.
### 0.x Milestone
- [ ] Add github support

View File

@@ -2,19 +2,13 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use build::build_and_deploy;
use clap::Args;
use clap::Parser;
use clap::Subcommand;
use clap::ValueEnum;
use dagger_sdk::ContainerId;
use dagger_sdk::ContainerPublishOpts;
use dagger_sdk::Platform;
use dagger_sdk::QueryContainerOpts;
use futures::StreamExt;
use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use crate::please_release::run_release_please;
@@ -137,7 +131,7 @@ async fn main() -> eyre::Result<()> {
&cli.global,
&base_image,
&prod_image,
&bin_name,
bin_name,
&None,
)
.await?;
@@ -158,11 +152,11 @@ async fn main() -> eyre::Result<()> {
image,
bin_name,
} => {
build::build_and_deploy(client, &cli.global, &bin_name, &image, &tag).await?;
build::build_and_deploy(client, &cli.global, bin_name, image, tag).await?;
}
LocalCommands::PleaseRelease => todo!(),
LocalCommands::BuildDocs {} => {
let image = docs::execute(
let _image = docs::execute(
client.clone(),
&cli.global,
&Some("linux/amd64".to_string()),
@@ -179,10 +173,10 @@ async fn main() -> eyre::Result<()> {
let args = &cli.global;
let base_image =
base_rust_image(client.clone(), &args, &None, bin_name, &"debug".into())
base_rust_image(client.clone(), args, &None, bin_name, &"debug".into())
.await
.unwrap();
test::execute(client.clone(), &args, base_image)
test::execute(client.clone(), args, base_image)
.await
.unwrap();
}
@@ -195,14 +189,14 @@ async fn main() -> eyre::Result<()> {
) {
let args = &cli.global;
build::build(client.clone(), &args, bin_name, image, tag)
build::build(client.clone(), args, bin_name, image, tag)
.await
.unwrap();
}
tokio::join!(
test(client.clone(), &cli, &bin_name),
build(client.clone(), &cli, &bin_name, &image, &tag),
test(client.clone(), &cli, bin_name),
build(client.clone(), &cli, bin_name, image, tag),
);
}
Commands::Main {
@@ -214,10 +208,10 @@ async fn main() -> eyre::Result<()> {
let args = &cli.global;
let base_image =
base_rust_image(client.clone(), &args, &None, bin_name, &"debug".into())
base_rust_image(client.clone(), args, &None, bin_name, &"debug".into())
.await
.unwrap();
test::execute(client.clone(), &args, base_image)
test::execute(client.clone(), args, base_image)
.await
.unwrap();
}
@@ -230,7 +224,7 @@ async fn main() -> eyre::Result<()> {
) {
let args = &cli.global;
build::build_and_deploy(client.clone(), &args, bin_name, image, tag)
build::build_and_deploy(client.clone(), args, bin_name, image, tag)
.await
.unwrap();
}
@@ -242,8 +236,8 @@ async fn main() -> eyre::Result<()> {
}
tokio::join!(
test(client.clone(), &cli, &bin_name),
build(client.clone(), &cli, &bin_name, &image, &tag),
test(client.clone(), &cli, bin_name),
build(client.clone(), &cli, bin_name, image, tag),
cuddle_please(client.clone(), &cli)
);
}
@@ -257,9 +251,7 @@ mod please_release {
use std::sync::Arc;
use dagger_sdk::Container;
use crate::{base_rust_image, build, get_base_debian_image, get_rust_dep_src, GlobalArgs};
use crate::{base_rust_image, GlobalArgs};
pub async fn run_release_please(
client: Arc<dagger_sdk::Query>,
@@ -313,12 +305,6 @@ mod please_release {
std::env::var("CUDDLE_PLEASE_TOKEN")?
),
])
.with_exec(vec![
"git",
"config",
"http.extraheader",
"'Authorization: token b52c18cab8a95d33f34b0d081440f77a2b156886'",
])
.with_exec(vec![
"cuddle-please",
"release",
@@ -366,7 +352,7 @@ mod docs {
pub async fn execute(
client: Arc<dagger_sdk::Query>,
args: &GlobalArgs,
platform: &Option<String>,
_platform: &Option<String>,
) -> eyre::Result<Container> {
let mkdocs_container = client.container().from(
args.mkdocs_image
@@ -429,10 +415,6 @@ mod build {
use dagger_sdk::Container;
use futures::StreamExt;
use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use crate::{base_rust_image, get_base_debian_image, GlobalArgs};
pub async fn build_and_deploy(
@@ -453,7 +435,7 @@ mod build {
let container = base_rust_image(
client.clone(),
&args,
args,
&Some("linux/amd64".to_string()),
&bin_name.clone(),
&"release".into(),
@@ -461,10 +443,10 @@ mod build {
.await?;
let build_image = execute(
client.clone(),
&args,
args,
&container,
&base_image,
&bin_name,
bin_name,
&Some("linux/amd64".to_string()),
)
.await?;
@@ -487,8 +469,8 @@ mod build {
client: Arc<dagger_sdk::Query>,
args: &GlobalArgs,
bin_name: &String,
image: &String,
tag: &String,
_image: &String,
_tag: &String,
) -> eyre::Result<()> {
// let containers = vec!["linux/amd64", "linux/arm64"];
@@ -501,7 +483,7 @@ mod build {
let container = base_rust_image(
client.clone(),
&args,
args,
&Some("linux/amd64".to_string()),
&bin_name.clone(),
&"release".into(),
@@ -509,10 +491,10 @@ mod build {
.await?;
let build_image = execute(
client.clone(),
&args,
args,
&container,
&base_image,
&bin_name,
bin_name,
&Some("linux/amd64".to_string()),
)
.await?;
@@ -545,7 +527,7 @@ mod build {
rust_target,
"--release",
"-p",
&bin_name,
bin_name,
]);
let final_image = base_image
@@ -556,7 +538,7 @@ mod build {
.id()
.await?,
)
.with_exec(vec![&bin_name, "--help"]);
.with_exec(vec![bin_name, "--help"]);
let output = final_image.stdout().await?;
println!("{output}");
@@ -616,6 +598,7 @@ pub async fn get_base_debian_image(
"pkg-config",
"openssl",
"git",
"jq",
]);
Ok(base_image)
@@ -654,12 +637,12 @@ pub async fn get_rust_dep_src(
.build()?,
);
return Ok(directory);
Ok(directory)
}
pub async fn get_rust_skeleton_files(
client: Arc<dagger_sdk::Query>,
args: &GlobalArgs,
_args: &GlobalArgs,
) -> eyre::Result<(dagger_sdk::Directory, Vec<String>)> {
let mut rust_crates = vec![PathBuf::from("ci")];
let mut dirs = tokio::fs::read_dir("crates").await?;
@@ -701,7 +684,7 @@ pub async fn get_rust_skeleton_files(
if let Some(file_name) = rust_crate.file_name() {
crate_names.push(file_name.to_str().unwrap().to_string());
}
directory = create_skeleton_files(directory, &rust_crate)?;
directory = create_skeleton_files(directory, rust_crate)?;
}
Ok((directory, crate_names))
@@ -736,10 +719,12 @@ pub async fn base_rust_image(
.as_ref()
.unwrap_or(&"rustlang/rust:nightly".into()),
)
.with_exec(vec!["rustup", "target", "add", rust_target]);
.with_exec(vec!["rustup", "target", "add", rust_target])
.with_exec(vec!["apt", "update"])
.with_exec(vec!["apt", "install", "-y", "jq"]);
let target_cache = client.cache_volume(format!("rust_target_{}", profile));
let mut build_options = vec!["cargo", "build", "--target", rust_target, "-p", &bin_name];
let mut build_options = vec!["cargo", "build", "--target", rust_target, "-p", bin_name];
if profile == "release" {
build_options.push("--release");
@@ -754,7 +739,7 @@ pub async fn base_rust_image(
let exclude = crates
.iter()
.filter(|c| **c != "ci")
.map(|c| format!("**/*{}*", c.replace("-", "_")))
.map(|c| format!("**/*{}*", c.replace('-', "_")))
.collect::<Vec<_>>();
let exclude = exclude.iter().map(|c| c.as_str()).collect();

View File

@@ -50,10 +50,8 @@ impl ReleaseCommandHandler {
tracing::trace!("fetched commits since last version");
let current_version = get_current_version(significant_tag);
tracing::trace!("found current version: {}", current_version.to_string());
self.ui.write_str_ln(&format!(
"found current version: {}",
current_version
));
self.ui
.write_str_ln(&format!("found current version: {}", current_version));
let conventional_commit_results = parse_conventional_commits(current_version, commits)?;
tracing::trace!("parsing conventional commits");
@@ -64,10 +62,8 @@ impl ReleaseCommandHandler {
return Ok(());
}
let (commit_strs, next_version) = conventional_commit_results.unwrap();
self.ui.write_str_ln(&format!(
"calculated next version: {}",
next_version
));
self.ui
.write_str_ln(&format!("calculated next version: {}", next_version));
tracing::trace!("creating changelog");
let (changelog_placement, changelog, changelog_last_changes) =
@@ -153,7 +149,8 @@ impl ReleaseCommandHandler {
owner,
repository,
&next_version.to_string(),
&changelog_last_changes.unwrap(),
&changelog_last_changes
.ok_or(anyhow::anyhow!("could not get the latest changes"))?,
existing_pr,
)?
} else {
@@ -168,7 +165,8 @@ impl ReleaseCommandHandler {
owner,
repository,
&next_version.to_string(),
&changelog,
&changelog_last_changes
.ok_or(anyhow::anyhow!("could not get the latest changes"))?,
branch,
)?
} else {
@@ -253,7 +251,6 @@ fn parse_conventional_commits(
}
fn get_current_version(significant_tag: Option<Tag>) -> Version {
significant_tag
.map(|st| Version::try_from(st).unwrap())
.unwrap_or(Version::new(0, 0, 0))

View File

@@ -30,10 +30,9 @@ const CUDDLE_CONFIG_FILE_NAME: &str = "cuddle.please";
const YAML_EXTENSION: &str = "yaml";
pub fn get_config_from_config_file(current_dir: &Path) -> PleaseConfigBuilder {
let current_cuddle_path = current_dir
.join(format!("{CUDDLE_FILE_NAME}.{YAML_EXTENSION}"));
let current_cuddle_config_path = current_dir
.join(format!("{CUDDLE_CONFIG_FILE_NAME}.{YAML_EXTENSION}"));
let current_cuddle_path = current_dir.join(format!("{CUDDLE_FILE_NAME}.{YAML_EXTENSION}"));
let current_cuddle_config_path =
current_dir.join(format!("{CUDDLE_CONFIG_FILE_NAME}.{YAML_EXTENSION}"));
let mut please_config = PleaseConfigBuilder::default();
if let Some(config) = get_config_from_file::<CuddleEmbeddedPleaseConfig>(current_cuddle_path) {

View File

@@ -67,7 +67,7 @@ impl VcsClient {
"-c",
&format!("http.extraHeader='Authorization: token {}'", token),
"-c",
&format!("http.extraHeader='Sudo: kjuulh'"),
"http.extraHeader='Sudo: kjuulh'",
"-c",
&format!("user.name={}", username),
"-c",

View File

@@ -330,7 +330,7 @@ impl RemoteGitEngine for GiteaClient {
base: base.into(),
body: body.into(),
head: "cuddle-please/release".into(),
title: format!("chore(release): {}", version),
title: format!("chore(release): v{}", version),
};
tracing::trace!(
@@ -377,7 +377,7 @@ impl RemoteGitEngine for GiteaClient {
let request = CreatePullRequestOption {
body: body.into(),
title: format!("chore(release): {}", version),
title: format!("chore(release): v{}", version),
};
tracing::trace!(
@@ -429,9 +429,9 @@ impl RemoteGitEngine for GiteaClient {
let request = CreateReleaseOption {
body: body.into(),
draft: false,
name: version.into(),
name: format!("v{version}"),
prerelease,
tag_name: version.into(),
tag_name: format!("v{version}"),
};
tracing::trace!(

View File

@@ -0,0 +1,34 @@
[package]
name = "cuddle-please-release-strategy"
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"
version = "0.1.0"
edition = "2021"
readme = "../../README.md"
license-file = "../../LICENSE"
publishable = true
[dependencies]
anyhow.workspace = true
tracing.workspace = true
serde.workspace = true
semver.workspace = true
cargo_metadata = "0.17.0"
[dev-dependencies]
tracing-test = { workspace = true, features = ["no-env-filter"] }
pretty_assertions.workspace = true
tempdir.workspace = true
serde_json.workspace = true
[features]
rust-workspace = []
rust-crate = []
toml-edit = []
json-edit = []
yaml-edit = []
default = [
"json-edit",
"rust-workspace"
]

View File

@@ -0,0 +1,60 @@
use std::path::Path;
use anyhow::Context;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct JsonEditOptions {
pub jq: String,
}
impl JsonEditOptions {
pub fn execute(&self, path: &Path, next_version: impl AsRef<str>) -> anyhow::Result<()> {
let next_version = next_version.as_ref();
if !path.exists() {
anyhow::bail!("could not find file at: {}", path.display());
}
if let Ok(metadata) = path.metadata() {
if !metadata.is_file() {
anyhow::bail!("{} is not a file", path.display());
}
}
let abs_path = path.canonicalize().context(anyhow::anyhow!(
"could not get absolute path from {}",
path.display()
))?;
let output = std::process::Command::new("jq")
.arg("--arg")
.arg("version")
.arg(next_version)
.arg(&self.jq)
.arg(
abs_path
.to_str()
.ok_or(anyhow::anyhow!("path contains non utf-8 chars"))?,
)
.output()
.context(anyhow::anyhow!(
"failed to run jq on file, jq may not be installed or query was invalid"
))?;
if !output.status.success() {
let err_content = std::str::from_utf8(output.stderr.as_slice())?;
anyhow::bail!("failed to run jq with output: {}", err_content);
}
let edited_json_content = std::str::from_utf8(output.stdout.as_slice())?;
tracing::trace!(
new_content = edited_json_content,
file = &abs_path.display().to_string(),
"applied jq to file"
);
std::fs::write(abs_path, edited_json_content)?;
Ok(())
}
}

View File

@@ -0,0 +1,11 @@
#[cfg(feature = "json-edit")]
mod json_edit;
#[cfg(feature = "rust-workspace")]
mod rust_workspace;
mod strategy;
#[cfg(feature = "json-edit")]
pub use json_edit::JsonEditOptions;
#[cfg(feature = "rust-workspace")]
pub use rust_workspace::RustWorkspaceOptions;

View File

@@ -0,0 +1,72 @@
use std::path::{Path, PathBuf};
use anyhow::Context;
use cargo_metadata::camino::{Utf8Path, Utf8PathBuf};
use serde::{Deserialize, Serialize};
fn lock_step_default() -> bool {
true
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RustWorkspaceOptions {
#[serde(default = "lock_step_default")]
pub lock_step: bool,
}
impl RustWorkspaceOptions {
pub fn execute(&self, path: &Path, next_version: impl AsRef<str>) -> anyhow::Result<()> {
let members = self.get_workspace(path)?;
Ok(())
}
pub fn get_workspace(&self, path: &Path) -> anyhow::Result<Vec<cargo_metadata::Package>> {
let entries = std::fs::read_dir(path)
.context(anyhow::anyhow!("could not read dir: {}", path.display()))?
.flatten()
.filter(|p| p.file_name().to_str().unwrap() == "Cargo.toml")
.collect::<Vec<_>>();
let cargo_manifest_file = match entries.first() {
Some(x) => x,
None => anyhow::bail!("did not find any Cargo.toml in: {}", path.display()),
};
let mut cmd = cargo_metadata::MetadataCommand::new();
let manifest = cmd
.no_deps()
.manifest_path(cargo_manifest_file.path())
.exec()
.context("could not parse manifest")?;
let members = manifest.workspace_members.iter().collect::<Vec<_>>();
let workspace_members = manifest
.packages
.into_iter()
.filter(|p| members.contains(&&p.id))
.map(|mut p| {
p.manifest_path = abs_path(&p.manifest_path);
for dependency in p.dependencies.iter_mut() {
dependency.path = dependency.path.take().map(|path| abs_path(&path))
}
p
})
.collect::<Vec<_>>();
Ok(workspace_members)
}
}
fn abs_path(path: &Utf8Path) -> Utf8PathBuf {
match path.canonicalize_utf8() {
Ok(path) => path,
Err(e) => {
tracing::debug!("failed to transform manifest_path into abs path: {}", path);
path.to_path_buf()
}
}
}

View File

@@ -0,0 +1,59 @@
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
pub struct UpdateOptions {
next_version: String,
global_changelog: String,
}
pub type Projects = Vec<Project>;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Project {
path: Option<PathBuf>,
r#type: ProjectType,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "type")]
pub enum ProjectType {
#[cfg(feature = "rust-workspace")]
#[serde(alias = "rust_workspace")]
RustWorkspace,
#[cfg(feature = "rust-crate")]
#[serde(alias = "json_edit")]
RustCrate,
#[cfg(feature = "toml-edit")]
#[serde(alias = "toml_edit")]
TomlEdit,
#[cfg(feature = "yaml-edit")]
#[serde(alias = "yaml_edit")]
YamlEdit,
#[cfg(feature = "json-edit")]
#[serde(alias = "json_edit")]
JsonEdit,
}
impl Project {
pub fn new(path: Option<PathBuf>, r#type: ProjectType) -> Self {
Self { path, r#type }
}
pub fn execute(&self, options: &UpdateOptions) -> anyhow::Result<()> {
match self.r#type {
#[cfg(feature = "rust-workspace")]
ProjectType::RustWorkspace => todo!(),
#[cfg(feature = "rust-crate")]
ProjectType::RustCrate => todo!(),
#[cfg(feature = "toml-edit")]
ProjectType::TomlEdit => todo!(),
#[cfg(feature = "yaml-edit")]
ProjectType::YamlEdit => todo!(),
#[cfg(feature = "json-edit")]
ProjectType::JsonEdit => todo!(),
}
Ok(())
}
}

View File

@@ -0,0 +1,50 @@
use tracing_test::traced_test;
#[test]
#[traced_test]
#[cfg(feature = "json-edit")]
pub fn test_can_update_version_in_jq() {
use cuddle_please_release_strategy::JsonEditOptions;
let dir = tempdir::TempDir::new("can_update_version_in_jq").unwrap();
let dir_path = dir.path();
let json_file = dir_path.join("some-test.json");
let initial_content = r#"{
"some": {
"nested": [
{
"structure": {
"version": "v1.0.1"
}
}
]
}
}
"#;
let expected = r#"{
"some": {
"nested": [
{
"structure": {
"version": "v1.0.2"
}
}
]
}
}
"#;
std::fs::write(&json_file, initial_content).unwrap();
let actual_file = std::fs::read_to_string(&json_file).unwrap();
pretty_assertions::assert_eq!(initial_content, actual_file);
let edit_options = JsonEditOptions {
jq: r#".some.nested[].structure.version=$version"#.into(),
};
edit_options.execute(&json_file, "v1.0.2").unwrap();
let actual_file = std::fs::read_to_string(&json_file).unwrap();
pretty_assertions::assert_eq!(expected, &actual_file);
}

View File

@@ -0,0 +1,60 @@
use cargo_metadata::{
camino::{Utf8Path, Utf8PathBuf},
Package,
};
use cuddle_please_release_strategy::RustWorkspaceOptions;
use serde_json::json;
use tracing_test::traced_test;
#[test]
#[traced_test]
fn test_can_read_manifest() {
let temp = tempdir::TempDir::new("test_rust_workspace_can_read_manifest").unwrap();
let temp_path = temp.path();
std::fs::write(
temp_path.join("Cargo.toml"),
r#"
[workspace]
members = [
"nested"
]
[workspace.dependencies]
nested = { path = "nested" }
"#,
)
.unwrap();
std::fs::create_dir_all(temp_path.join("nested")).unwrap();
std::fs::write(
temp_path.join("nested").join("Cargo.toml"),
r#"
[package]
name = "nested"
version = "0.1.0"
edition = "2021"
[dependencies]
nested.workspace = true
"#,
)
.unwrap();
std::fs::create_dir_all(temp_path.join("nested").join("src")).unwrap();
std::fs::write(
temp_path.join("nested").join("src").join("lib.rs"),
r#"
#[test]
test () {}
"#,
)
.unwrap();
let options = RustWorkspaceOptions { lock_step: true };
let members = options.get_workspace(temp_path).unwrap();
assert!(!members.is_empty());
let first = members.first().unwrap();
pretty_assertions::assert_eq!("nested", &first.name);
}