
name: "Continuous Integration"

on: ["pull_request", "push"]

jobs:
  static-analysis-phpstan:
    name: "Static Analysis with PHPStan"
    runs-on: "ubuntu-latest"

    strategy:
      matrix:
        php-version:
          - "7.4"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "none"
          php-version: "${{ matrix.php-version }}"
          tools: "cs2pr"

      - name: "Cache dependencies installed with composer"
        uses: "actions/cache@v1"
        with:
          path: "~/.composer/cache"
          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
          restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

      - name: "Install dependencies with composer"
        run: "composer install --no-interaction --no-progress --no-suggest"

      - name: "Run a static analysis with phpstan/phpstan"
        run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr"

  static-analysis-psalm:
    name: "Static Analysis with Psalm"
    runs-on: "ubuntu-latest"

    strategy:
      matrix:
        php-version:
          - "7.4"

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

      - name: "Install PHP"
        uses: "shivammathur/setup-php@v2"
        with:
          coverage: "none"
          php-version: "${{ matrix.php-version }}"

      - name: "Cache dependencies installed with composer"
        uses: "actions/cache@v1"
        with:
          path: "~/.composer/cache"
          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
          restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

      - name: "Install dependencies with composer"
        run: "composer install --no-interaction --no-progress --no-suggest"

      - name: "Run a static analysis with vimeo/psalm"
        run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4"

  phpunit-oci8:
    name: "PHPUnit on OCI8"
    runs-on: "ubuntu-latest"

    strategy:
      matrix:
        php-version:
          - "7.4"

    services:
      oracle:
        image: "wnameless/oracle-xe-11g-r2"
        ports:
          - "1521:1521"

    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 }}"
          extensions: "oci8"
          coverage: "pcov"

      - name: "Cache dependencies installed with composer"
        uses: "actions/cache@v1"
        with:
          path: "~/.composer/cache"
          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
          restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

      - name: "Install dependencies with composer"
        run: "composer install --no-interaction --no-progress --no-suggest"

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

      - name: "Upload Code Coverage"
        uses: "codecov/codecov-action@v1"

  phpunit-pdo-oci:
    name: "PHPUnit on PDO_OCI"
    runs-on: "ubuntu-latest"

    strategy:
      matrix:
        php-version:
          - "7.4"

    services:
      oracle:
        image: "wnameless/oracle-xe-11g-r2"
        ports:
          - "1521:1521"

    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 }}"
          extensions: "pdo_oci"
          coverage: "pcov"

      - name: "Cache dependencies installed with composer"
        uses: "actions/cache@v1"
        with:
          path: "~/.composer/cache"
          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
          restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

      - name: "Install dependencies with composer"
        run: "composer install --no-interaction --no-progress --no-suggest"

      - name: "Run PHPUnit"
        run: "vendor/bin/phpunit -c ci/github/phpunit.pdo-oci.xml --coverage-clover=coverage.xml"

      - name: "Upload Code Coverage"
        uses: "codecov/codecov-action@v1"
