From dac53e019ff9e5c6b1845b16b5dde0a563bb16e4 Mon Sep 17 00:00:00 2001 From: Di Wu Date: Wed, 2 Oct 2024 17:43:27 -0700 Subject: [PATCH] ci: add step to auto generate changelog in kickoff PR --- .github/scripts/group-commit-message.awk | 25 ++++++++++++++++++++ .github/workflows/kick-off-release.yaml | 30 +++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/group-commit-message.awk diff --git a/.github/scripts/group-commit-message.awk b/.github/scripts/group-commit-message.awk new file mode 100755 index 0000000..f5d45c8 --- /dev/null +++ b/.github/scripts/group-commit-message.awk @@ -0,0 +1,25 @@ +#!/usr/bin/awk -f + +function add_to_group(key, value) { + groups[key] = groups[key] "- " value "\n" +} + +{ + 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 { + next + } + } +} + +END { + for (group in groups) { + print "\n### " group + print groups[group] + } + print "\n" +} diff --git a/.github/workflows/kick-off-release.yaml b/.github/workflows/kick-off-release.yaml index 9634ac6..61b450f 100644 --- a/.github/workflows/kick-off-release.yaml +++ b/.github/workflows/kick-off-release.yaml @@ -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: | @@ -56,6 +56,34 @@ jobs: git push origin HEAD shell: bash + - name: Generate CHANGELOG + env: + RELEASE_VERSION: ${{ github.event.inputs.release-version }} + shell: bash + run: | + LOGS=$(git log --pretty=format:%s origin/release..HEAD | awk -F '\n' '{print $1}') + GROUPED_LOGS=$(echo $LOGS | ./.github/scripts/group-commit-message.awk) + awk -v date=$(date +"%Y-%m-%d") \ + -v version="$RELEASE_VERSION" ' + NR == 2 { + print "\n" + print "## " version " - (" date ")" + while (getline line < "/dev/stdin") { + print line + } + next + } + {print} + ' CHANGELOG.md < <(echo "$GROUPED_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" + git push origin HEAD + - name: Create Pull Request env: GH_TOKEN: ${{ github.token }}