name: "Continuous Integration"

on:
  pull_request:
  push:
    branches:
      - "*.x"

jobs:
  composer_normalize:
    name: "Composer Normalize"
    runs-on: "ubuntu-20.04"
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - uses: "docker://ergebnis/composer-normalize-action:latest"
        with:
          args: "--dry-run"

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

    strategy:
      matrix:
        dbal-version:
          - "^2.11"
          - "^3.0"
        php-version:
          - "7.2"
          - "7.3"
          - "7.4"
          - "8.0"
        dependencies:
          - "highest"
        include:
          - deps: "lowest"
            php-version: "7.2"
        exclude:
          - dbal-version: "^3.0"
            php-version: "7.2"

    steps:
      - name: "Checkout"
        uses: "actions/checkout@v2"

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          php-version: "${{ matrix.php-version }}"
          coverage: "pcov"
          extensions: "pdo_sqlite"
          ini-values: "zend.assertions=1"
          # Remove this line when a fix for is available https://github.com/box-project/box/issues/555
          tools: "composer:v2.0.14"

      - name: "Download box"
        run: "./download-box.sh"

      - name: "Require the right DBAL version"
        run: "composer require doctrine/dbal:${{ matrix.dbal-version }} --no-update"
        if: "${{ matrix.dbal-version }}"

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

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

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

  phpunit-with-symfony-6:
    name: "PHPUnit with Symfony 6.0.x-dev"
    uses: "doctrine/.github/.github/workflows/continuous-integration-symfony-unstable.yml@1.4.1"
    with:
      symfony-version-constraint: "6.0.*"

  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
