name: Update Changelog

on:
  push:
    branches:
      - dev
  workflow_dispatch:

permissions:
  contents: write
jobs:
  changelog:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Generate Changelog
        uses: janheinrichmerker/action-github-changelog-generator@v2.3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Commit and push changes (if any)
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"

          git add CHANGELOG.md

          if git diff --cached --quiet; then
            echo "No changes to commit."
            exit 0
          fi

          git commit -m "chore: update changelog"
          git push
