# Action to run pip-compile weekly and create a Pull Request with the changes.
# Althought GitHub says that pip-compile is supported by dependabot, we couldn't make it work together.
# That's why this action exists.
# If we ever find the proper configuration for dependabot+pip-compile,
# we can delete this action.

name: Update dependencies with pip-tools

on:
  schedule:
    # Run weekly on Mondays at 00:00 UTC
    - cron: "0 0 * * 1"

jobs:
  update-dependencies:
    name: Update dependencies
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        with:
          python-version: "3.10"
      - name: Install test dependencies
        run: python -m pip install -U pip-tools
      - name: Run pip-compile
        run: pip-compile --upgrade --extra=doc --output-file=docs/requirements.txt pyproject.toml
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          add-paths: |
            docs/requirements.txt
          title: |
            Dependencies: all packages updated via pip-tools
          body: |
            Dependencies: all packages updated via pip-tools
          commit-message: |
            Dependencies: all packages updated via pip-tools
          delete-branch: true
          branch: dependencies/pip-tools
          branch-suffix: short-commit-hash
          team-reviewers: readthedocs/backend
