Skip to content

Commit

Permalink
feat: add git-cliff
Browse files Browse the repository at this point in the history
  • Loading branch information
vjousse committed Sep 26, 2024
1 parent d4c53ab commit f63d98e
Show file tree
Hide file tree
Showing 7 changed files with 501 additions and 8 deletions.
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
81 changes: 81 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Generate changelog

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

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
GITHUB_REPO: ${{ github.repository }}

- 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:
OUTPUT: CHANGELOG-cliff.md
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: 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
11 changes: 11 additions & 0 deletions CHANGELOG-cliff.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.

## [2.4.0-cliff-test.1] - 2024-09-26

### ⚙️ Miscellaneous Tasks

- Add 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

0 comments on commit f63d98e

Please sign in to comment.