Skip to content

Continue Utility class review #1132

Continue Utility class review

Continue Utility class review #1132

Workflow file for this run

name: CI
on:
push:
branches:
- main
paths:
# Same as .ci-pathspec
- ".github/workflows/**"
- "bin/**"
- "scripts/**"
- "src/**"
- "tests/**"
- "tools/**"
- ".ci-pathspec"
- ".gitattributes"
- ".php-cs-fixer.dist.php"
- ".prettyphp"
- "codecov.yml"
- "composer.json"
- "composer.lock"
- "phpstan*"
- "phpunit.xml.dist"
pull_request:
workflow_call:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
check-ci-runs:
name: Check previous runs
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-24.04
outputs:
ci_required: ${{ steps.check-ci-runs.outputs.ci_required }}
steps:
- name: Check CI runs
id: check-ci-runs
uses: lkrms/check-ci-runs@v1
with:
ci_workflows: CI
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
check:
name: Check generated files and formatting
needs:
- check-ci-runs
if: ${{ (github.event_name != 'pull_request' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
# PHP 8.3 is needed to parse DNF types in test fixtures, and
# php-cs-fixer doesn't support PHP 8.4
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
coverage: none
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Check generated files
run: scripts/generate.php --check
- name: Run PHP CS Fixer
run: tools/php-cs-fixer check --diff --verbose
- name: Run pretty-php
run: tools/pretty-php --diff
phpstan:
name: PHPStan
needs:
- check
- check-ci-runs
if: ${{ (github.event_name != 'pull_request' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
php-version:
- "8.4"
- "7.4"
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Persist PHPStan cache
uses: actions/cache@v4
with:
path: build/cache/phpstan
key: phpstan-cache-${{ runner.os }}-${{ matrix.php-version }}-${{ github.run_id }}
restore-keys: phpstan-cache-${{ runner.os }}-${{ matrix.php-version }}-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Run PHPStan
run: vendor/bin/phpstan
unit-tests:
name: PHPUnit tests
needs:
- check
- check-ci-runs
if: ${{ (github.event_name != 'pull_request' || needs.check-ci-runs.outputs.ci_required == 1) && !cancelled() && !failure() }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
- windows-latest
- macos-latest
php-version:
- "8.4"
include:
- os: ubuntu-24.04
php-version: "8.3"
- os: ubuntu-24.04
php-version: "8.2"
- os: ubuntu-24.04
php-version: "8.1"
- os: ubuntu-24.04
php-version: "8.0"
- os: ubuntu-24.04
php-version: "7.4"
- os: windows-latest
php-version: "7.4"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP and Composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: fileinfo, sqlite3
coverage: pcov
- name: Get Composer cache directory
id: get-composer-cache
shell: bash
run: printf 'cache_dir=%s\n' "$(composer config cache-files-dir)" >>"$GITHUB_OUTPUT"
- name: Cache PHP dependencies
uses: actions/cache@v4
with:
path: ${{ steps.get-composer-cache.outputs.cache_dir }}
key: composer-cache-${{ runner.os }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: composer-cache-${{ runner.os }}-
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: npm
cache-dependency-path: tools/*/package-lock.json
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress
- name: Install Node.js dependencies
shell: bash
run: |
for file in tools/*/package-lock.json; do
(cd "${file%/*}" && npm install)
done
- name: Start Mockoon CLI
id: start-mockoon
shell: bash
run: scripts/start-mockoon.sh
- name: Run PHPUnit tests and generate code coverage report
id: run-phpunit-tests
shell: bash
run: |
scripts/delete-covers.php --force
vendor/bin/phpunit ${RUNNER_DEBUG+--debug} ${RUNNER_DEBUG+--no-extensions} --no-coverage --coverage-clover=coverage.xml --log-junit=junit.xml && status=0 || status=$?
printf 'coverage_generated=%d\n' "$([[ -s coverage.xml ]] && echo 1 || echo 0)" >>"$GITHUB_OUTPUT"
printf 'results_generated=%d\n' "$([[ -s junit.xml ]] && echo 1 || echo 0)" >>"$GITHUB_OUTPUT"
(exit $status)
- name: Upload coverage to Codecov
if: ${{ !cancelled() && steps.run-phpunit-tests.outputs.coverage_generated == 1 }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() && steps.run-phpunit-tests.outputs.results_generated == 1 }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload Mockoon CLI log files artifact
if: ${{ !cancelled() && steps.start-mockoon.conclusion == 'success' }}
uses: actions/upload-artifact@v4
with:
name: mockoon-cli-logs-${{ matrix.os }}-${{ matrix.php-version }}
path: ~/.mockoon-cli/logs/*.log