Skip to content

Commit

Permalink
ci: add step to auto generate changelog in kickoff PR
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Oct 3, 2024
1 parent 8e0458b commit 7f0ce19
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/scripts/group-commit-message.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/awk -f

function add_to_group(key, value) {
groups[key] = groups[key] "- " value "\n"
}

{
# Remove leading and trailing whitespace
$0 = $0

if (NF > 0) { # Skip empty lines
if (tolower($1) == "feat:") {
add_to_group("Features:", substr($0, index($0, $2)))
} else if (tolower($1) == "fix:") {
add_to_group("Fixes:", substr($0, index($0, $2)))
} else if (tolower($1) == "chore:") {
add_to_group("MISC:", substr($0, index($0, $2)))
} else {
add_to_group("MISC:", $0)
}
}
}

END {
for (group in groups) {
print "\n### " group
print groups[group]
}
print
}
27 changes: 26 additions & 1 deletion .github/workflows/kick-off-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Checkout Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: main
fetch-depth: 0

- name: Bump versions to ${{ env.RELEASE_VERSION }}
run: |
Expand All @@ -56,6 +56,31 @@ jobs:
git push origin HEAD
shell: bash

- name: Generate CHANGELOG
env:
RELEASE_VERSION: ${{ github.event.inputs.release-version }}
run: |
LOGS=$(git log --pretty=format:%s origin/release..HEAD | awk -F '\n' '{print $1}')
LOGS=$(echo $LOGS | ./.github/scripts/group-commit-message.awk)
awk -v date=$(date +"%Y-%m-%d") \
-v version="$RELEASE_VERSION" '
NR == 2 {
print "## " version " (" date ")"
while (getline line < "/dev/stdin") {
print line
}
next
}
{print}
' CHANGELOG.md < <(echo "$LOGS") > temp && mv temp CHANGELOG.md
- name: Create CHANGELOG commit
env:
RELEASE_VERSION: ${{ github.event.inputs.release-version }}
run: |
git add CHANGELOG.md
git commit -m "chore: update CHANGELOG for $RELEASE_VERSION"
- name: Create Pull Request
env:
GH_TOKEN: ${{ github.token }}
Expand Down

0 comments on commit 7f0ce19

Please sign in to comment.