name: Code Climate

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4
          tools: composer:v2

      - name: Install dependencies
        run: composer install --prefer-dist --no-progress

      - name: Run test suite
        run: composer run-script test:coverage

      - name: Code Coverage
        env:
            CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_REPORTER_ID }}
        # Linux: https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
        # macOS: https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64
        run: |
          curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
          chmod +x ./cc-test-reporter
          ./cc-test-reporter after-build -t clover build/logs/clover.xml
