name: Changelog Generator

on:
  schedule:
    - cron: '0 0 * * 1'
  push:
    tags:
      - '*.*.*'

jobs:
  changelog:
    name: Changelog Generator
    runs-on: ubuntu-22.04
    timeout-minutes: 30

    steps:
      - name: Create release
        run: |
          if [[ ${{ env.GITHUB_REF_NAME }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            gh release create ${{ env.GITHUB_REF_NAME }}
          fi
        if: env.GITHUB_REF_TYPE == 'tag'

      - name: Get Date
        id: get-date
        run: |
          echo "date=$(/bin/date -u "+%Y%m%d%H%M%S")" >> $GITHUB_OUTPUT
      - uses: actions/cache@v3
        with:
          path: .cache
          key: automation-${{ steps.get-date.outputs.date }}
          restore-keys: |
            automation-

      - run: docker pull aeonphp/automation
      - name: Generate changelog
        run: >
          docker run --env=AEON_AUTOMATION_GH_TOKEN --rm --volume=$(pwd)/.cache:/cache aeonphp/automation
          changelog:generate:all
          ${{ github.repository }}
          --github-release-update
          --cache-path=/cache
          --skip-from=dependabot-preview[bot]
          --skip-from=dependabot[bot]
          --skip-from=renovate[bot]
          -v
        env:
          AEON_AUTOMATION_GH_TOKEN: ${{ secrets.TOKEN }}
