name: Coverage

on:
  pull_request:

  push:
    branches: ["*"]

  schedule:
    - cron: "0 8 * * 1"

jobs:
  test80:
    runs-on: ubuntu-latest
    name: PHPUnit
    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2"

      - name: "Setup PHP cache environment"
        id: "extcache"
        uses: "shivammathur/cache-extensions@v1"
        with:
          php-version: "8.0"
          extensions: "pcov"
          key: "v1"

      - name: "Cache PHP extensions"
        uses: "actions/cache@v2"
        with:
          path: "${{ steps.extcache.outputs.dir }}"
          key: "${{ steps.extcache.outputs.key }}"
          restore-keys: "${{ steps.extcache.outputs.key }}"

      - name: Setup PHP with PCOV
        uses: shivammathur/setup-php@v2
        with:
          php-version: "8.0"
          coverage: "pcov"

      - name: "Setup problem matchers for PHP"
        shell: "bash"
        run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'

      - name: "Composer"
        run: "composer install --prefer-dist --no-progress --no-suggest"

      - name: "Run PHPUnit"
        run: "make coverage"

      - name: "Coveralls.io"
        env:
          CI_NAME: github
          CI: true
          COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
        run: |
          wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.1/php-coveralls.phar
          php php-coveralls.phar --verbose --config tests/.coveralls.yml
