Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve changelog by using git-cliff #768

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/actions/build-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: "Build a release"
description: "Create the dist files for a specific version"

inputs:
tag:
description: 'The tag we want to create the release for'
required: true
# @FIX: this should not be required?
commit_sha:
description: 'The commit of the tag'
required: true
encryption_key:
description: 'The key used to encypt the detailed processes'
required: true
private_ssh_key:
description: 'The private ssh key used to clone the detailed impacts'
required: true
ecobalyse_data_dir:
description: 'The path to the ecobalyse dir containing the detailed impacts'
required: false
default: "./ecobalyse-private"
outputs:
dist-archive:
description: "Dist archive file path"
value: ${{ steps.create-dist-archive.outputs.dist-archive }}


runs:
using: "composite"
steps:

- uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: 'npm'

- name: Install Node dependencies
shell: bash
run: npm ci --prefer-offline --no-audit

- name: Clone the detailed impacts
shell: bash
run: |
eval `ssh-agent -s`
ssh-add - <<< '${{ inputs.private_ssh_key }}'
git clone [email protected]:MTES-MCT/ecobalyse-private.git

- name: Build app
shell: bash
env:
# Specify the created SHA to correctly update version.json
# @FIX: this should not be requiered when creating a tagged version
SOURCE_VERSION: ${{ inputs.commit_sha }}
TAG: ${{ inputs.tag }}
ECOBALYSE_DATA_DIR: ${{ inputs.ecobalyse_data_dir }}
run: |
npm run build:standalone-app

- name: Encrypt the impacts files
shell: bash
env:
ENCRYPTION_KEY: ${{ inputs.encryption_key }}
ECOBALYSE_DATA_DIR: ${{ inputs.ecobalyse_data_dir }}
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
shell: bash
id: create-dist-archive
run: |
tar czvf ${{ inputs.tag }}-dist.tar.gz dist
echo "dist-archive=${{ inputs.tag }}-dist.tar.gz" >> $GITHUB_OUTPUT
98 changes: 98 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Generate changelog

on:
push:
branches: [ master, staging ]
pull_request:
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
changelog:
name: Generate 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-cliff.md

- name: Generate latest changes
uses: orhun/git-cliff-action@v4
id: git-cliff-latest
with:
config: cliff.toml
args: --verbose --exclude-path "data/" --bump --unreleased
env:
GITHUB_REPO: ${{ github.repository }}

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
with:
base: master
commit-message: Update changelog
signoff: false
branch: chore/update-changelog-${{ steps.git-cliff.outputs.version }}
delete-branch: true
title: 'chore(release): Release ${{ steps.git-cliff.outputs.version }}'
body: ${{ steps.git-cliff-latest.outputs.content }}
labels: |
pending-release
automated pr


# - name: Commit the changelog
# run: |
# git checkout ${{ steps.extract_branch.outputs.branch }}
# git config user.name 'github-actions[bot]'
# git config user.email 'github-actions[bot]@users.noreply.github.com'
# set +e
# git add CHANGELOG-cliff.md
# git commit -m "Update changelog"
# git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git ${{ steps.extract_branch.outputs.branch }}
#
# - name: Tag the next version
# run: |
# git checkout ${{ steps.extract_branch.outputs.branch }}
# git config user.name 'github-actions[bot]'
# git config user.email 'github-actions[bot]@users.noreply.github.com'
# set +e
# git tag -f ${{ steps.git-cliff.outputs.version }}-cliff-test
# git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git ${{ steps.git-cliff.outputs.version }}-cliff-test
#
# - name: Create dist archive
# uses: ./.github/actions/build-release
# id: create-dist-archive
# with:
# tag: ${{ steps.git-cliff.outputs.version }}-cliff-test
# commit_sha: ${{ github.event.pull_request.head.sha }}
# encryption_key: ${{ secrets.ENCRYPTION_KEY }}
# private_ssh_key: ${{ secrets.PRIVATE_SSH_KEY }}
#
#
# - name: Upload the release
# uses: svenstaro/upload-release-action@v2
# with:
# file: ${{ steps.create-dist-archive.outputs.dist-archive}}
# repo_token: ${{ secrets.GITHUB_TOKEN }}
# tag: ${{ steps.git-cliff.outputs.version }}-cliff-test
# body: ${{ steps.git-cliff-latest.outputs.content }}
# draft: true
19 changes: 19 additions & 0 deletions CHANGELOG-cliff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

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

## [2.4.0] - 2024-09-26

### πŸš€ Features

- Add `git-cliff`

### πŸ› Bug Fixes

- Don't download draft releases

### βš™οΈ Miscellaneous Tasks

- Better logging

<!-- generated by git-cliff -->
3 changes: 3 additions & 0 deletions bin/download_github_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def download_file(url, destination_directory=None):

for asset in release.assets:
if "-dist.tar.gz" in asset.browser_download_url:
logger.info(
f"Downloading {asset.browser_download_url} to {args.destination_directory}."
)
file_path = download_file(
asset.browser_download_url, args.destination_directory
)
Expand Down
83 changes: 83 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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
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 | 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\\): prepare for", skip = true },
{ message = "^chore\\(deps.*\\)", skip = true },
{ message = "^chore\\(pr\\)", skip = true },
{ message = "^chore\\(pull\\)", 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"
Loading
Loading