Skip to content

Commit

Permalink
test(config): add tests for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyclonit committed Apr 12, 2024
1 parent 71f7290 commit 339b9bd
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 7 deletions.
34 changes: 34 additions & 0 deletions .github/fixtures/test-v1-config-arg/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") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% 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" },
]
11 changes: 11 additions & 0 deletions .github/fixtures/test-v1-config-arg/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
git tag v0.1.0
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "feat(gui): add feature 2"
GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit --allow-empty -m "fix(gui): fix feature 2"
git tag v0.2.0
GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
31 changes: 31 additions & 0 deletions .github/fixtures/test-v1-config-arg/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

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

## [unreleased]

### Test

- Add tests

## [0.2.0] - 2022-04-06

### Bug Fixes

- Fix feature 2

### Features

- Add feature 2

## [0.1.0] - 2022-04-06

### Bug Fixes

- Fix feature 1

### Features

- Add feature 1

<!-- generated by git-cliff -->
38 changes: 38 additions & 0 deletions .github/fixtures/test-v1-config-meta/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[meta]
# The version of the config schema.
version = 1

[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") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% 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" },
]
11 changes: 11 additions & 0 deletions .github/fixtures/test-v1-config-meta/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2022-04-06 01:25:08" git commit --allow-empty -m "Initial commit"
GIT_COMMITTER_DATE="2022-04-06 01:25:09" git commit --allow-empty -m "feat: add feature 1"
GIT_COMMITTER_DATE="2022-04-06 01:25:10" git commit --allow-empty -m "fix: fix feature 1"
git tag v0.1.0
GIT_COMMITTER_DATE="2022-04-06 01:25:11" git commit --allow-empty -m "feat(gui): add feature 2"
GIT_COMMITTER_DATE="2022-04-06 01:25:12" git commit --allow-empty -m "fix(gui): fix feature 2"
git tag v0.2.0
GIT_COMMITTER_DATE="2022-04-06 01:25:13" git commit --allow-empty -m "test: add tests"
31 changes: 31 additions & 0 deletions .github/fixtures/test-v1-config-meta/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

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

## [unreleased]

### Test

- Add tests

## [0.2.0] - 2022-04-06

### Bug Fixes

- Fix feature 2

### Features

- Add feature 2

## [0.1.0] - 2022-04-06

### Bug Fixes

- Fix feature 1

### Features

- Add feature 1

<!-- generated by git-cliff -->
3 changes: 3 additions & 0 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ jobs:
- fixtures-name: test-custom-tag-pattern
command: --release-tags-pattern "alpha.*"
- fixtures-name: test-configure-from-cargo-toml
- fixtures-name: test-v1-config-meta
- fixtures-name: test-v1-config-arg
command: --config-version 1
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions git-cliff-core/src/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ mod test {
use super::*;
use crate::config::models_v2::{
Bump,
ChangelogConfig,
CommitConfig,
CommitParser,
CommitSortOrder,
ReleaseConfig,
Expand Down
8 changes: 6 additions & 2 deletions git-cliff-core/src/config/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub fn run(args: &MigrateArgs) -> Result<()> {
if !args.in_path.exists() {
return Err(Error::ArgumentError(format!(
"File {0} does not exist.",
&args.in_path.to_str().unwrap()
&args
.in_path
.to_str()
.expect("could not unwrap argument 'in_path'")
)));
}

Expand All @@ -36,7 +39,8 @@ pub fn run(args: &MigrateArgs) -> Result<()> {

// convert to the new config format
let new_config = super::models_v2::Config::from(old_config);
let new_toml = toml::to_string(&new_config).unwrap();
let new_toml = toml::to_string(&new_config)
.expect("could not serialize migrated config into toml");

// write the new config file
let mut new_config_file = fs::OpenOptions::new()
Expand Down
6 changes: 4 additions & 2 deletions git-cliff-core/src/config/models_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ impl Config {
tags_pattern: config_v1.git.tag_pattern,
skip_tags_pattern: config_v1.git.ignore_tags,
order_by: Some(
if config_v1.git.topo_order.is_some() &&
config_v1.git.topo_order.unwrap()
if config_v1
.git
.topo_order
.is_some_and(|topo_order| topo_order)
{
TagsOrderBy::Topology
} else {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/configuration/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Example:

- `git-cliff migrate-config --in cliff.toml --out cliff-new.toml`

## Backwards compatability
## Backwards compatibility
While configuration version 1 is deprecated, the cli argument `--config-version` can be used to make git-cliff use old configuration files. Keep in mind that new features might not be supported when using the old configuration format.

Example:
Expand Down

0 comments on commit 339b9bd

Please sign in to comment.