name: ci

on:
  push:
    branches:
      - '*'
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
    branches:
      - 'master'
  schedule:
    - cron: '1 9 * * 0'

jobs:
  test_unit:
    name: Unit Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - php: '7.1'
          - php: '7.2'
          - php: '7.3'
          - php: '7.4'
          - php: '8.0'
          - php: '8.1'
          - php: '8.2'
          - php: '8.3'
    steps:
      - name: checkout
        uses: actions/checkout@v3
      - name: Setup PHP Action
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
      - name: run unit tests
        run: |
          # create folder for coverage
          mkdir -p build/logs
          
          # use phpunit9 for php8 and phpunit6 for 7.1 to 7.4
          composer update
          
          # create a lock file
          composer install
          
          composer run-script test
      - name: docs healthcheck
        run: |
          php ci/check_filters_docs.php
          php ci/check_validators_docs.php
          php ci/check_validators_translations.php
      # it is enough to upload the coverage once!
      - name: upload coverage
        if: matrix.php == '7.1'
        env:
          COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: php vendor/bin/php-coveralls --exclude-no-stmt --coverage_clover=build/logs/clover.xml -v
