Skip to content

Commit d5e0f63

Browse files
committed
ci: add step to auto generate changelog in kickoff PR
1 parent 8e0458b commit d5e0f63

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/awk -f
2+
3+
function add_to_group(key, value) {
4+
groups[key] = groups[key] "- " value "\n"
5+
}
6+
7+
{
8+
if (NF > 0) { # Skip empty lines
9+
if (tolower($1) == "feat:") {
10+
add_to_group("Features:", substr($0, index($0, $2)))
11+
} else if (tolower($1) == "fix:") {
12+
add_to_group("Fixes:", substr($0, index($0, $2)))
13+
} else if (tolower($1) == "chore:") {
14+
add_to_group("MISC:", substr($0, index($0, $2)))
15+
} else {
16+
next
17+
}
18+
}
19+
}
20+
21+
END {
22+
for (group in groups) {
23+
print "\n### " group
24+
print groups[group]
25+
}
26+
print "\n"
27+
}

.github/workflows/kick-off-release.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: Checkout Code
4444
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4545
with:
46-
ref: main
46+
fetch-depth: 0
4747

4848
- name: Bump versions to ${{ env.RELEASE_VERSION }}
4949
run: |
@@ -56,6 +56,34 @@ jobs:
5656
git push origin HEAD
5757
shell: bash
5858

59+
- name: Generate CHANGELOG
60+
env:
61+
RELEASE_VERSION: ${{ github.event.inputs.release-version }}
62+
shell: bash
63+
run: |
64+
LOGS=$(git log --pretty=format:%s origin/release..HEAD | awk -F '\n' '{print $1}')
65+
GROUPED_LOGS=$(echo $LOGS | ./.github/scripts/group-commit-message.awk)
66+
awk -v date=$(date +"%Y-%m-%d") \
67+
-v version="$RELEASE_VERSION" '
68+
NR == 2 {
69+
print "\n"
70+
print "## " version " - (" date ")"
71+
while (getline line < "/dev/stdin") {
72+
print line
73+
}
74+
next
75+
}
76+
{print}
77+
' CHANGELOG.md < <(echo "$GROUPED_LOGS") > temp && mv temp CHANGELOG.md
78+
79+
- name: Create CHANGELOG commit
80+
env:
81+
RELEASE_VERSION: ${{ github.event.inputs.release-version }}
82+
run: |
83+
git add CHANGELOG.md
84+
git commit -m "chore: update CHANGELOG for $RELEASE_VERSION"
85+
git push origin HEAD
86+
5987
- name: Create Pull Request
6088
env:
6189
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)