name: Integration Interop

on:
  pull_request:

jobs:
  interop:
    name: Interop (${{ matrix.scenario }} / ${{ matrix.mode }})
    runs-on: ubuntu-latest
    timeout-minutes: 90
    strategy:
      fail-fast: false
      matrix:
        include:
          - scenario: superseedr_to_superseedr
            mode: v1
          - scenario: superseedr_to_superseedr
            mode: v2
          - scenario: superseedr_to_superseedr
            mode: hybrid
          - scenario: superseedr_to_qbittorrent
            mode: v1
          - scenario: superseedr_to_qbittorrent
            mode: v2
          - scenario: superseedr_to_qbittorrent
            mode: hybrid
          - scenario: qbittorrent_to_superseedr
            mode: v1
          - scenario: qbittorrent_to_superseedr
            mode: v2
          - scenario: qbittorrent_to_superseedr
            mode: hybrid
          - scenario: superseedr_to_transmission
            mode: v1
          - scenario: transmission_to_superseedr
            mode: v1

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install -r requirements-integration.txt

      - name: Decide mode for this matrix shard
        id: select_mode
        run: |
          echo "scenario=${{ matrix.scenario }}" >> "$GITHUB_OUTPUT"
          echo "mode=${{ matrix.mode }}" >> "$GITHUB_OUTPUT"
          echo "run=true" >> "$GITHUB_OUTPUT"

      - name: Run interop harness
        if: steps.select_mode.outputs.run == 'true'
        env:
          INTEROP_TIMEOUT_SECS: "300"
        run: |
          ./integration_tests/run_interop.sh "${{ steps.select_mode.outputs.mode }}" "${{ steps.select_mode.outputs.scenario }}"

      - name: Upload interop artifacts
        if: always() && steps.select_mode.outputs.run == 'true'
        uses: actions/upload-artifact@v4
        with:
          name: interop-artifacts-${{ matrix.scenario }}-${{ matrix.mode }}-${{ github.run_id }}
          path: integration_tests/artifacts/
