Skip to content

Commit 7f617c3

Browse files
authored
[ignore] Add release PR feature to auto generate changelog entries. (#394)
1 parent 449a290 commit 7f617c3

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

.github/workflows/release_pr.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: release_pr
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release-pr:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Unshallow
15+
run: git fetch --prune --unshallow
16+
17+
# git-cliff generates CHANGELOG.md
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.10'
21+
- run: pip install git-cliff==2.4.0 typos
22+
- name: Check new changlog entry for version bump type
23+
id: type
24+
run: |
25+
changelog=$(git cliff --unreleased)
26+
case $changelog in
27+
*"BREAKING CHANGES:"* )
28+
echo "MAJOR"
29+
echo "bump="MAJOR: version change"" >> $GITHUB_OUTPUT
30+
;;
31+
*"IMPROVEMENTS:"* )
32+
echo "MINOR"
33+
echo "bump="MINOR: version change"" >> $GITHUB_OUTPUT
34+
;;
35+
*"DEPRECATIONS:"* )
36+
echo "MINOR"
37+
echo "bump="MINOR: version change"" >> $GITHUB_OUTPUT
38+
;;
39+
* )
40+
echo "PATCH"
41+
echo "bump="PATCH: version change"" >> $GITHUB_OUTPUT
42+
;;
43+
esac
44+
# The --with-commit inserts a commit message to git-cliff without it being in the history.
45+
# It is used here to dynamically add version bump commands.
46+
- name: Get next version
47+
id: vars
48+
run: echo "version=$(git cliff --bumped-version --with-commit "${{ steps.type.outputs.bump }}")" >> $GITHUB_OUTPUT
49+
- name: Generate changelog output
50+
run: git cliff --bump --unreleased --with-commit "${{ steps.type.outputs.bump }}"
51+
- name: Prepend new changelog entry
52+
run: git cliff --bump --unreleased -p CHANGELOG.md --with-commit "${{ steps.type.outputs.bump }}"
53+
54+
# Commit changes to release_pr branch
55+
- name: Set git config
56+
run: git config user.email "[email protected]" && git config user.name "dcne-automation"
57+
- name: Commit
58+
run: git add -u && git status && git commit -m "[ignore] Update Changelog and annotation_unsupported.go for new release (${{ steps.vars.outputs.version }})"
59+
- name: Branch & Push
60+
run: git checkout -b release_pr && git push --set-upstream origin release_pr --force && git clean -f -d
61+
62+
# Create or update release PR
63+
- run: gh pr create --base master --head release_pr --title "Pre-Release PR (${{ steps.vars.outputs.version }})" --body ""
64+
id: pr
65+
continue-on-error: true
66+
env:
67+
GH_TOKEN: ${{ secrets.DCNE_AUTO_TOKEN }}
68+
- run: gh pr edit release_pr --title "Pre-Release PR (${{ steps.vars.outputs.version }})"
69+
if: steps.pr.outcome == 'failure'
70+
env:
71+
GH_TOKEN: ${{ secrets.DCNE_AUTO_TOKEN }}

_typos.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default.extend-words]
2+
# Don't correct the following words or acronyms
3+
aci = "aci"
4+
nd = "nd"
5+
mso = "mso"
6+
useg = "useg"

cliff.toml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# git-cliff ~ configuration file
2+
# https://git-cliff.org/docs/configuration
3+
4+
[changelog]
5+
header = """
6+
# Terraform Provider MSO - Changelog\n
7+
All notable changes to this project will be documented in this file.\n
8+
"""
9+
# template for the changelog body
10+
# https://keats.github.io/tera/docs/#introduction
11+
# TODO find a nicer way to remove the [something] tags from the start of commits.
12+
body = """
13+
{% if version %}\
14+
## {{ version | trim_start_matches(pat="v") }} ({{ timestamp | date(format="%B %d, %Y") }})
15+
{% else %}\
16+
## [unreleased]
17+
{% endif %}\
18+
{% for group, commits in commits | group_by(attribute="group") %}
19+
{{ group | striptags | trim | upper_first }}:
20+
{% for commit in commits -%}
21+
- {{ commit.message | trim
22+
| trim_start_matches(pat="[bugfix]")
23+
| trim_start_matches(pat="[bug_fix]")
24+
| trim_start_matches(pat="[bugfixes]")
25+
| trim_start_matches(pat="[minor_change]")
26+
| trim_start_matches(pat="[minor_changes]")
27+
| trim_start_matches(pat="[major_change]")
28+
| trim_start_matches(pat="[major_changes]")
29+
| trim | capitalize }}
30+
{% endfor -%}
31+
{% endfor %}\n
32+
"""
33+
footer = """
34+
"""
35+
trim = true
36+
postprocessors = [
37+
{ pattern = '.*', replace_command = 'typos --write-changes -' }
38+
]
39+
40+
[git]
41+
conventional_commits = false
42+
filter_unconventional = false
43+
split_commits = false
44+
commit_preprocessors = []
45+
commit_parsers = [
46+
{ message = "^.[I|i]gnore", skip = true },
47+
{ message = "^Bump", skip = true }, # Ignore Dependabot version bumps
48+
{ message = "^Merge.branch", skip = true }, # Ignore merge commits
49+
{ message = "^.[M|m]ajor", group = "<!-- 0 -->BREAKING CHANGES" },
50+
{ message = "[D|d]eprecat", group = "<!-- 1 -->DEPRECATIONS" },
51+
{ message = "^.[M|m]inor", group = "<!-- 2 -->IMPROVEMENTS" },
52+
{ message = "^.[B|b]ug", group = "<!-- 3 -->BUG FIXES" },
53+
# Not skipped so version bumps are registered.
54+
# However, not grouped so they don't show up in the changelog.
55+
{ message = ".*[MAJOR|MINOR|PATCH].*version change" },
56+
{ message = ".*", group = "<!-- 4 -->OTHER" },
57+
]
58+
protect_breaking_commits = false
59+
filter_commits = true
60+
topo_order = false
61+
sort_commits = "oldest"
62+
63+
[bump]
64+
features_always_bump_minor = true
65+
breaking_always_bump_major = true
66+
custom_major_increment_regex = "major"
67+
custom_minor_increment_regex = "minor"

0 commit comments

Comments
 (0)