Skip to content

Commit 7f0ce19

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

File tree

2 files changed

+56
-1
lines changed

2 files changed

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

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

Lines changed: 26 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,31 @@ 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+
run: |
63+
LOGS=$(git log --pretty=format:%s origin/release..HEAD | awk -F '\n' '{print $1}')
64+
LOGS=$(echo $LOGS | ./.github/scripts/group-commit-message.awk)
65+
awk -v date=$(date +"%Y-%m-%d") \
66+
-v version="$RELEASE_VERSION" '
67+
NR == 2 {
68+
print "## " version " (" date ")"
69+
while (getline line < "/dev/stdin") {
70+
print line
71+
}
72+
next
73+
}
74+
{print}
75+
' CHANGELOG.md < <(echo "$LOGS") > temp && mv temp CHANGELOG.md
76+
77+
- name: Create CHANGELOG commit
78+
env:
79+
RELEASE_VERSION: ${{ github.event.inputs.release-version }}
80+
run: |
81+
git add CHANGELOG.md
82+
git commit -m "chore: update CHANGELOG for $RELEASE_VERSION"
83+
5984
- name: Create Pull Request
6085
env:
6186
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)