Skip to content

Commit

Permalink
feat(bump): support setting the initial_tag (#701)
Browse files Browse the repository at this point in the history
* feat: add `initial_tag` to `bump` - allows changing from default `0.1.0` when using `bump` and no tags are found

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(tests): add `test-bump-initial-tag-default`

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(tests): add `test-bump-initial-tag-cli-arg`

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(tests): add `test-bump-initial-tag`

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(ci,tests): add tests to `text-fixtures.yml`

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(ci,tests): check if cli arg overwrites config file

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(ci,tests): fix chmod for commit files

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(docs): add cli flag to args.md

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(lint): rustfmt

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* chore(lint): fix formatting

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* Revert "chore(docs): add cli flag to args.md"

This reverts commit 1499e40.

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* feat(cli,args): remove `bump-initial-flag` and use `tag`

Signed-off-by: Bukowa <gitbukowa@gmail.com>

* Revert "chore(lint): fix formatting"

This reverts commit 02717ef.

Signed-off-by: Bukowa <gitbukowa@gmail.com>

---------

Signed-off-by: Bukowa <gitbukowa@gmail.com>
  • Loading branch information
bukowa authored Jun 15, 2024
1 parent 403d3dc commit 7341500
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 4 deletions.
37 changes: 37 additions & 0 deletions .github/fixtures/test-bump-initial-tag-cli-arg/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}]
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true

[git]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features", default_scope = "app" },
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
]

[bump]
initial_tag = "asdasd"
4 changes: 4 additions & 0 deletions .github/fixtures/test-bump-initial-tag-cli-arg/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
11 changes: 11 additions & 0 deletions .github/fixtures/test-bump-initial-tag-cli-arg/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

## [2.1.1]

### Test

- Add tests

<!-- generated by git-cliff -->
34 changes: 34 additions & 0 deletions .github/fixtures/test-bump-initial-tag-default/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}]
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true

[git]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features", default_scope = "app" },
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
]
4 changes: 4 additions & 0 deletions .github/fixtures/test-bump-initial-tag-default/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
11 changes: 11 additions & 0 deletions .github/fixtures/test-bump-initial-tag-default/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

## [0.1.0]

### Test

- Add tests

<!-- generated by git-cliff -->
37 changes: 37 additions & 0 deletions .github/fixtures/test-bump-initial-tag/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}]
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true

[git]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "Features", default_scope = "app" },
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
]

[bump]
initial_tag = "1.15.5"
4 changes: 4 additions & 0 deletions .github/fixtures/test-bump-initial-tag/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
11 changes: 11 additions & 0 deletions .github/fixtures/test-bump-initial-tag/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

All notable changes to this project will be documented in this file.

## [1.15.5]

### Test

- Add tests

<!-- generated by git-cliff -->
6 changes: 6 additions & 0 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ jobs:
- fixtures-name: test-custom-tag-pattern
command: --tag-pattern "alpha.*"
- fixtures-name: test-configure-from-cargo-toml
- fixtures-name: test-bump-initial-tag
command: --bump
- fixtures-name: test-bump-initial-tag-default
command: --bump
- fixtures-name: test-bump-initial-tag-cli-arg
command: --bump --tag=2.1.1
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions git-cliff-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ pub struct Bump {
/// - A minor version update if the major version is 0.
/// - A major version update otherwise.
pub breaking_always_bump_major: Option<bool>,

/// Configures the initial version of the project.
///
/// When set, the version will be set to this value if no tags are found.
pub initial_tag: Option<String>,
}

/// Parser for grouping commits.
Expand Down
22 changes: 18 additions & 4 deletions git-cliff-core/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,20 @@ impl<'a> Release<'a> {
Ok(next_version)
}
}
None => {
warn!("No releases found, using 0.1.0 as the next version.");
Ok(String::from("0.1.0"))
}
None => match config.initial_tag.clone() {
Some(tag) => {
warn!(
"No releases found, using initial tag '{}' as the next \
version.",
tag
);
Ok(tag)
}
None => {
warn!("No releases found, using 0.1.0 as the next version.");
Ok(String::from("0.1.0"))
}
},
}
}
}
Expand Down Expand Up @@ -249,6 +259,7 @@ mod test {
release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(false),
breaking_always_bump_major: Some(false),
initial_tag: None,
})?;
assert_eq!(expected_version, &next_version);
}
Expand All @@ -269,6 +280,7 @@ mod test {
release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(true),
breaking_always_bump_major: Some(false),
initial_tag: None,
})?;
assert_eq!(expected_version, &next_version);
}
Expand All @@ -289,6 +301,7 @@ mod test {
release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(false),
breaking_always_bump_major: Some(true),
initial_tag: None,
})?;
assert_eq!(expected_version, &next_version);
}
Expand All @@ -309,6 +322,7 @@ mod test {
empty_release.calculate_next_version_with_config(&Bump {
features_always_bump_minor: Some(features_always_bump_minor),
breaking_always_bump_major: Some(breaking_always_bump_major),
initial_tag: None,
})?
);
}
Expand Down
4 changes: 4 additions & 0 deletions git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ pub fn run(mut args: Opt) -> Result<()> {
config.git.tag_pattern.clone_from(&args.tag_pattern);
}

if args.tag.is_some() {
config.bump.initial_tag.clone_from(&args.tag);
}

// Process the repositories.
let repositories = args.repository.clone().unwrap_or(vec![env::current_dir()?]);
let mut releases = Vec::<Release>::new();
Expand Down

0 comments on commit 7341500

Please sign in to comment.