name: python-presubmit
on:
  push:
    branches: ['master']
  pull_request:
    paths: ['python/**', '.github/workflows/presubmit-python.yml']
  workflow_dispatch: {}

defaults:
  run:
    working-directory: python

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: yapf
        run: |
          python -m pip install --upgrade yapf
          find . -type f -name '*.py' -print0 | \
            xargs -0 --verbose yapf -d --style google
      - name: pylint
        # pylint checks only pyglome/*
        run: |
          python -m pip install --upgrade pylint
          find pyglome -type f -name '*.py' -print0 | \
            xargs -0 --verbose pylint

  unit-test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12"]

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Run tests
        run: python -m test
