Skip to content

Commit

Permalink
feat: allow to disable package tagging for monorepos
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 28, 2024
1 parent 3ff98b2 commit 426223e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 13 deletions.
28 changes: 18 additions & 10 deletions src/command/bump/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// A list of glob patterns to allow bumping only on matching branches.
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions tests/cog_tests/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
82 changes: 82 additions & 0 deletions tests/lib_tests/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 11 additions & 0 deletions website/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>`
Expand Down

0 comments on commit 426223e

Please sign in to comment.