name: Dependency Update Check

on:
  schedule:
    - cron: '0 0 * * 1'  # Weekly on Monday at midnight UTC
  workflow_dispatch:

jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Install UV
        run: |
          curl -LsSf https://astral.sh/uv/install.sh | sh
          echo "$HOME/.cargo/bin" >> $GITHUB_PATH

      - name: Update Dependencies
        working-directory: backend
        run: |
          uv lock --upgrade
          uv sync

      - name: Run Tests
        working-directory: backend
        run: |
          uv run manage.py test

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v8
        with:
          commit-message: "chore: update dependencies"
          title: "chore: weekly dependency updates"
          body: |
            Automated dependency updates.

            This PR was automatically generated by the dependency update workflow.

            ## Changes
            - Updated `uv.lock` with latest compatible versions

            ## Checklist
            - [ ] Review dependency changes
            - [ ] Verify all tests pass
            - [ ] Check for breaking changes
          branch: "dependency-updates"
          labels: dependencies
