Skip to content

Commit

Permalink
feat(bump): option to specify skip-ci pattern for bump commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wassim Ahmed-Belkacem authored and oknozor committed Aug 1, 2023
1 parent 9a49999 commit 92736aa
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
8 changes: 8 additions & 0 deletions src/bin/cog/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ enum Command {
/// Dry-run: print the target version. No action taken
#[arg(short, long)]
dry_run: bool,

/// Specify a "Skip CI" string to append to the end of the commit
#[arg(long = "skip-ci")]
skip_ci: Option<String>,
},

/// Install cog config files
Expand Down Expand Up @@ -358,6 +362,7 @@ fn main() -> Result<()> {
package,
annotated,
dry_run,
skip_ci,
} => {
let mut cocogitto = CocoGitto::get()?;
let is_monorepo = !SETTINGS.packages.is_empty();
Expand Down Expand Up @@ -392,6 +397,7 @@ fn main() -> Result<()> {
hook_profile.as_deref(),
annotated,
dry_run,
skip_ci,
)?
}
None => cocogitto.create_monorepo_version(
Expand All @@ -400,6 +406,7 @@ fn main() -> Result<()> {
hook_profile.as_deref(),
annotated,
dry_run,
skip_ci,
)?,
}
} else {
Expand All @@ -409,6 +416,7 @@ fn main() -> Result<()> {
hook_profile.as_deref(),
annotated,
dry_run,
skip_ci,
)?
}
}
Expand Down
44 changes: 38 additions & 6 deletions src/command/bump/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,28 @@ impl CocoGitto {
hooks_config: Option<&str>,
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
) -> Result<()> {
match increment {
IncrementCommand::Auto => {
if SETTINGS.generate_mono_repository_global_tag {
self.create_monorepo_version_auto(pre_release, hooks_config, annotated, dry_run)
self.create_monorepo_version_auto(
pre_release,
hooks_config,
annotated,
dry_run,
skip_ci,
)
} else {
if annotated.is_some() {
warn!("--annotated flag is not supported for package bumps without a global tag");
}
self.create_all_package_version_auto(pre_release, hooks_config, dry_run)
self.create_all_package_version_auto(
pre_release,
hooks_config,
dry_run,
skip_ci,
)
}
}
_ => self.create_monorepo_version_manual(
Expand All @@ -63,6 +75,7 @@ impl CocoGitto {
hooks_config,
annotated,
dry_run,
skip_ci,
),
}
}
Expand All @@ -72,6 +85,7 @@ impl CocoGitto {
pre_release: Option<&str>,
hooks_config: Option<&str>,
dry_run: bool,
skip_ci: Option<String>,
) -> Result<()> {
self.pre_bump_checks()?;
// Get package bumps
Expand All @@ -96,8 +110,13 @@ impl CocoGitto {
self.bump_packages(pre_release, hooks_config, &bumps)?;

let sign = self.repository.gpg_sign();
self.repository
.commit("chore(version): bump packages", sign)?;

let skip_ci_pattern = skip_ci.unwrap_or(SETTINGS.skip_ci.clone().unwrap_or_default());

self.repository.commit(
&format!("chore(version): bump packages {}", skip_ci_pattern),
sign,
)?;

for bump in &bumps {
self.repository.create_tag(&bump.new_version.prefixed_tag)?;
Expand Down Expand Up @@ -131,6 +150,7 @@ impl CocoGitto {
hooks_config: Option<&str>,
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
) -> Result<()> {
self.pre_bump_checks()?;
// Get package bumps
Expand Down Expand Up @@ -227,8 +247,14 @@ impl CocoGitto {
self.bump_packages(pre_release, hooks_config, &bumps)?;

let sign = self.repository.gpg_sign();

let skip_ci_pattern = skip_ci.unwrap_or(SETTINGS.skip_ci.clone().unwrap_or_default());

self.repository.commit(
&format!("chore(version): {}", next_version.prefixed_tag),
&format!(
"chore(version): {} {}",
next_version.prefixed_tag, skip_ci_pattern
),
sign,
)?;

Expand Down Expand Up @@ -279,6 +305,7 @@ impl CocoGitto {
hooks_config: Option<&str>,
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
) -> Result<()> {
self.pre_bump_checks()?;
// Get package bumps
Expand Down Expand Up @@ -343,8 +370,13 @@ impl CocoGitto {
self.unwrap_or_stash_and_exit(&tag, hook_result);

let sign = self.repository.gpg_sign();
let skip_ci_pattern = skip_ci.unwrap_or(SETTINGS.skip_ci.clone().unwrap_or_default());

self.repository.commit(
&format!("chore(version): {}", next_version.prefixed_tag),
&format!(
"chore(version): {} {}",
next_version.prefixed_tag, skip_ci_pattern
),
sign,
)?;

Expand Down
7 changes: 6 additions & 1 deletion src/command/bump/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use semver::Prerelease;
use tera::Tera;

impl CocoGitto {
#[allow(clippy::too_many_arguments)]
pub fn create_package_version(
&mut self,
(package_name, package): (&str, &MonoRepoPackage),
Expand All @@ -23,6 +24,7 @@ impl CocoGitto {
hooks_config: Option<&str>,
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
) -> Result<()> {
self.pre_bump_checks()?;

Expand Down Expand Up @@ -82,8 +84,11 @@ impl CocoGitto {
self.unwrap_or_stash_and_exit(&tag, hook_result);

let sign = self.repository.gpg_sign();

let skip_ci_pattern = skip_ci.unwrap_or(SETTINGS.skip_ci.clone().unwrap_or_default());

self.repository
.commit(&format!("chore(version): {tag}"), sign)?;
.commit(&format!("chore(version): {tag} {}", skip_ci_pattern), sign)?;

if let Some(msg_tmpl) = annotated {
let mut context = tera::Context::new();
Expand Down
8 changes: 7 additions & 1 deletion src/command/bump/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl CocoGitto {
hooks_config: Option<&str>,
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
) -> Result<()> {
self.pre_bump_checks()?;

Expand Down Expand Up @@ -70,8 +71,13 @@ impl CocoGitto {

let sign = self.repository.gpg_sign();

let skip_ci_pattern = skip_ci.unwrap_or(SETTINGS.skip_ci.clone().unwrap_or_default());

self.repository.commit(
&format!("chore(version): {}", next_version.prefixed_tag),
&format!(
"chore(version): {} {}",
next_version.prefixed_tag, skip_ci_pattern
),
sign,
)?;

Expand Down
2 changes: 2 additions & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Settings {
pub monorepo_version_separator: Option<String>,
pub branch_whitelist: Vec<String>,
pub tag_prefix: Option<String>,
pub skip_ci: Option<String>,
pub pre_bump_hooks: Vec<String>,
pub post_bump_hooks: Vec<String>,
pub pre_package_bump_hooks: Vec<String>,
Expand All @@ -56,6 +57,7 @@ impl Default for Settings {
monorepo_version_separator: None,
branch_whitelist: vec![],
tag_prefix: None,
skip_ci: None,
pre_bump_hooks: vec![],
post_bump_hooks: vec![],
pre_package_bump_hooks: vec![],
Expand Down
Loading

0 comments on commit 92736aa

Please sign in to comment.