name: Test Requirements Lockfiles Check
on:
  push:
    branches:
      - main
      - 'mq-working-branch**'
  pull_request:
    types: [opened, reopened, synchronize]

jobs:
  validate:
    name: Check requirements lockfiles
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/datadog/dd-trace-py/testrunner:adc7896c0901c0589e45776d9e409c3d1b15cd51@sha256:5fa1b0062e20c753cd5da590df3841b74b9ead5b4531a7ec9f5cacd2b95386e3
      options: "--user 0"
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Fixup git permissions
        # https://github.com/actions/checkout/issues/766
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

      - name: Set python interpreters
        run: pyenv global 3.10 3.8 3.9 3.11 3.12 3.13 3.14

      - name: Install Dependencies
        # Keep pip at <25.3 until https://github.com/jazzband/pip-tools/issues/2252 is resolved
        run: pip install --upgrade "pip<25.3" && pip install riot==0.20.1 && pip install toml==0.10.2

      - name: Generate riot locks
        run: scripts/compile-and-prune-test-requirements

      - name: Check locks diff
        run: scripts/check-diff '.riot/requirements/' 'Mismatches found between .riot/requirements/*.txt and riotfile.py. Run scripts/compile-and-prune-test-requirements and commit the result.'

      - name: Generate tracer requirements csv
        run: python scripts/requirements_to_csv.py

      - name: Check tracer requirements csv diff
        run: scripts/check-diff 'requirements.csv' 'Tracer dependency requirements in requirements.csv is out of date. Run `python scripts/requirements_to_csv.py` and commit the result.'
