diff --git a/.github/fixtures/test-bump-initial-tag-cli-arg/cliff.toml b/.github/fixtures/test-bump-initial-tag-cli-arg/cliff.toml new file mode 100644 index 0000000000..d001b840fd --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag-cli-arg/cliff.toml @@ -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 = """ + +""" +# 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" \ No newline at end of file diff --git a/.github/fixtures/test-bump-initial-tag-cli-arg/commit.sh b/.github/fixtures/test-bump-initial-tag-cli-arg/commit.sh new file mode 100755 index 0000000000..8897f4d8ef --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag-cli-arg/commit.sh @@ -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" diff --git a/.github/fixtures/test-bump-initial-tag-cli-arg/expected.md b/.github/fixtures/test-bump-initial-tag-cli-arg/expected.md new file mode 100644 index 0000000000..f7e325a493 --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag-cli-arg/expected.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [2.1.1] + +### Test + +- Add tests + + diff --git a/.github/fixtures/test-bump-initial-tag-default/cliff.toml b/.github/fixtures/test-bump-initial-tag-default/cliff.toml new file mode 100644 index 0000000000..5da431c6c3 --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag-default/cliff.toml @@ -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 = """ + +""" +# 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" }, +] diff --git a/.github/fixtures/test-bump-initial-tag-default/commit.sh b/.github/fixtures/test-bump-initial-tag-default/commit.sh new file mode 100755 index 0000000000..8897f4d8ef --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag-default/commit.sh @@ -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" diff --git a/.github/fixtures/test-bump-initial-tag-default/expected.md b/.github/fixtures/test-bump-initial-tag-default/expected.md new file mode 100644 index 0000000000..8b2acf53ac --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag-default/expected.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [0.1.0] + +### Test + +- Add tests + + diff --git a/.github/fixtures/test-bump-initial-tag/cliff.toml b/.github/fixtures/test-bump-initial-tag/cliff.toml new file mode 100644 index 0000000000..38080e482c --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag/cliff.toml @@ -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 = """ + +""" +# 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" \ No newline at end of file diff --git a/.github/fixtures/test-bump-initial-tag/commit.sh b/.github/fixtures/test-bump-initial-tag/commit.sh new file mode 100755 index 0000000000..8897f4d8ef --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag/commit.sh @@ -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" diff --git a/.github/fixtures/test-bump-initial-tag/expected.md b/.github/fixtures/test-bump-initial-tag/expected.md new file mode 100644 index 0000000000..d3b19c4381 --- /dev/null +++ b/.github/fixtures/test-bump-initial-tag/expected.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [1.15.5] + +### Test + +- Add tests + + diff --git a/.github/workflows/test-fixtures.yml b/.github/workflows/test-fixtures.yml index 3bb433671b..59fe955ec9 100644 --- a/.github/workflows/test-fixtures.yml +++ b/.github/workflows/test-fixtures.yml @@ -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 diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index a2bbc56e47..0d2a855328 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -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, + + /// 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, } /// Parser for grouping commits. diff --git a/git-cliff-core/src/release.rs b/git-cliff-core/src/release.rs index 1cea7580b6..55a7793c6a 100644 --- a/git-cliff-core/src/release.rs +++ b/git-cliff-core/src/release.rs @@ -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")) + } + }, } } } @@ -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); } @@ -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); } @@ -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); } @@ -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, })? ); } diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index 3939919a41..2d43d2fdb5 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -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::::new();