name: Update Changelog

on:
    push:
      tags:
        - '*'
    workflow_dispatch:

jobs:
  update-changelog:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.24.x

      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Update Changelog
        run: |
          go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest
          git-chglog -o CHANGELOG.md

      - name: Commit changes
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git commit -a -m "update CHANGELOG.md"

      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ github.ref }}
