diff --git a/.github/scripts/group-commit-message.awk b/.github/scripts/group-commit-message.awk new file mode 100755 index 0000000..9e58ce9 --- /dev/null +++ b/.github/scripts/group-commit-message.awk @@ -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 +} diff --git a/.github/workflows/kick-off-release.yaml b/.github/workflows/kick-off-release.yaml index 9634ac6..402ad16 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,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 }}