name: "Check combinations.json"
on:
  schedule:
  # Run at midnight on the first of every month
  # https://crontab.guru/once-a-month
  - cron: "0 0 1 * *"

  workflow_dispatch:
  push:
    paths:
      - 'ci/**'

jobs:
  check_combinations:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 20
      
    - name: Update the "update-combinations" branch (ff merge to master)
      uses: MaximeHeckel/github-action-merge-fast-forward@b4e9b28dce30a682e5fbe3135be4053ea2a75e15
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        branchtomerge: "origin/master"
        branch: "update-combinations"

    - name: Set up Python 3.9
      uses: actions/setup-python@v4
      with:
        python-version: '3.9'

    - name: Build and install
      run: |
        python -m pip install ./ --user

    - name: Install generate_combinations dependencies
      run: pip install -U jsoncomparison

    - name: Check combinations.json
      run: PYTHONPATH=$(pwd) python3 ci/generate_combinations.py --write --no-tqdm

    - name: Commit and make pull request
      uses: gr2m/create-or-update-pull-request-action@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        title: "Update `aqt/combinations.json`"
        body: |
          The `ci/generate_combinations.py` script has detected changes to the repo at https://download.qt.io.
          This PR will update `aqt/combinations.json` to account for those changes.

          Posted from [the `check_combinations` action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})

        branch: "update-combinations"
        path: "aqt/combinations.json"
        commit-message: "Update aqt/combinations.json"
        author: "Qt Repo Watchbot <qtrepowatchbot[bot]@users.noreply.github.com>"
