Skip to content

Commit

Permalink
feat(changelog): custom template for release notes (GH action)
Browse files Browse the repository at this point in the history
- nice visual, badges, nice links, logo
  • Loading branch information
tomassebestik committed Sep 24, 2024
1 parent d073c9d commit 19e8cec
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 87 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
# This workflow builds the Python package and stores it as an artifact for testing during development.
# It only triggers when the 'PR Draft-Release' label is applied to a pull request.
# The built package is NOT pushed to PyPI but is instead stored in a draft GitHub release for reviewers to test.
name: Build draft release, store in GitHub repo only

on:
pull_request:
types: [opened, edited, reopened, synchronize, labeled]
workflow_dispatch:

jobs:
build-draft-release:
runs-on: ubuntu-latest
if: github.event.label.name == 'PR Draft-Release'
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |-
python -m pip install --upgrade pip
pip install build wheel setuptools_scm # Ensure both sdist and wheel are built, setuptools_scm can help with versioning
- name: Create dist directory
run: mkdir -p dist

- name: Get version from Git tag, save to version file
run: echo $(git describe --tags --abbrev=0 | sed 's/^v//') > dist/version.txt

- name: Modify version for PR draft
run: |-
PR_NUMBER=${{ github.event.number }}
VERSION=$(cat dist/version.txt)
echo "${VERSION}.dev.pr${PR_NUMBER}" > dist/version.txt
- name: Build package with PR suffix
run: |-
PR_VERSION=$(cat dist/version.txt)
python -m build --wheel --sdist --outdir dist --tag ${PR_VERSION}
- name: Upload builds and version file
uses: actions/upload-artifact@v3
with:
name: python-package-${{ matrix.python-version }}
path: dist/*

create-draft-release:
runs-on: ubuntu-latest
needs: build-draft-release # This job runs after all matrix jobs complete

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download all builds and version file
uses: actions/download-artifact@v3
with:
path: dist/

- name: Read version from file
id: read_version
run: echo "VERSION=$(cat dist/version.txt)" >> $GITHUB_ENV

- name: Create release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: 'v${{ env.VERSION }} - Draft release for review PR #${{ github.event.number }}'
name: v${{ env.VERSION }}.dev.pr${{ github.event.number }}
draft: true # Keeps the release as a draft until published
prerelease: true # Marks it as a pre-release
files: dist/** # Upload all collected artifacts
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Run pre-commit
uses: pre-commit/[email protected]
Expand Down
17 changes: 7 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: check-shebang-scripts-are-executable # Checks that scripts with shebangs are executable.
- id: check-case-conflict # Check conflict on a case-insensitive filesystem (MacOS HFS+/Windows FAT).
- id: mixed-line-ending # Detects mixed line endings (CRLF/LF)
args: ["-f=lf"] # Forces files to use LF line endings
args: ['-f=lf'] # Forces files to use LF line endings

- repo: https://github.com/pylint-dev/pylint
rev: v3.2.6
Expand Down Expand Up @@ -46,7 +46,7 @@ repos:
rev: v2.3.0
hooks:
- id: codespell # Code spell checker
args: ["--write-changes"]
args: ['--write-changes']
additional_dependencies: [tomli]

- repo: https://github.com/executablebooks/mdformat
Expand All @@ -72,6 +72,11 @@ repos:
hooks:
- id: yamlfix

- repo: https://github.com/espressif/cz-plugin-espressif
rev: v1.0.1
hooks:
- id: update-changelog

# Local hooks
- repo: local
hooks:
Expand All @@ -81,11 +86,3 @@ repos:
language: system
pass_filenames: false
files: requirements.txt|pyproject.toml

- repo: local
hooks:
- id: update-changelog # Update changelog, section Unreleased
name: update changelog
entry: bash -c 'cz changelog > /dev/null'
language: system
pass_filenames: false
42 changes: 34 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
<a href="https://www.espressif.com">
<img src="czespressif/templates/espressif-logo.svg" align="right" height="20" />
</a>

# CHANGELOG

> All notable changes to this project are documented in this file.
> This list is not exhaustive - only important changes, fixes, and new features in the code are reflected here.
<sub>The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
</sub>

---
<div align="center">
<img alt="Static Badge" src="https://img.shields.io/badge/Keep%20a%20Changelog-v1.1.0-salmon?logo=keepachangelog&logoColor=black&labelColor=white&link=https%3A%2F%2Fkeepachangelog.com%2Fen%2F1.1.0%2F">
<img alt="Static Badge" src="https://img.shields.io/badge/Conventional%20Commits-v1.0.0-pink?logo=conventionalcommits&logoColor=black&labelColor=white&link=https%3A%2F%2Fwww.conventionalcommits.org%2Fen%2Fv1.0.0%2F">
<img alt="Static Badge" src="https://img.shields.io/badge/Semantic%20Versioning-v2.0.0-grey?logo=semanticrelease&logoColor=black&labelColor=white&link=https%3A%2F%2Fsemver.org%2Fspec%2Fv2.0.0.html">
</div>
<hr>

## Unreleased

### ✨ New features

- **changelog**: custom template for release notes (GH action) *(Tomas Sebestik - fa886f1)*

### 🐛 Bug fixes

- **github-actions**: update create-release.yml, missing "v" in version *(Tomas Sebestik - 3d2f492)*

### 📖 Documentation

- **readme**: add section about solving conflicts commitizen *(Tomas Sebestik - 73a86a7)*
- **readme**: docs to automatic process of "Release notes" *(Tomas Sebestik - df93e19)*

---

## v1.0.1 (2024-09-10)
Expand All @@ -36,7 +55,14 @@

---

**[Espressif Systems CO LTD. (2024)](https://www.espressif.com/)**

- [Commitizen tools plugin with Espressif code style](https://www.github.com/espressif/cz-plugin-espressif)
- [Espressif Coding Standards and Best Practices](https://www.github.com/espressif/standards)
<div align="center">
<small>
<b>
<a href="https://www.github.com/espressif/cz-plugin-espressif">Commitizen Espressif plugin</a>
·
<a href="https://www.github.com/espressif/standards">Espressif Standards</a>
</b>
<br>
<sup><a href="https://www.espressif.com">Espressif Systems CO LTD. (2024)</a><sup>
</small>
</div>
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div align="center">
<h1>Commitizen Espressif style plugin </h1>
Commitizen tools plugin with Espressif code style
<br>
<br>
<a href="https://www.espressif.com">
<img src="czespressif/templates/espressif-logo.svg" align="right" height="20" />
</a>

[![Release][release-badge]][release-url] [![Pre-commit][pre-commit-badge]][pre-commit-url] [![Conventional Commits][conventional-badge]][conventional-url] [![PYPI version][pypiversion-badge]][pypiversion-url] [![Python compatible][pypipythons-badge]][pypipythons-url]

Expand Down
5 changes: 5 additions & 0 deletions czespressif/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CzEspressifSettings(Settings):
changelog_section_line: Union[bool, None]
changelog_show_commits: Union[bool, None]
changelog_show_authors: Union[bool, None]
release_notes_footer: Union[str, None]


@dataclass
Expand Down Expand Up @@ -132,3 +133,7 @@ def changelog_show_commits(self) -> bool:
@property
def changelog_show_authors(self) -> bool:
return self.settings.get('changelog_show_authors', True)

@property
def release_notes_footer(self) -> str:
return self.settings.get('release_notes_footer', None)
15 changes: 2 additions & 13 deletions czespressif/czespressif.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import itertools
import re
import sys

from collections import OrderedDict
from typing import Any
Expand All @@ -24,7 +23,6 @@


class CzPluginEspressif(BaseCommitizen): # pylint: disable=abstract-method
template = 'CHANGELOG.md.j2'
template_loader = PackageLoader('czespressif', 'templates')

def __init__(self, config: BaseConfig):
Expand All @@ -33,11 +31,7 @@ def __init__(self, config: BaseConfig):

@property
def known_types(self) -> Dict[str, CommitType]:
return dict(
itertools.chain(
((t.type, t) for t in self.cze_config.known_types),
)
)
return dict(itertools.chain(((t.type, t) for t in self.cze_config.known_types)))

@property
def re_known_types(self) -> str:
Expand Down Expand Up @@ -169,12 +163,7 @@ def changelog_message_builder_hook(self, parsed_message: Dict[str, Any], commit:

def changelog_hook(self, full: str, partial: Union[str, None]) -> str:
"""Process resulting changelog to keep 1 empty line at the end of the file."""
if 'bump' in sys.argv: # no headers
changelog = full
elif partial: # no headers
changelog = partial
else: # add title, header and footer
changelog = f'# {self.cze_config.changelog_title}\n{self.cze_config.changelog_header}\n\n{full}{self.cze_config.changelog_footer}'
changelog = partial or full
return changelog.rstrip() + '\n'

def example(self) -> str:
Expand Down
38 changes: 27 additions & 11 deletions czespressif/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,39 @@
},
]

CHANGELOG_TITLE: str = 'CHANGELOG'
CHANGELOG_TITLE: str = """
<a href="https://www.espressif.com">
<img src="czespressif/templates/espressif-logo.svg" align="right" height="20" />
</a>
# CHANGELOG
"""

CHANGELOG_HEADER: str = """
> All notable changes to this project are documented in this file.
> This list is not exhaustive - only important changes, fixes, and new features in the code are reflected here.
<sub>The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), \
[Semantic Versioning](https://semver.org/spec/v2.0.0.html) and \
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
</sub>
---"""

<div align="center">
<img alt="Static Badge" src="https://img.shields.io/badge/Keep%20a%20Changelog-v1.1.0-salmon?logo=keepachangelog&logoColor=black&labelColor=white&link=https%3A%2F%2Fkeepachangelog.com%2Fen%2F1.1.0%2F">
<img alt="Static Badge" src="https://img.shields.io/badge/Conventional%20Commits-v1.0.0-pink?logo=conventionalcommits&logoColor=black&labelColor=white&link=https%3A%2F%2Fwww.conventionalcommits.org%2Fen%2Fv1.0.0%2F">
<img alt="Static Badge" src="https://img.shields.io/badge/Semantic%20Versioning-v2.0.0-grey?logo=semanticrelease&logoColor=black&labelColor=white&link=https%3A%2F%2Fsemver.org%2Fspec%2Fv2.0.0.html">
</div>
<hr>
"""

CHANGELOG_FOOTER: str = f"""**[Espressif Systems CO LTD. ({datetime.now().year})](https://www.espressif.com/)**\n
- [Commitizen tools plugin with Espressif code style](https://www.github.com/espressif/cz-plugin-espressif)
- [Espressif Coding Standards and Best Practices](https://www.github.com/espressif/standards)"""
CHANGELOG_FOOTER: str = f"""
<div align="center">
<small>
<b>
<a href="https://www.github.com/espressif/cz-plugin-espressif">Commitizen Espressif plugin</a>
·
<a href="https://www.github.com/espressif/standards">Espressif Standards</a>
</b>
<br>
<sup><a href="https://www.espressif.com">Espressif Systems CO LTD. ({datetime.now().year})</a><sup>
</small>
</div>
"""

INCREMENT = Literal['MAJOR', 'MINOR', 'PATCH']

Expand Down
Loading

0 comments on commit 19e8cec

Please sign in to comment.