name: CI

# see https://github.community/t5/GitHub-Actions/How-to-trigger-an-action-on-push-or-pull-request-but-not-both/m-p/35805
on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master
  schedule:
    # Run workflow every morning (* needs quotes).
    - cron: '0 4 * * *'


jobs:
  run-tests:

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [macos-11, macos-12, ubuntu-20.04, ubuntu-22.04]

    steps:
    - uses: actions/checkout@v3

    - name: Show environment
      run: |
        python --version
        python3 --version
        python3 -c "import multiprocessing as m; print('CPUs:', m.cpu_count())"

    - name: Install dependencies (Ubuntu)
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        sudo apt-get update
        sudo apt-get -y install -qq gettext gir1.2-gdkpixbuf-2.0 gir1.2-glib-2.0 gir1.2-gtk-3.0 gir1.2-gtksource-4 gir1.2-pango-1.0 gir1.2-webkit2-4.0 python3 python3-enchant python3-gi python3-yaml

    - name: Install dependencies (macOS)
      if: startsWith(matrix.os, 'macos')
      run: |
        # We need pygobject from PyPI. Using only pygobject3 from homebrew leads to "gi module not found".
        brew install gettext gtk+3 gobject-introspection glib libffi cairo gtksourceview3 atk librsvg gsettings-desktop-schemas adwaita-icon-theme enchant
        python3 -m pip install pyenchant pygobject pyyaml

    - name: Install common dependencies
      run: |
        python3 -m pip install setuptools==59.6.0 tox==3.27.1

    - name: Check style
      if: matrix.os == 'ubuntu-22.04'
      run: |
        python3 -m tox -v -e style

    - name: Run tests
      run: |
        python3 -c "import gi"
        python3 -m tox -v -e py
        python3 -m pip install .
