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 commit1499e40df2
. 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 commit02717efa19
. Signed-off-by: Bukowa <gitbukowa@gmail.com> --------- Signed-off-by: Bukowa <gitbukowa@gmail.com>
This commit is contained in:
parent
403d3dcd32
commit
734150020e
37
.github/fixtures/test-bump-initial-tag-cli-arg/cliff.toml
vendored
Normal file
37
.github/fixtures/test-bump-initial-tag-cli-arg/cliff.toml
vendored
Normal 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"
|
4
.github/fixtures/test-bump-initial-tag-cli-arg/commit.sh
vendored
Executable file
4
.github/fixtures/test-bump-initial-tag-cli-arg/commit.sh
vendored
Executable 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"
|
11
.github/fixtures/test-bump-initial-tag-cli-arg/expected.md
vendored
Normal file
11
.github/fixtures/test-bump-initial-tag-cli-arg/expected.md
vendored
Normal 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 -->
|
34
.github/fixtures/test-bump-initial-tag-default/cliff.toml
vendored
Normal file
34
.github/fixtures/test-bump-initial-tag-default/cliff.toml
vendored
Normal 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" },
|
||||
]
|
4
.github/fixtures/test-bump-initial-tag-default/commit.sh
vendored
Executable file
4
.github/fixtures/test-bump-initial-tag-default/commit.sh
vendored
Executable 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"
|
11
.github/fixtures/test-bump-initial-tag-default/expected.md
vendored
Normal file
11
.github/fixtures/test-bump-initial-tag-default/expected.md
vendored
Normal 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 -->
|
37
.github/fixtures/test-bump-initial-tag/cliff.toml
vendored
Normal file
37
.github/fixtures/test-bump-initial-tag/cliff.toml
vendored
Normal 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"
|
4
.github/fixtures/test-bump-initial-tag/commit.sh
vendored
Executable file
4
.github/fixtures/test-bump-initial-tag/commit.sh
vendored
Executable 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"
|
11
.github/fixtures/test-bump-initial-tag/expected.md
vendored
Normal file
11
.github/fixtures/test-bump-initial-tag/expected.md
vendored
Normal 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 -->
|
6
.github/workflows/test-fixtures.yml
vendored
6
.github/workflows/test-fixtures.yml
vendored
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
})?
|
||||
);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user