diff --git a/.github/actions/run-fixtures-test/action.yml b/.github/actions/run-fixtures-test/action.yml index 6b284f53a9..d733fe7041 100644 --- a/.github/actions/run-fixtures-test/action.yml +++ b/.github/actions/run-fixtures-test/action.yml @@ -9,6 +9,10 @@ inputs: description: The git-cliff command to run required: false default: "" + date-format: + description: The date format to use + required: false + default: "%Y-%m-%d" runs: using: composite @@ -40,7 +44,11 @@ runs: - name: Compare the output with the expected output working-directory: ${{ inputs.fixtures-dir }} + env: + IN_DATE_FORMAT: ${{ inputs.date-format }} run: | cat output.md + current_date=$(date +"$IN_DATE_FORMAT") + sed -i "s/<>/$current_date/g" expected.md diff --strip-trailing-cr output.md expected.md shell: bash diff --git a/.github/fixtures/test-keep-a-changelog-links-current-arg/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-current-arg/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-current-arg/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-current-arg/commit.sh b/.github/fixtures/test-keep-a-changelog-links-current-arg/commit.sh new file mode 100755 index 0000000000..1ad3a38959 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-current-arg/commit.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-24 01:23:46" git commit --allow-empty -m "feat: add feature 2" +git tag v0.2.0 diff --git a/.github/fixtures/test-keep-a-changelog-links-current-arg/expected.md b/.github/fixtures/test-keep-a-changelog-links-current-arg/expected.md new file mode 100644 index 0000000000..259dfff457 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-current-arg/expected.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.0](https://github.com/dummy/dummy/compare/v0.1.0...v0.2.0) - 2021-01-24 + +### Added + +- Add feature 2 + + diff --git a/.github/fixtures/test-keep-a-changelog-links-latest-arg/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-latest-arg/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-latest-arg/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-latest-arg/commit.sh b/.github/fixtures/test-keep-a-changelog-links-latest-arg/commit.sh new file mode 100755 index 0000000000..0e39c70138 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-latest-arg/commit.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-24 01:23:46" git commit --allow-empty -m "feat: add feature 2" +git tag v0.2.0 + +GIT_COMMITTER_DATE="2021-01-25 01:23:47" git commit --allow-empty -m "fix: fix feature 1" diff --git a/.github/fixtures/test-keep-a-changelog-links-latest-arg/expected.md b/.github/fixtures/test-keep-a-changelog-links-latest-arg/expected.md new file mode 100644 index 0000000000..259dfff457 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-latest-arg/expected.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.0](https://github.com/dummy/dummy/compare/v0.1.0...v0.2.0) - 2021-01-24 + +### Added + +- Add feature 2 + + diff --git a/.github/fixtures/test-keep-a-changelog-links-no-tags/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-no-tags/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-no-tags/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-no-tags/commit.sh b/.github/fixtures/test-keep-a-changelog-links-no-tags/commit.sh new file mode 100755 index 0000000000..d70bb68148 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-no-tags/commit.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" + +GIT_COMMITTER_DATE="2021-01-24 01:23:46" git commit --allow-empty -m "feat: add feature 2" + +GIT_COMMITTER_DATE="2021-01-25 01:23:47" git commit --allow-empty -m "fix: fix feature 1" diff --git a/.github/fixtures/test-keep-a-changelog-links-no-tags/expected.md b/.github/fixtures/test-keep-a-changelog-links-no-tags/expected.md new file mode 100644 index 0000000000..c721d4b523 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-no-tags/expected.md @@ -0,0 +1,19 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- Add feature 1 +- Add feature 2 + +### Fixed + +- Fix feature 1 + + diff --git a/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/commit.sh b/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/commit.sh new file mode 100755 index 0000000000..7220ce5ed4 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/commit.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "Initial commit" + +GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add feature 1" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-25 01:23:47" git commit --allow-empty -m "fix: fix feature 1" diff --git a/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/expected.md b/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/expected.md new file mode 100644 index 0000000000..250f1b0bb6 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-one-tag-bump-arg/expected.md @@ -0,0 +1,20 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.1](https://github.com/dummy/dummy/compare/v0.1.0...0.1.1) - <> + +### Fixed + +- Fix feature 1 + +## [0.1.0](https://github.com/dummy/dummy/releases/tag/v0.1.0) - 2021-01-23 + +### Added + +- Add feature 1 + + diff --git a/.github/fixtures/test-keep-a-changelog-links-one-tag/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-one-tag/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-one-tag/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-one-tag/commit.sh b/.github/fixtures/test-keep-a-changelog-links-one-tag/commit.sh new file mode 100755 index 0000000000..23e2249480 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-one-tag/commit.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" +git tag v0.1.0 diff --git a/.github/fixtures/test-keep-a-changelog-links-one-tag/expected.md b/.github/fixtures/test-keep-a-changelog-links-one-tag/expected.md new file mode 100644 index 0000000000..11d38addf1 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-one-tag/expected.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.0](https://github.com/dummy/dummy/releases/tag/v0.1.0) - 2021-01-23 + +### Added + +- Add feature 1 + + diff --git a/.github/fixtures/test-keep-a-changelog-links-tag-arg/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-tag-arg/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-tag-arg/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-tag-arg/commit.sh b/.github/fixtures/test-keep-a-changelog-links-tag-arg/commit.sh new file mode 100755 index 0000000000..0e39c70138 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-tag-arg/commit.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-24 01:23:46" git commit --allow-empty -m "feat: add feature 2" +git tag v0.2.0 + +GIT_COMMITTER_DATE="2021-01-25 01:23:47" git commit --allow-empty -m "fix: fix feature 1" diff --git a/.github/fixtures/test-keep-a-changelog-links-tag-arg/expected.md b/.github/fixtures/test-keep-a-changelog-links-tag-arg/expected.md new file mode 100644 index 0000000000..348dc2f827 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-tag-arg/expected.md @@ -0,0 +1,26 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.3.0](https://github.com/dummy/dummy/compare/v0.2.0...v0.3.0) - <> + +### Fixed + +- Fix feature 1 + +## [0.2.0](https://github.com/dummy/dummy/compare/v0.1.0...v0.2.0) - 2021-01-24 + +### Added + +- Add feature 2 + +## [0.1.0](https://github.com/dummy/dummy/releases/tag/v0.1.0) - 2021-01-23 + +### Added + +- Add feature 1 + + diff --git a/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/cliff.toml b/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/cliff.toml new file mode 100644 index 0000000000..c96c37331f --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/cliff.toml @@ -0,0 +1,77 @@ +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/dummy/dummy/releases/tag/{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ + {% endif %}\ +{% else %}\ + {% if previous %}\ + {% if previous.version %}\ + ## [Unreleased](https://github.com/dummy/dummy/compare/{{ previous.version }}...HEAD) + {% else %}\ + ## [Unreleased] + {% endif %}\ + {% else %}\ + ## [Unreleased] + {% endif %}\ +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | upper_first }} + {% for commit in commits %} + - {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^.*: add", group = "Added" }, + { message = "^.*: support", group = "Added" }, + { message = "^.*: remove", group = "Removed" }, + { message = "^.*: delete", group = "Removed" }, + { message = "^test", group = "Fixed" }, + { message = "^fix", group = "Fixed" }, + { message = "^.*: fix", group = "Fixed" }, + { message = "^.*", group = "Changed" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# glob pattern for matching git tags +tag_pattern = "v[0-9]*" +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" diff --git a/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/commit.sh b/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/commit.sh new file mode 100755 index 0000000000..0e39c70138 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/commit.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -e + +GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1" +git tag v0.1.0 + +GIT_COMMITTER_DATE="2021-01-24 01:23:46" git commit --allow-empty -m "feat: add feature 2" +git tag v0.2.0 + +GIT_COMMITTER_DATE="2021-01-25 01:23:47" git commit --allow-empty -m "fix: fix feature 1" diff --git a/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/expected.md b/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/expected.md new file mode 100644 index 0000000000..dfaf58eaf7 --- /dev/null +++ b/.github/fixtures/test-keep-a-changelog-links-unreleased-arg/expected.md @@ -0,0 +1,14 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased](https://github.com/dummy/dummy/compare/v0.2.0...HEAD) + +### Fixed + +- Fix feature 1 + + diff --git a/.github/fixtures/test-keep-a-changelog-links/cliff.toml b/.github/fixtures/test-keep-a-changelog-links/cliff.toml index c907a04dfa..59ef355cf0 100644 --- a/.github/fixtures/test-keep-a-changelog-links/cliff.toml +++ b/.github/fixtures/test-keep-a-changelog-links/cliff.toml @@ -1,5 +1,3 @@ -# configuration file for git-cliff (0.1.0) - [changelog] # changelog header header = """ diff --git a/.github/workflows/test-fixtures.yml b/.github/workflows/test-fixtures.yml index b68546298b..11fba67d6a 100644 --- a/.github/workflows/test-fixtures.yml +++ b/.github/workflows/test-fixtures.yml @@ -32,12 +32,34 @@ jobs: - fixtures-name: test-limit-commits - fixtures-name: test-skip-breaking-changes - fixtures-name: test-split-commits - - fixtures-name: test-keep-a-changelog-links - fixtures-name: test-bump-version command: --bump - fixtures-name: test-bumped-version command: --bumped-version - fixtures-name: test-footer-template + - fixtures-name: test-keep-a-changelog-links + - fixtures-name: test-keep-a-changelog-links-current-arg + command: --current + - fixtures-name: test-keep-a-changelog-links-current-arg + command: --latest + - fixtures-name: test-keep-a-changelog-links-latest-arg + command: --latest + - fixtures-name: test-keep-a-changelog-links-no-tags + - fixtures-name: test-keep-a-changelog-links-no-tags + command: --unreleased + - fixtures-name: test-keep-a-changelog-links-no-tags + command: --latest + - fixtures-name: test-keep-a-changelog-links-no-tags + command: --current + - fixtures-name: test-keep-a-changelog-links-one-tag + - fixtures-name: test-keep-a-changelog-links-tag-arg + command: --tag v0.3.0 + - fixtures-name: test-keep-a-changelog-links-unreleased-arg + command: --unreleased + - fixtures-name: test-keep-a-changelog-links-unreleased-arg + command: --latest --unreleased + - fixtures-name: test-keep-a-changelog-links-one-tag-bump-arg + command: --bump steps: - name: Checkout uses: actions/checkout@v4 diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index daa347007b..4e2f2b8f2d 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -191,6 +191,7 @@ fn process_repository<'a>( let mut releases = vec![Release::default()]; let mut release_index = 0; let mut previous_release = Release::default(); + let mut first_processed_tag = None; for git_commit in commits.into_iter().rev() { let commit = Commit::from(&git_commit); let commit_id = commit.id.to_string(); @@ -210,6 +211,9 @@ fn process_repository<'a>( } else { git_commit.time().seconds() }; + if first_processed_tag.is_none() { + first_processed_tag = Some(tag); + } previous_release.previous = None; releases[release_index].previous = Some(Box::new(previous_release)); previous_release = releases[release_index].clone(); @@ -234,16 +238,28 @@ fn process_repository<'a>( } } - // Set the previous release if needed. - if args.latest || args.unreleased { - let sub = if args.latest || args.tag.is_some() { - 2 - } else { - 1 - }; - if let Some((commit_id, version)) = - tags.len().checked_sub(sub).and_then(|v| tags.get_index(v)) - { + // Set the previous release if the first release does not have one set. + if !releases.is_empty() && + releases + .first() + .and_then(|r| r.previous.as_ref()) + .and_then(|p| p.version.as_ref()) + .is_none() + { + // Get the previous tag of the first processed tag in the release loop. + let first_tag = first_processed_tag + .map(|tag| { + tags.iter() + .enumerate() + .find(|(_, (_, v))| v == &tag) + .and_then(|(i, _)| i.checked_sub(1)) + .and_then(|i| tags.get_index(i)) + }) + .or_else(|| Some(tags.last())) + .flatten(); + + // Set the previous release if the first tag is found. + if let Some((commit_id, version)) = first_tag { let previous_release = Release { commit_id: Some(commit_id.to_string()), version: Some(version.to_string()),