Skip to content

Commit

Permalink
feat(changelog, config)!: replace --topo-order by --date-order (#58)
Browse files Browse the repository at this point in the history
* feat(changelog, config)!: replace --topo-order by --date-order

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* ci: simplify test-fixtures workflow

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* ci: add fixtures tests of topo_order and date_order

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* remove unnecessary checkout

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* remove cargo run

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* set GIT_COMMITTER_DATE for each commit

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* add a test for --date-order arg

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* fix git config style

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* remove an unnecessary period

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* apply #60

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* minify the config files for tests

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* fix git config style

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* fix styles of expected.md

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* make some steps one-line

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* remove footers

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* remove newlines

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>

* Revert "remove newlines"

This reverts commit 8028815.

* Revert "remove footers"

This reverts commit 3d334cc.

* add trim and footer

Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp>
  • Loading branch information
kenji-miyake authored Feb 12, 2022
1 parent 0293b28 commit a3980f4
Show file tree
Hide file tree
Showing 28 changed files with 301 additions and 127 deletions.
50 changes: 50 additions & 0 deletions .github/actions/run-fixtures-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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: ""

runs:
using: composite
steps:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- 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 }}
run: |
cat output.md
diff --strip-trailing-cr output.md expected.md
shell: bash
59 changes: 0 additions & 59 deletions .github/fixtures/cliff.toml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/fixtures/test-date-order-arg/cliff.toml
Original file line number Diff line number Diff line change
@@ -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://tera.netlify.app/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 %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""
12 changes: 12 additions & 0 deletions .github/fixtures/test-date-order-arg/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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-23 01:23:46" git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0

git checkout v0.1.0
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: fix feature 1"
git tag v0.1.1
11 changes: 11 additions & 0 deletions .github/fixtures/test-date-order-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.

## [0.1.1] - 2021-01-23

### Feat

- Fix feature 1

<!-- generated by git-cliff -->
30 changes: 30 additions & 0 deletions .github/fixtures/test-date-order/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[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://tera.netlify.app/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 %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""

[git]
date_order = true
12 changes: 12 additions & 0 deletions .github/fixtures/test-date-order/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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-23 01:23:46" git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0

git checkout v0.1.0
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: fix feature 1"
git tag v0.1.1
11 changes: 11 additions & 0 deletions .github/fixtures/test-date-order/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.1] - 2021-01-23

### Feat

- Fix feature 1

<!-- generated by git-cliff -->
33 changes: 33 additions & 0 deletions .github/fixtures/test-ignore-tags/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[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://tera.netlify.app/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 %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""

[git]
# regex for skipping tags
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = "v.*-beta.*"
15 changes: 15 additions & 0 deletions .github/fixtures/test-ignore-tags/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -e

GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add skip feature"
git tag v0.1.0-beta.1

GIT_COMMITTER_DATE="2021-01-23 01:23:46" git commit --allow-empty -m "feat: add feature 1"
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: fix feature 1"
git tag v0.1.0

GIT_COMMITTER_DATE="2021-01-23 01:23:48" git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0-beta.1

GIT_COMMITTER_DATE="2021-01-23 01:23:49" git commit --allow-empty -m "feat: add feature 3"
git tag v0.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ All notable changes to this project will be documented in this file.

## [0.2.0] - 2021-01-23

### Features
### Feat

- Add feature 2
- Add feature 3

## [0.1.0] - 2021-01-23

### Features
### Feat

- Add feature 1
- Fix feature 1
Expand Down
27 changes: 27 additions & 0 deletions .github/fixtures/test-topo-order/cliff.toml
Original file line number Diff line number Diff line change
@@ -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://tera.netlify.app/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 %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""
12 changes: 12 additions & 0 deletions .github/fixtures/test-topo-order/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/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-23 01:23:46" git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0

git checkout v0.1.0
GIT_COMMITTER_DATE="2021-01-23 01:23:47" git commit --allow-empty -m "feat: fix feature 1"
git tag v0.1.1
11 changes: 11 additions & 0 deletions .github/fixtures/test-topo-order/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.2.0] - 2021-01-23

### Feat

- Add feature 2

<!-- generated by git-cliff -->
50 changes: 16 additions & 34 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,23 @@ jobs:
test-fixtures:
name: Test fixtures
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- fixtures-name: test-ignore-tags
- fixtures-name: test-topo-order
command: --latest
- fixtures-name: test-date-order
command: --latest
- fixtures-name: test-date-order-arg
command: --latest --date-order
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run a fixtures test
uses: ./.github/actions/run-fixtures-test
with:
fetch-depth: 0
- name: Set git config
run: |
git config --global user.name github-actions
git config --global user.email github-actions@github.com
- name: Create commits and tags
run: |
mkdir .workspace && cd .workspace && git init
git commit --allow-empty -m "Initial commit"
git commit --allow-empty -m "feat: add skip feature"
git tag v0.1.0-beta.1
git commit --allow-empty -m "feat: add feature 1"
git commit --allow-empty -m "feat: fix feature 1"
git tag v0.1.0
git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0-beta.1
git commit --allow-empty -m "feat: add feature 3"
git tag v0.2.0
env:
GIT_AUTHOR_DATE: "2021-01-23 01:23:45"
GIT_COMMITTER_DATE: "2021-01-23 01:23:45"
- name: Generate a changelog
run: |
cd .workspace
fixtures_dir=${GITHUB_WORKSPACE}/.github/fixtures
docker run -t \
-v "$(pwd)/.git":/app/ \
-v "$fixtures_dir/cliff.toml":/app/cliff.toml \
orhunp/git-cliff:latest > "$fixtures_dir/output.md"
- name: Compare the output with the expected output
run: |
cd ${GITHUB_WORKSPACE}/.github/fixtures
cat output.md
diff --strip-trailing-cr output.md expected.md
fixtures-dir: .github/fixtures/${{ matrix.fixtures-name }}
command: ${{ matrix.command }}
Loading

0 comments on commit a3980f4

Please sign in to comment.