Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bump): support setting the initial_tag #701

Merged
merged 13 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -68,6 +68,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
6 changes: 4 additions & 2 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,16 @@ impl<'a> Changelog<'a> {
serde_json::to_value(self.config.remote.clone())?,
);
#[cfg(feature = "github")]
let (github_commits, github_pull_requests) = if self.config.remote.github.is_set() {
let (github_commits, github_pull_requests) = if self.config.remote.github.is_set()
{
self.get_github_metadata()
.expect("Could not get github metadata")
} else {
(vec![], vec![])
};
#[cfg(feature = "gitlab")]
let (gitlab_commits, gitlab_merge_request) = if self.config.remote.gitlab.is_set() {
let (gitlab_commits, gitlab_merge_request) = if self.config.remote.gitlab.is_set()
{
bukowa marked this conversation as resolved.
Show resolved Hide resolved
self.get_gitlab_metadata()
.expect("Could not get gitlab metadata")
} else {
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 @@ -192,6 +192,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 @@ -114,10 +114,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 @@ -239,6 +249,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 @@ -259,6 +270,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 @@ -279,6 +291,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 @@ -299,6 +312,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 @@ -473,6 +473,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
Loading