ekinhbayar/gitamp

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: CI

on: [pull_request, push]

env:
  COMPOSER_COMMAND: composer update
  COMPOSER_ARGS: --no-interaction --no-progress

jobs:
  Dependencies:
    runs-on: ubuntu-latest
    name: Check Dependencies
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          coverage: none
          tools: composer-require-checker

      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install dependencies
        run: composer install $COMPOSER_ARGS

      - name: Run require check
        run: composer-require-checker

  Coding-Standards:
    runs-on: ubuntu-latest
    continue-on-error: true #TODO: Remove this once we get to a passing baseline
    name: Check Coding Standards
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '7.4'
          coverage: none
          tools: cs2pr

      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install dependencies
        run: composer install $COMPOSER_ARGS

      - name: Run coding standards check
        run: ./vendor/bin/phpcs -q --report=full --report-checkstyle=checkstyle-report.xml

      - name: Annotate pull request
        if: ${{ github.event_name == 'pull_request' }}
        run: cs2pr checkstyle-report.xml

  Tests:
    strategy:
      fail-fast: false
      matrix:
        php-versions: ['7.4', '8.0']
        deps: [lowest, highest, locked]
        include:
          - deps: lowest
            deps-arg: --prefer-lowest
          - deps: locked
            composer-command: composer install
            hash-file: '**/composer.lock'
    runs-on: ubuntu-latest
    name: Test on PHP ${{ matrix.php-versions }} with deps ${{ matrix.deps }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup PHP ${{ matrix.php-versions }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-versions }}
          coverage: pcov
        env:
          update: true

      - name: Setup problem matchers for PHPUnit
        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: >-
            ${{ format('{0}-composer-{1}-{2}',
            runner.os,
            matrix.deps,
            hashFiles(matrix.hash-file || '**/composer.json')
            ) }}
          restore-keys: ${{ runner.os }}-composer-${{ matrix.deps }}-

      - name: Install ${{ matrix.deps }} dependencies
        env:
          COMPOSER_COMMAND: ${{ matrix.composer-command || env.COMPOSER_COMMAND }}
        run: $COMPOSER_COMMAND $COMPOSER_ARGS ${{ matrix.deps-arg }}

      - name: Run tests
        run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

      - name: Upload coverage to Scrutinizer
        if: ${{ matrix.php-versions != '8.0' }}
        run: |
          wget https://scrutinizer-ci.com/ocular.phar
          php ocular.phar code-coverage:upload --format=php-clover coverage.clover