Skip to content

Commit

Permalink
ci(GitHub workflow): add changelog.md file generation and automatic v…
Browse files Browse the repository at this point in the history
…ersion bumping

Add changelog.md file generation and automatic version bumping on push to GitHub.
  • Loading branch information
renedekat committed Sep 5, 2024
1 parent 224cbda commit cf06c27
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .cz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[tool.commitizen]
version = "0.0.1"
template = ".github/templates/CHANGELOG.md.j2"
name = "cz_customize"

[tool.commitizen.customize]
message_template = "{{change_type}}{% if scope %}({{scope}}){% endif %}: {{subject}}{% if ticket_no %} ({{ticket_no}}){% endif %}{% if body %}\n\n{{body}}{% endif %}"
bump_pattern = "^((BREAKING[\\-\\ ]CHANGE|\\w+)(\\(.+\\))?!?):"
bump_map = { "^.+!$" = "MAJOR", "^BREAKING[\\- ]CHANGE" = "MAJOR", "^feat" = "MINOR", "^fix" = "PATCH", ci = "PATCH", build = "PATCH", "^refactor" = "PATCH", "^perf" = "PATCH" }

schema = "<type>: <body>"
schema_pattern = "^(build|ci|docs|feat|fix|perf|refactor|style|test|revert)(\\(\\w+\\))?: [\\w -.]+(\\((#)-[0-9]+\\))?(\\[skip ci\\](.|\\n)*)?$"

commit_parser = "^(?P<change_type>build|ci|docs|feat|fix|perf|refactor|style|test|revert|BREAKING CHANGE)(?:\\((?P<scope>[^)]+)\\))?:?\\s(?P<message>.*)?"

changelog_pattern = "^(build|ci|docs|feat|fix|perf|refactor|style|test|revert)?(!)?"
change_type_order = ["BREAKING CHANGE", "feat", "fix", "refactor", "perf", "style", "test", "build", "ci"]
change_type_map = {"build" = "Build process", "ci" = "Continuous integration/delivery", "feat" = "New Features", "fix" = "Bug fixes", "style" = "Code style changes", "refactor" = "Refactored", "test" = "Tests" }

[[tool.commitizen.customize.questions]]
type = "list"
name = "change_type"
choices = [
{value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer"},
{value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer"},
{value = "docs", name = "docs: Documentation only changes"},
{value = "style", name = "style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"},
{value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature"},
{value = "perf", name = "perf: A code change that improves performance"},
{value = "test", name = "test: Adding missing or correcting existing tests"},
{value = "build", name = "build: Changes that affect the build system or external dependencies (example scopes: pip, docker, npm)"},
{value = "ci", name = "ci: Changes to our CI configuration files and scripts (example scopes: Jenkins, Docker)"},
{value = "BREAKING CHANGE", name = "BREAKING: A major change."}
]
message = "Select the type of change you are committing"

[[tool.commitizen.customize.questions]]
type = "input"
name = "scope"
message = "What is the scope of this change? (class or file name): (press [enter] to skip)\n"

[[tool.commitizen.customize.questions]]
type = "input"
name = "subject"
message = "Write a short and imperative summary of the code changes: (lower case and no period)\n"

[[tool.commitizen.customize.questions]]
type = "input"
name = "body"
message = "Provide additional contextual information about the code changes: (press [enter] to skip)\n"

[[tool.commitizen.customize.questions]]
type = "input"
name = "ticket_no"
message = "Ticket number i.e: #7 (Keep empty if no ticket)\n"
24 changes: 24 additions & 0 deletions .github/templates/CHANGELOG.md.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% for entry in tree %}

## {{ entry.version }}{% if entry.date %} ({{ entry.date }}){% endif %}

{% for change_key, changes in entry.changes.items() %}

{% if change_key %}
### {{ change_key }}
{% endif %}

{% for change in changes %}
{% set message_parts = change.message.split('#') %}
{% set issue = message_parts[1] %}
{% set subject = message_parts[0] %}
{% set issue_link = "[#" + issue + "](https://github.com/renedekat/salary-match/issues/" + issue + ") " if issue else "" %}
{% set commit_link = "[" + change.sha1[:7] + "](" + change.sha1 + ")" %}
{% set scope = "**" + change.scope + "**: " if change.scope else "" %}
- {{ commit_link }} - {{ scope }} {{subject }} (*by [{{ change.author }}](mailto:{{ change.author_email }}))*
{% if issue_link %}
- Fixes issue {{ issue_link }}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}
30 changes: 30 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Bump version

on:
push:
branches:
- master

jobs:
bump-version:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
runs-on: ubuntu-latest
name: "Bump version and generate changelog with commitizen"
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
changelog_increment_filename: body.md
- name: Release
uses: softprops/action-gh-release@v2
with:
body_path: "body.md"
tag_name: ${{ env.REVISION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit cf06c27

Please sign in to comment.