name: integration tests

on:
  workflow_dispatch:
    inputs:
      branch:
        description: 'Branch to test on'
        required: true

permissions: {}

jobs:
  run_transformers_integration_tests:
    strategy:
      fail-fast: false
      matrix:
        transformers-version: ['main', 'latest']
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8  # v5.0.0
        with:
          ref: ${{ github.event.inputs.branch }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          persist-credentials: false
      - name: Set up Python
        uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c  # v6.0.0
        with:
          python-version: "3.10"
          cache: "pip"
          cache-dependency-path: "setup.py"
      - name: print environment variables
        run: |
          echo "env.CI_BRANCH = ${CI_BRANCH}"
          echo "env.CI_SHA = ${CI_SHA}"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install .[test]
          if [ "${{ matrix.transformers-version }}" == "main" ]; then
              pip install -U git+https://github.com/huggingface/transformers.git
          else
              echo "Nothing to do as transformers latest already installed"
          fi

      - name: Test transformers integration
        run: |
          cd .. && git clone https://github.com/huggingface/transformers.git && cd transformers/ && git rev-parse HEAD
          RUN_SLOW=1 pytest tests/peft_integration/test_peft_integration.py
  run_diffusers_integration_tests:
    strategy:
      fail-fast: false
      matrix:
        # For now diffusers integration is not on PyPI
        diffusers-version: ['main']
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8  # v5.0.0
        with:
          ref: ${{ github.event.inputs.branch }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          persist-credentials: false
      - name: Set up Python
        uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c  # v6.0.0
        with:
          python-version: "3.10"
          cache: "pip"
          cache-dependency-path: "setup.py"
      - name: print environment variables
        run: |
          echo "env.CI_BRANCH = ${CI_BRANCH}"
          echo "env.CI_SHA = ${CI_SHA}"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install .[test]

          if [ "${{ matrix.diffusers-version }}" == "main" ]; then
              pip install -U git+https://github.com/huggingface/diffusers.git
          else
              echo "Nothing to do as diffusers latest already installed"
          fi

      - name: Test diffusers integration
        run: |
          cd .. && git clone https://github.com/huggingface/diffusers.git && cd diffusers/ && git rev-parse HEAD
          pytest tests/lora/test_lora_layers_peft.py
