-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve changelog by using
git-cliff
(#768)
## 🔧 Problem We can't customize the changelog generated by [release-please](https://github.com/googleapis/release-please), so it's impossible to filter technical and non technical changes. Moreover only `fix` and `feat` commits are parts of the changelog, sometimes it would make sense to add `chore`, `refactor` and `doc` changes to the changelog. ## 🍰 Solution Use [`git-cliff`](https://git-cliff.org/) to generate the changelog and create the tags too. The process is the same than with `release-please`, it will create an automated PR that, when merged, will tag the appropriate version and create a release. ## 🚨 Points to watch/comments Commits that are only relative to `data/` are excluded from the changelog. We will be able to fully test this PR only once it will be merged into master and once a release will be created. I did all the tests that I could without merging, see below. ## 🏝️ How to test The generated PR will look like this one: #797 > [!IMPORTANT] > This automated PR was updated using the commits of this PR, so once this is merged into `master`, the changelog will only contain the squashed commits of the `master` branch. The different workflows were tested extensively here: https://github.com/vjousse/git-cliff-release-creation-exemple I did a test on this PR by enabling release creation on commit push here (instead of merging the changelog PR). The tag and the release (configured as draft in my test) was created as expected, see the screenshots below. ![Screenshot 2024-10-09 at 15-53-53 Tags · MTES-MCT_ecobalyse](https://github.com/user-attachments/assets/21f27b56-3f04-43bb-9b95-9be239a63664) ![Screenshot 2024-10-09 at 15-53-32 Releases · MTES-MCT_ecobalyse](https://github.com/user-attachments/assets/070e5939-53ea-44a1-b853-17ee33d76340) I have removed the tag and the draft PR since.
- Loading branch information
Showing
6 changed files
with
257 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Generate changelog PR | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
changelog: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Generate the full changelog | ||
uses: orhun/git-cliff-action@v4 | ||
id: git_cliff | ||
with: | ||
config: cliff.toml | ||
args: --verbose --exclude-path "data/" --bump | ||
env: | ||
OUTPUT: CHANGELOG.md | ||
|
||
- name: Generate latest changes | ||
uses: orhun/git-cliff-action@v4 | ||
id: git_cliff_latest | ||
with: | ||
config: cliff.toml | ||
args: --verbose --latest --strip header --exclude-path "data/" --bump --unreleased | ||
|
||
- name: Create Pull Request | ||
if: steps.git_cliff.outputs.version != 'null' | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
add-paths: | | ||
CHANGELOG.md | ||
base: master | ||
commit-message: "chore: update CHANGELOG.md for ${{ steps.git_cliff.outputs.version }}" | ||
signoff: true | ||
sign-commits: true | ||
branch: chore/next-release-changelog | ||
delete-branch: true | ||
title: "chore(release): release ${{ steps.git_cliff.outputs.version }}" | ||
body: ${{ steps.git_cliff_latest.outputs.content }} | ||
labels: | | ||
pending-release | ||
automated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: Create tag and release | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
env: | ||
ECOBALYSE_DATA_DIR: ./ecobalyse-private | ||
|
||
jobs: | ||
create_tag_and_release: | ||
# The tag and the release should be created only when the automated PR created by `create_pr_for_changelog` is merged | ||
# Or to test it for now, by triggering a workflow dispatch by hand | ||
if: (github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'chore(release)') && contains(github.event.pull_request.labels.*.name, 'automated') && contains(github.event.pull_request.labels.*.name, 'pending-release')) | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get latest version | ||
uses: orhun/git-cliff-action@v4 | ||
id: git_cliff | ||
with: | ||
config: cliff.toml | ||
args: -vv --latest --strip header --exclude-path "data/" --bump --unreleased | ||
|
||
- name: Set up Git | ||
run: | | ||
git config user.name 'github-actions[bot]' | ||
git config user.email 'github-actions[bot]@users.noreply.github.com' | ||
- name: Create and push tag | ||
# If something went wrong when getting the latest version from `git-cliff` | ||
# don't create a messy tag | ||
if: steps.git_cliff.outputs.version != 'null' | ||
id: tag_creation | ||
run: | | ||
git tag -a "${{ steps.git_cliff.outputs.version }}" -m "Release ${{ steps.git_cliff.outputs.version }}" | ||
git push origin "${{ steps.git_cliff.outputs.version }}" | ||
echo "tag_created=true" >> "$GITHUB_OUTPUT" | ||
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
if: steps.tag_creation.outputs.tag_created | ||
|
||
- name: Install Node dependencies | ||
if: steps.tag_creation.outputs.tag_created | ||
run: npm ci --prefer-offline --no-audit | ||
|
||
- name: Clone the detailed impacts | ||
if: steps.tag_creation.outputs.tag_created | ||
run: | | ||
eval `ssh-agent -s` | ||
ssh-add - <<< '${{ secrets.PRIVATE_SSH_KEY }}' | ||
git clone [email protected]:MTES-MCT/ecobalyse-private.git | ||
- name: Build app | ||
if: steps.tag_creation.outputs.tag_created | ||
env: | ||
# Specify the created SHA to correctly update version.json | ||
SOURCE_VERSION: ${{ steps.git_cliff.outputs.sha }} | ||
TAG: ${{ steps.git_cliff.outputs.version }} | ||
run: | | ||
npm run build:standalone-app | ||
- name: Encrypt the impacts files | ||
if: steps.tag_creation.outputs.tag_created | ||
env: | ||
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }} | ||
run : | | ||
# We include the encrypted detailed processes with the dist | ||
# so that people with the encryption key could later on use the app with the exact | ||
# files it was using on production | ||
npm run encrypt $ECOBALYSE_DATA_DIR/data/textile/processes_impacts.json dist/processes_impacts_textile.json.enc | ||
npm run encrypt $ECOBALYSE_DATA_DIR/data/food/processes_impacts.json dist/processes_impacts_food.json.enc | ||
- name: Generate dist archive | ||
if: steps.tag_creation.outputs.tag_created | ||
run: | | ||
tar czvf ${{ steps.git_cliff.outputs.version }}-dist.tar.gz dist | ||
- name: Create release | ||
if: steps.tag_creation.outputs.tag_created | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
tag_name: ${{ steps.git_cliff.outputs.version }} | ||
body: ${{ steps.git_cliff.outputs.content }} | ||
files: ${{ steps.git_cliff.outputs.version }}-dist.tar.gz | ||
generate_release_notes: false | ||
make_latest: true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# git-cliff ~ default configuration file | ||
# https://git-cliff.org/docs/configuration | ||
# | ||
# Lines starting with "#" are comments. | ||
# Configuration options are organized into tables and keys. | ||
# See documentation for more information on available options. | ||
|
||
[changelog] | ||
# template for the changelog header | ||
header = """ | ||
# Changelog\n | ||
""" | ||
# template for the changelog body | ||
# https://keats.github.io/tera/docs/#introduction | ||
body = """ | ||
{% if version %}\ | ||
{% if previous.version %} | ||
## [{{ version | trim_start_matches(pat="v") }}](https://github.com/MTES-MCT/ecobalyse/compare/{{ previous.version }}..{{ version }}) ({{ timestamp | date(format="%Y-%m-%d") }}) | ||
{% else %} | ||
## {{ version | trim_start_matches(pat="v") }} ({{ timestamp | date(format="%Y-%m-%d") }}) | ||
{% endif %} | ||
{% else %}\ | ||
## [unreleased] | ||
{% endif %}\ | ||
{% for group, commits in commits | group_by(attribute="group") %} | ||
### {{ group | striptags | trim | upper_first }} | ||
{% for commit in commits %} | ||
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ | ||
{% if commit.breaking %}[**breaking**] {% endif %}\ | ||
{{ commit.message | upper_first }}\ | ||
{% endfor %} | ||
{% endfor %}\n | ||
""" | ||
# template for the changelog footer | ||
footer = """ | ||
<!-- generated by git-cliff --> | ||
""" | ||
# remove the leading and trailing s | ||
trim = true | ||
# postprocessors | ||
postprocessors = [ | ||
{ pattern = '<REPO>', replace = "https://github.com/MTES-MCT/ecobalyse" }, # replace repository URL | ||
] | ||
# render body even when there are no releases to process | ||
# render_always = true | ||
# output file path | ||
# output = "test.md" | ||
|
||
[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 preprocessing the commit messages | ||
commit_preprocessors = [ | ||
# Replace issue numbers | ||
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"}, | ||
# Check spelling of the commit with https://github.com/crate-ci/typos | ||
# If the spelling is incorrect, it will be automatically fixed. | ||
#{ pattern = '.*', replace_command = 'typos --write-changes -' }, | ||
] | ||
# regex for parsing and grouping commits | ||
commit_parsers = [ | ||
{ message = "^feat", group = "<!-- 0 -->🚀 Features" }, | ||
{ message = "^fix", group = "<!-- 1 -->🪲 Bug Fixes" }, | ||
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" }, | ||
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" }, | ||
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" }, | ||
{ message = "^style", group = "<!-- 5 -->🎨 Styling" }, | ||
{ message = "^test", group = "<!-- 6 -->🧪 Testing" }, | ||
{ message = "^chore\\(release\\):", skip = true }, | ||
{ message = "^chore\\(master\\): release", skip = true }, | ||
{ message = "^chore\\(deps.*\\)", skip = true }, | ||
{ message = "^chore\\(pr\\)", skip = true }, | ||
{ message = "^chore\\(pull\\)", skip = true }, | ||
{ message = "^chore\\(Snyk\\)", skip = true }, | ||
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" }, | ||
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" }, | ||
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" }, | ||
] | ||
# filter out the commits that are not matched by commit parsers | ||
filter_commits = false | ||
# sort the tags topologically | ||
topo_order = false | ||
# sort the commits inside sections by oldest/newest order | ||
sort_commits = "oldest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters