name: changelog

on:
  push:
    branches:
      - 'master'

jobs:
  create_changelog:
    runs-on: ubuntu-latest

    steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: install
        run: |
          pip install auto-changelog

      - name: generate
        env:
          REPO: ${{github.repository}}
        run: |
          auto-changelog --unreleased --latest-version latest \
            --remote "https://github.com/${REPO}.git" \
            --diff-url "https://github.com/${REPO}/compare/{previous}...{current}" \
            --issue-url "https://github.com/${REPO}/issues/{id}"

      - name: change log PR
        uses: peter-evans/create-pull-request@v3
        with:
          commit-message: "chore: changelog bump"
          delete-branch: true
          title: 'chore: update changelog'
          body: |
            Updates the changelog with the latest updates
            This is raised as a draft and should be merged before tagging a release
          labels: 'chore'
          base: 'master'
          branch: create-pull-request/changelog_bump
          draft: true
