1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-09-11 15:05:30 +03:00

feat(bump): support setting the initial_tag (#701)

* 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 1499e40df2.

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 02717efa19.

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

---------

Signed-off-by: Bukowa <gitbukowa@gmail.com>
This commit is contained in:
Buk Bukowski 2024-06-15 20:22:23 +02:00 committed by GitHub
parent 403d3dcd32
commit 734150020e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 186 additions and 4 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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 -->

View File

@ -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" },
]

View File

@ -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"

View File

@ -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 -->

View File

@ -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"

View File

@ -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"

View File

@ -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 -->

View File

@ -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

View File

@ -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.

View File

@ -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,
})?
);
}

View File

@ -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();