name: Python tests

on:
  workflow_call:
    inputs:
      compiler-ref:
        required: false
        type: string
      reactor-c-ref:
        required: false
        type: string
      reactor-c-py-ref:
        required: false
        type: string
      all-platforms:
        required: false
        default: true
        type: boolean

jobs:
  regular-tests:
    strategy:
      matrix:
        platform: ${{ (inputs.all-platforms && fromJSON('["ubuntu-24.04", "macos-latest", "windows-latest"]')) || fromJSON('["ubuntu-24.04"]') }}
    runs-on: ${{ matrix.platform }}
    steps:
      - name: Check out lingua-franca repository
        uses: actions/checkout@v3
        with:
          repository: lf-lang/lingua-franca
          submodules: true
          ref: ${{ inputs.compiler-ref }}
          fetch-depth: 0
      - name: Prepare build environment
        uses: ./.github/actions/prepare-build-env
      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.12'
      - name: Install dependencies OS X
        run: |
          brew install coreutils
        if: ${{ runner.os == 'macOS' }}
      - name: Install LinguaFrancaBase
        run: pip3 install LinguaFrancaBase
      - name: Install Google API Python Client
        run: pip3 install --upgrade google-api-python-client
      - name: Check out specific ref of reactor-c
        uses: actions/checkout@v3
        with:
          repository: lf-lang/reactor-c
          path: core/src/main/resources/lib/c/reactor-c
          ref: ${{ inputs.reactor-c-ref }}
        if: ${{ inputs.reactor-c-ref }}
      - name: Check out specific ref of reactor-c-py
        uses: actions/checkout@v3
        with:
          repository: lf-lang/reactor-c-py
          path: core/src/main/resources/lib/py/reactor-c-py
          ref: ${{ inputs.reactor-c-py-ref }}
        if: ${{ inputs.reactor-c-py-ref }}
      - name: Install RTI
        uses: ./.github/actions/install-rti
        if: ${{ runner.os == 'macOS' || runner.os == 'Linux' }}
      - name: Run Python tests
        run: ./gradlew targetTest -Ptarget=Python
      - name: Report to CodeCov
        uses: ./.github/actions/report-code-coverage
        with:
          files: core/build/reports/jacoco/integrationTestCodeCoverageReport/integrationTestCodeCoverageReport.xml
        if: ${{ github.repository == 'lf-lang/lingua-franca' }}
