Skip to content

Commit

Permalink
docs(fixtures): add instructions for adding new fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Dec 6, 2023
1 parent 4bee628 commit 8290769
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Fixtures

[Test fixtures](https://en.wikipedia.org/wiki/Test_fixture) are a way of testing the `git-cliff`'s functionality against a configuration file (`cliff.toml`) and asserting the output (`expected.md`).

They are being [run](https://github.com/orhun/git-cliff/actions/workflows/test-fixtures.yml) as a part of the GitHub Actions and the workflow file can be viewed [here](../workflows/test-fixtures.yml).

## Adding new fixtures

1. Copy the `new-fixture-template` as `test-<functionality>`.
2. Update the files accordingly to the function that is being tested.
3. Run the fixture locally. (see below)
4. Add the fixture to [`test-fixtures.yml`](../workflows/test-fixtures.yml) matrix.
- If you need to specify custom arguments to `git-cliff` for the fixture test, you can do it here with using `command`.
5. Commit your changes.

See [this commit](https://github.com/orhun/git-cliff/commit/c94cb6a37ae268953ab29dd35cb43b6a4fec47cc) as an example.

## Running locally

To run the fixtures locally:

```sh
./test-fixtures-locally.sh <fixture_name>
```

## See also

- [Contribution Guidelines](https://github.com/orhun/git-cliff/blob/main/CONTRIBUTING.md)
37 changes: 37 additions & 0 deletions .github/fixtures/new-fixture-template/cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[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 group, commits in commits | group_by(attribute="scope") %}
#### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | upper_first }}\
{% endfor %}
{% 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/new-fixture-template/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"
37 changes: 37 additions & 0 deletions .github/fixtures/new-fixture-template/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Changelog

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

## [unreleased]

### Test

## [0.2.0] - 2022-04-05

### Bug Fixes

#### Cli

- Fix feature 2

### Features

#### Gui

- Add feature 2

## [0.1.0] - 2022-04-05

### Bug Fixes

#### Cli

- Fix feature 1

### Features

#### App

- Add feature 1

<!-- generated by git-cliff -->
1 change: 1 addition & 0 deletions .github/workflows/test-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
fail-fast: false
matrix:
include:
- fixtures-name: new-fixture-template
- fixtures-name: test-ignore-tags
- fixtures-name: test-topo-order
command: --latest
Expand Down

0 comments on commit 8290769

Please sign in to comment.