|
| 1 | +name: Update Changelog on PR Merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - closed |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-changelog: |
| 10 | + name: Update Changelog |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.event.pull_request.merged == true |
| 13 | + |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + ref: ${{ github.event.pull_request.base.ref }} |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Determine changelog section to update |
| 25 | + id: sections |
| 26 | + run: | |
| 27 | + section="" |
| 28 | + labels=$(echo '${{ toJSON(github.event.pull_request.labels.*.name) }}' | jq -r '.[]') |
| 29 | + for label in $labels; do |
| 30 | + lower_label=$(echo "$label" | tr '[:upper:]' '[:lower:]') |
| 31 | + case "$lower_label" in |
| 32 | + enhancement|feature) section="Added"; break;; |
| 33 | + bug|bugfix|fix|patch) section="Fixed"; break;; |
| 34 | + change) section="Changed"; break;; |
| 35 | + optimization|improvement|performance|refactor) section="Optimized"; break;; |
| 36 | + deprecation|deprecated) section="Deprecated"; break;; |
| 37 | + revert) section="Reverted"; break;; |
| 38 | + removal) section="Removed"; break;; |
| 39 | + security) section="Security"; break;; |
| 40 | + esac |
| 41 | + done |
| 42 | +
|
| 43 | + if [ -z "$section" ]; then |
| 44 | + echo "No matching label found for changelog entry, skipping changelog update." |
| 45 | + exit 0 |
| 46 | + else |
| 47 | + echo "section=$section" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Add entry to CHANGELOG.md |
| 51 | + if: steps.sections.outputs.section != '' |
| 52 | + uses: claudiodekker/changelog-updater@master |
| 53 | + with: |
| 54 | + section: "${{ steps.sections.outputs.section }}" |
| 55 | + entry-text: "${{ github.event.pull_request.title }}" |
| 56 | + entry-link: "${{ github.event.pull_request.html_url }}" |
| 57 | + |
| 58 | + - name: Commit updated CHANGELOG |
| 59 | + if: steps.sections.outputs.section != '' |
| 60 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 61 | + with: |
| 62 | + branch: ${{ github.event.pull_request.base.ref }} |
| 63 | + commit_message: "Update CHANGELOG.md w/ PR #${{ github.event.pull_request.number }}" |
| 64 | + file_pattern: CHANGELOG.md |
0 commit comments