name: changelog

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

jobs:
  changelog:
    name: Generate changelog
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Generate a changelog
        uses: orhun/git-cliff-action@v1
        id: git-cliff
        with:
          config: cliff.toml
          args: --verbose
        env:
          OUTPUT: CHANGELOG.md

      - name: Commit the changelog
        uses: EndBug/add-and-commit@v9
        with:
          add: 'CHANGELOG.md'
          author_name: Git Cliff
          committer_name: Git Cliff
          message: 'chore: update CHANGELOG.md'
          push: origin HEAD:master
