From d0e907b7a25d1e082ab6c38a515b7f3fc4bd2f51 Mon Sep 17 00:00:00 2001 From: Christopher Cyclonit Klinge Date: Sun, 24 Mar 2024 11:01:07 +0100 Subject: [PATCH] test(config): add test fixtures for backwards compatability --- .github/actions/run-fixtures-test/action.yml | 126 ++++++++++-------- .../fixtures/test-bump-version/cliff.v1.toml | 27 ++++ 2 files changed, 99 insertions(+), 54 deletions(-) create mode 100644 .github/fixtures/test-bump-version/cliff.v1.toml diff --git a/.github/actions/run-fixtures-test/action.yml b/.github/actions/run-fixtures-test/action.yml index d733fe7041..caf148c77c 100644 --- a/.github/actions/run-fixtures-test/action.yml +++ b/.github/actions/run-fixtures-test/action.yml @@ -1,54 +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/<>/$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 --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/<>/$current_date/g" expected.md + diff --strip-trailing-cr output.md expected.md + shell: bash + + - 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/<>/$current_date/g" expected.md + diff --strip-trailing-cr output.md expected.md + shell: bash diff --git a/.github/fixtures/test-bump-version/cliff.v1.toml b/.github/fixtures/test-bump-version/cliff.v1.toml new file mode 100644 index 0000000000..ec2fc39132 --- /dev/null +++ b/.github/fixtures/test-bump-version/cliff.v1.toml @@ -0,0 +1,27 @@ +[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 %} + - {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing whitespace from the templates +trim = true