8000 feat: add bump order config for packages by oknozor · Pull Request #443 · cocogitto/cocogitto · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add bump order config for packages #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ massif.out.*
perf.data
perf.data.old
stacks.folded
.zed
6 changes: 5 additions & 1 deletion src/command/bump/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::conventional::version::{Increment, IncrementCommand};

use crate::git::tag::{Tag, TagLookUpOptions};
use crate::hook::HookVersion;
use crate::settings::MonoRepoPackage;
use crate::{settings, CocoGitto, SETTINGS};
use anyhow::Result;
use colored::*;
Expand Down Expand Up @@ -449,7 +450,10 @@ impl CocoGitto {
build: Option<&str>,
) -> Result<Vec<PackageBumpData>> {
let mut package_bumps = vec![];
for (package_name, package) in SETTINGS.packages.iter() {
let mut packages: Vec<(&String, &MonoRepoPackage)> = SETTINGS.packages.iter().collect();
packages.sort_by(|a, b| a.1.bump_order.cmp(&b.1.bump_order));

for (package_name, package) in packages {
let old = self.repository.get_latest_package_tag(package_name);
let old = tag_or_fallback_to_zero(old)?;

Expand Down
17 changes: 11 additions & 6 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,28 @@ pub enum GitHook {
#[serde(deny_unknown_fields, default)]
pub struct MonoRepoPackage {
/// The package path, relative to the repository root dir.
/// Used to scan commits and set hook commands current directory
/// Used to scan commits and set hook commands current directory.
pub path: PathBuf,
/// List of globs for additional paths to include, relative to
/// the repository root dir.
pub include: Vec<String>,
/// List of globs for paths to ignore, relative to
/// the repository root dir.
pub ignore: Vec<String>,
/// Where to write the changelog
/// Where to write the changelog.
pub changelog_path: Option<String>,
/// Bumping package marked as public api will increment
/// the global monorepo version when using `cog bump --auto`
/// the global monorepo version when using `cog bump --auto`.
pub public_api: bool,
/// Overrides `pre_package_bump_hooks`
/// Overrides `pre_package_bump_hooks`.
pub pre_bump_hooks: Option<Vec<String>>,
/// Overrides `post_package_bump_hooks`
/// Overrides `post_package_bump_hooks`.
pub post_bump_hooks: Option<Vec<String>>,
/// Custom profile to override `pre_bump_hooks`, `post_bump_hooks`
/// Custom profile to override `pre_bump_hooks`, `post_bump_hooks`.
pub bump_profiles: HashMap<String, BumpProfile>,
/// Ordering of packages in the changelog, this affect in which order
/// packages will be bumped.
pub bump_order: Option<usize>,
}

impl Default for &MonoRepoPackage {
Expand All @@ -236,6 +239,7 @@ impl Default for &MonoRepoPackage {
post_bump_hooks: None,
bump_profiles: Default::default(),
public_api: true,
bump_order: None,
});

Box::leak(package)
Expand All @@ -253,6 +257,7 @@ impl Default for MonoRepoPackage {
post_bump_hooks: None,
bump_profiles: Default::default(),
public_api: true,
bump_order: None,
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions tests/lib_tests/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::PathBuf;

use anyhow::Result;
use cmd_lib::run_cmd;
use cmd_lib::run_fun;
use sealed_test::prelude::*;
use speculoos::prelude::*;

Expand Down Expand Up @@ -273,6 +274,79 @@ fn consecutive_package_bump_ok() -> Result<()> {
Ok(())
}

fn ordered_package_bump() -> 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()),
bump_order: Some(2),
..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()),
bump_order: Some(1),
..Default::default()
};

packages.insert("thumbor".to_owned(), thumbor());

let settings = Settings {
packages,
ignore_merge_commits: true,
..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 {
increment: IncrementCommand::Auto,
pre_release: None,
build: None,
hooks_config: None,
annotated: None,
dry_run: false,
skip_ci: false,
skip_ci_override: None,
skip_untracked: false,
disable_bump_commit: false,
});

// Assert
let tags_sorted_by_date = run_fun!(git tag --sort=-taggerdate)?;
let tags_sorted_by_date: Vec<&str> = tags_sorted_by_date.lines().collect();
assert_that!(tags_sorted_by_date).is_equal_to(vec!["jenkins-0.1.0", "thumbor-0.1.0"]);

Ok(())
}

#[sealed_test]
fn should_fallback_to_0_0_0_when_there_is_no_tag() -> Result<()> {
// Arrange
Expand Down
17 changes: 17 additions & 0 deletions website/guide/monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ If some of your packages does not belong to your project public API use `public_
from updating the global project version.
:::

### Package bump order

When creating tags for multiple packages in a monorepo, you can control the order in which packages are bumped by setting the `bump_order` property in your package configuration. Packages with lower `bump_order` values will be bumped first.

**Example:**

```toml
[packages]
package-a = { path = "packages/a", bump_order = 1 } # Will be bumped first
package-b = { path = "packages/b", bump_order = 2 } # Will be bumped second
package-c = { path = "packages/c" } # No explicit order specified
```

This is particularly useful when you have dependencies between packages and need to ensure they are versioned in a specific order. Tags will be created according to the specified bump order, which can be important for deployment processes or dependency management.

If `bump_order` is not specified for a package, those packages will be processed after packages with explicit ordering.

### Packages hooks

When creating a monorepo version Cocogitto will execute the pre-bump and post-bump hooks normally. Additionally, it will
Expand Down
Loading
0