
name: "Continuous Integration"

on:
  pull_request:

jobs:
  roave_bc_check:
    name: "Roave BC Check"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: fetch tags
        run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
      - name: Roave BC Check
        uses: docker://nyholm/roave-bc-check-ga

  phpunit:
    name: "PHPUnit"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php-version:
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"
        dependencies:
          - "highest"
        include:
          - dependencies: "lowest"
            php-version: "7.2"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2"
        with:
          fetch-depth: 2

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php-version }}"
          coverage: "pcov"
          ini-values: "zend.assertions=1"

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"
        with:
          dependency-versions: "${{ matrix.dependencies }}"
          composer-options: "--prefer-dist"

      - name: "Run PHPUnit"
        run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

      - name: "Upload coverage file"
        uses: "actions/upload-artifact@v2"
        with:
          name: "phpunit-${{ matrix.dependencies }}-${{ matrix.php-version }}.coverage"
          path: "coverage.xml"

  phpunit-lower-php-versions:
    name: "PHPUnit"
    runs-on: "ubuntu-20.04"

    strategy:
      matrix:
        php-version:
          - "7.1"
        dependencies:
          - "highest"
        include:
          - dependencies: "lowest"
            php-version: "7.1"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2"
        with:
          fetch-depth: 2

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php-version }}"
          ini-values: "zend.assertions=1"

      - name: "Install dependencies with Composer"
        uses: "ramsey/composer-install@v1"
        with:
          dependency-versions: "${{ matrix.dependencies }}"
          composer-options: "--prefer-dist"

      - name: "Run PHPUnit"
        run: "vendor/bin/phpunit"

  upload_coverage:
    name: "Upload coverage to Codecov"
    runs-on: "ubuntu-20.04"
    needs:
      - "phpunit"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2"
        with:
          fetch-depth: 2

      - name: "Download coverage files"
        uses: "actions/download-artifact@v2"
        with:
          path: "reports"

      - name: "Upload to Codecov"
        uses: "codecov/codecov-action@v1"
        with:
          directory: reports

