Skip to content

Exclude JSON and CSV resources from composer distribution #144

Exclude JSON and CSV resources from composer distribution

Exclude JSON and CSV resources from composer distribution #144

Workflow file for this run

name: Tests
on:
pull_request:
branches: [main]
push:
branches: [main]
# paths: ['.github/**.yml', 'src/*', 'tests/*']
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CC_TEST_REPORTER_URL: ${{ vars.CC_TEST_REPORTER_URL }}
DB_USERNAME: creasico
DB_PASSWORD: secret
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare:
name: Prepare Database
runs-on: ubuntu-latest
env:
DB_NUSA: nusantara
outputs:
composer-cache: ${{ steps.composer-cache.outputs.dir }}
strategy:
fail-fast: false
matrix:
php: ['8.1']
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.DB_NUSA }}
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: xdebug
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: composer update --prefer-dist --no-interaction --no-progress
- name: Import databases
run: composer db:import
tests:
name: Test on PHP ${{ matrix.php }} with DB ${{ matrix.db }}
needs: prepare
runs-on: ubuntu-latest
env:
DB_CONNECTION: ${{ matrix.db }}
DB_DATABASE: 'creasico'
services:
postgresql:
image: postgres:14
env:
POSTGRES_DB: ${{ env.DB_DATABASE }}
POSTGRES_USER: ${{ env.DB_USERNAME }}
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 5432:5432
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.DB_DATABASE }}
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
db: ['mysql', 'pgsql', 'sqlite']
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: xdebug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: ${{ needs.prepare.outputs.composer-cache }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: composer update --prefer-dist --no-interaction --no-progress
- name: Run tests
run: composer test -- --coverage
- name: Generate reports for CodeClimate
if: github.actor != 'dependabot[bot]'
env:
COVERAGE_FILE: tests/reports/clover.xml
CODECLIMATE_REPORT: ${{ github.workspace }}/tests/reports/codeclimate.${{ matrix.php }}.json
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t clover -o $CODECLIMATE_REPORT $COVERAGE_FILE
- name: Upload tests reports
uses: actions/upload-artifact@v3
if: github.actor != 'dependabot[bot]'
with:
name: test-reports
path: tests/reports
reports:
name: Report Test Coverages
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
needs: tests
steps:
- name: Download test reports
uses: actions/download-artifact@v3
with:
name: test-reports
- name: Report to CodeClimate
run: |
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
./cc-test-reporter sum-coverage -o - codeclimate.*.json | ./cc-test-reporter upload-coverage --input -