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 15, 2024
1 parent bd225f3 commit fe6d2bd
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 173 deletions.
146 changes: 72 additions & 74 deletions .github/actions/run-fixtures-test/action.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,72 @@
name: Run a fixtures test
description: Run a fixtures test

inputs:
fixtures-dir:
description: Path to the fixtures directory
required: true
command:
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
steps:
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Install git-cliff
run: cargo install --path git-cliff/
shell: bash

- name: Set git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
shell: bash

- name: Create commits and tags
working-directory: ${{ inputs.fixtures-dir }}
run: |
git init
./commit.sh
shell: bash

- name: Generate a changelog
working-directory: ${{ inputs.fixtures-dir }}
run: git cliff --config cliff.toml ${{ inputs.command }} > output.md
shell: bash

- 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/<<DATE>>/$current_date/g" expected.md
diff --strip-trailing-cr output.md expected.md
shell: bash

# test backwards compatibility using v1 confiuration

- name: Generate a chanlog using v1 configuration
if: ${{ hashFiles(format('{0}/cliff.v1.toml', inputs.fixtures-dir)) }}
working-directory: ${{ inputs.fixtures-dir }}
run: git-cliff --config cliff.v1.toml --config-version 1 ${{ inputs.command }} > output.md
shell: bash

- name: Compare the v1 configuration output with the expected output
if: ${{ hashFiles(format('{0}/cliff.v1.toml', inputs.fixtures-dir)) }}
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/<<DATE>>/$current_date/g" expected.md
diff --strip-trailing-cr output.md expected.md
shell: bash
name: Run a fixtures test
description: Run a fixtures test

inputs:
fixtures-dir:
description: Path to the fixtures directory
required: true
command:
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
steps:
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Install git-cliff
run: cargo install --path git-cliff/
shell: bash

- name: Set git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
shell: bash

- name: Create commits and tags
working-directory: ${{ inputs.fixtures-dir }}
run: |
git init
./commit.sh
shell: bash

- name: Generate a changelog
working-directory: ${{ inputs.fixtures-dir }}
run: git cliff -v --config cliff.toml ${{ inputs.command }} --output output.md
shell: bash

- name: Compare the output with the expected output
working-directory: ${{ inputs.fixtures-dir }}
env:
IN_DATE_FORMAT: ${{ inputs.date-format }}
run: |
current_date=$(date +"$IN_DATE_FORMAT")
sed -i "s/<<DATE>>/$current_date/g" expected.md
git diff --no-index expected.md output.md
shell: bash

# test backwards compatibility using v1 confiuration

- name: Generate a chanlog using v1 configuration
if: ${{ hashFiles(format('{0}/cliff.v1.toml', inputs.fixtures-dir)) }}
working-directory: ${{ inputs.fixtures-dir }}
run: git-cliff -v --config cliff.v1.toml --config-version 1 ${{ inputs.command }} --output output.md
shell: bash

- name: Compare the v1 configuration output with the expected output
if: ${{ hashFiles(format('{0}/cliff.v1.toml', inputs.fixtures-dir)) }}
working-directory: ${{ inputs.fixtures-dir }}
env:
IN_DATE_FORMAT: ${{ inputs.date-format }}
run: |
current_date=$(date +"$IN_DATE_FORMAT")
sed -i "s/<<DATE>>/$current_date/g" expected.md
git diff --no-index expected.md output.md
shell: bash
20 changes: 10 additions & 10 deletions .github/fixtures/test-configure-from-cargo-toml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ version = "0.1.0"
edition = "2021"

[package.metadata.git-cliff.changelog]
# changelog header
# A static header for the changelog.
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 = """
# A Tera template to be rendered for each release in the changelog (see https://keats.github.io/tera/docs/#introduction).
body_template = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
Expand All @@ -24,15 +23,16 @@ body = """
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
# A Tera template to be rendered as the changelog's footer (see https://keats.github.io/tera/docs/#introduction).
footer_template = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true
# Whether to remove leading and trailing whitespaces from all lines of the changelog's body.
trim_body_whitespace = true

[package.metadata.git-cliff.git]
# regex for parsing and grouping commits
[package.metadata.git-cliff.commit]
# A list of parsers using regex for extracting data from the commit message.
# Sets the commits' `group` and `scope` and can decide to exclude commits from further processing.
commit_parsers = [
{ message = "^feat", group = "Features", default_scope = "app" },
{ message = "^fix", group = "Bug Fixes", scope = "cli" },
Expand Down
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
Loading

0 comments on commit fe6d2bd

Please sign in to comment.