From 426223e807e0e653afc85cde498a5db976babfa9 Mon Sep 17 00:00:00 2001 From: Paul Delafosse Date: Thu, 28 Nov 2024 06:02:44 +0100 Subject: [PATCH] feat: allow to disable package tagging for monorepos --- src/command/bump/monorepo.rs | 28 +++++++----- src/settings/mod.rs | 3 ++ tests/cog_tests/changelog.rs | 4 +- tests/lib_tests/bump.rs | 82 ++++++++++++++++++++++++++++++++++++ website/reference/config.md | 11 +++++ 5 files changed, 115 insertions(+), 13 deletions(-) diff --git a/src/command/bump/monorepo.rs b/src/command/bump/monorepo.rs index b2eb7785..65828c8c 100644 --- a/src/command/bump/monorepo.rs +++ b/src/command/bump/monorepo.rs @@ -97,9 +97,11 @@ impl CocoGitto { } } - for bump in &bumps { - self.repository - .create_tag(&bump.new_version.prefixed_tag, disable_bump_commit)?; + if SETTINGS.generate_mono_repository_package_tags { + for bump in &bumps { + self.repository + .create_tag(&bump.new_version.prefixed_tag, disable_bump_commit)?; + } } // Run per package post hooks @@ -145,10 +147,14 @@ impl CocoGitto { .repository .get_latest_tag(TagLookUpOptions::default().include_pre_release()); let old = tag_or_fallback_to_zero(old)?; - let mut tag = old.bump( - IncrementCommand::AutoMonoRepoGlobal(increment_from_package_bumps), - &self.repository, - )?; + let mut tag = if SETTINGS.generate_mono_repository_package_tags { + old.bump( + IncrementCommand::AutoMonoRepoGlobal(increment_from_package_bumps), + &self.repository, + )? + } else { + old.bump(IncrementCommand::Auto, &self.repository)? + }; ensure_tag_is_greater_than_previous(&old, &tag)?; @@ -255,9 +261,11 @@ impl CocoGitto { } } - for bump in &bumps { - self.repository - .create_tag(&bump.new_version.prefixed_tag, disable_bump_commit)?; + if SETTINGS.generate_mono_repository_package_tags { + for bump in &bumps { + self.repository + .create_tag(&bump.new_version.prefixed_tag, disable_bump_commit)?; + } } if let Some(msg_tmpl) = opts.annotated { diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 0c9c508e..ef15e917 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -42,6 +42,8 @@ pub struct Settings { pub disable_bump_commit: bool, /// Activate or deactivate global tag generation for mono-repository. pub generate_mono_repository_global_tag: bool, + /// Activate or deactivate package tag generation for mono-repository. + pub generate_mono_repository_package_tags: bool, /// Specify the version separator character for mono-repository package's tags. pub monorepo_version_separator: Option, /// A list of glob patterns to allow bumping only on matching branches. @@ -74,6 +76,7 @@ impl Default for Settings { disable_changelog: false, disable_bump_commit: false, generate_mono_repository_global_tag: true, + generate_mono_repository_package_tags: true, monorepo_version_separator: None, branch_whitelist: vec![], tag_prefix: None, diff --git a/tests/cog_tests/changelog.rs b/tests/cog_tests/changelog.rs index 8a26fc12..d0c401c6 100644 --- a/tests/cog_tests/changelog.rs +++ b/tests/cog_tests/changelog.rs @@ -515,14 +515,12 @@ fn should_ignore_merge_commit() -> Result<()> { )?; // Act - let changelog = Command::cargo_bin("cog")? + Command::cargo_bin("cog")? .arg("changelog") // Assert .assert() .success(); - let changelog = changelog.stderr(""); - Ok(()) } diff --git a/tests/lib_tests/bump.rs b/tests/lib_tests/bump.rs index 862a2907..c749c93d 100644 --- a/tests/lib_tests/bump.rs +++ b/tests/lib_tests/bump.rs @@ -388,6 +388,88 @@ fn auto_bump_package_only_ok() -> Result<()> { Ok(()) } +#[sealed_test] +fn auto_bump_global_only_ok() -> Result<()> { + // Arrange + let mut packages = HashMap::new(); + let jenkins = || MonoRepoPackage { + path: PathBuf::from("jenkins"), + public_api: false, + changelog_path: Some("jenkins/CHANGELOG.md".to_owned()), + ..Default::default() + }; + + packages.insert("jenkins".to_owned(), jenkins()); + + let thumbor = || MonoRepoPackage { + path: PathBuf::from("thumbor"), + public_api: false, + changelog_path: Some("thumbor/CHANGELOG.md".to_owned()), + ..Default::default() + }; + + packages.insert("thumbor".to_owned(), thumbor()); + + let settings = Settings { + packages, + generate_mono_repository_package_tags: false, + ..Default::default() + }; + + let settings = toml::to_string(&settings)?; + + git_init()?; + run_cmd!( + echo Hello > README.md; + git add .; + git commit -m "first commit"; + mkdir jenkins; + echo "some jenkins stuff" > jenkins/file; + git add .; + git commit -m "feat(jenkins): add jenkins stuffs"; + mkdir thumbor; + echo "some thumbor stuff" > thumbor/file; + git add .; + git commit -m "feat(thumbor): add thumbor stuffs"; + echo $settings > cog.toml; + git add .; + git commit -m "chore: add cog.toml"; + )?; + + let mut cocogitto = CocoGitto::get()?; + + // Act + cocogitto.create_monorepo_version(BumpOptions::default())?; + + assert_tag_does_not_exist("jenkins-0.1.0")?; + assert_tag_does_not_exist("thumbor-0.1.0")?; + assert_tag_exists("0.1.0")?; + + cocogitto.clear_cache(); + + run_cmd!( + echo "fix jenkins bug" > jenkins/fix; + git add .; + git commit -m "fix(jenkins): bug fix on jenkins package"; + )?; + + cocogitto.create_monorepo_version(BumpOptions::default())?; + + // Assert + assert_tag_exists("0.1.1")?; + + run_cmd!( + echo "feat global feature" > global; + git add .; + git commit -m "feat: some global feature"; + )?; + + cocogitto.create_monorepo_version(BumpOptions::default())?; + + assert_tag_exists("0.2.0")?; + Ok(()) +} + // FIXME: Failing on non compliant tag should be configurable // until it's implemented we will ignore non compliant tags // #[sealed_test] diff --git a/website/reference/config.md b/website/reference/config.md index f865db43..2a5acc65 100755 --- a/website/reference/config.md +++ b/website/reference/config.md @@ -440,6 +440,17 @@ The config reference list all value that can be set in the `cog.toml` file at th generate_mono_repository_global_tag = false ``` +### ``generate_mono_repository_package_tags`` + +- Type: `boolean` +- Optional: `true` +- Default value: `true` +- Description: Activate or deactivate packages tag generation for mono-repository. +- Example: + ```toml + generate_mono_repository_package_tags = false + ``` + ### `pre_package_bump_hooks` - Type: `Array`