Skip to content

Enhance CI workflow input handling and defaults #943

Enhance CI workflow input handling and defaults

Enhance CI workflow input handling and defaults #943

# GitHub Actions workflow specifically designed for running PHPUnit tests
# This workflow is optimized to install only the necessary dependencies for PHPUnit
# and explicitly avoids installing development tools to prevent latest PHP compatibility issues
name: Continuous Integration
on:
push:
paths-ignore:
- '**.md' # Skip workflow on documentation changes only
pull_request:
workflow_dispatch: # Enable manual trigger (inputs can be provided manually here)
workflow_call: # Enable calling from other workflows
inputs:
old_stable:
required: false
type: string
default: '[]' # Default for workflow_call if 'old_stable' input is not provided by the caller.
# Example, if caller wants specific old stables: '["8.0", "8.1"]'
# If caller wants NO old stables, they can pass '[]' or omit it to use this default.
current_stable:
required: true # Required for workflow_call. Example from caller: "8.4" or "8.5"
type: string
script:
required: false
type: string
env: # This env block is for steps and job-level environment settings.
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist --no-plugins"
COMPOSER_UPDATE_FLAGS: ""
# Default versions - can be easily updated when new PHP versions are released
DEFAULT_OLD_STABLE: '["8.1", "8.2", "8.3"]'
DEFAULT_CURRENT_STABLE: '8.4'
jobs:
phpunit:
name: PHPUnit
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# For workflow_call:
# - If inputs.old_stable is provided by the caller, that value is used.
# - If inputs.old_stable is NOT provided by the caller, its `default: '[]'` in the `inputs` definition is used.
# For push/pull_request/workflow_dispatch (where inputs.old_stable is an empty string "" if not set via dispatch UI):
# - The `|| env.DEFAULT_OLD_STABLE` provides the default JSON array because "" is falsy.
php-version: ${{ fromJson(inputs.old_stable || env.DEFAULT_OLD_STABLE) }}

Check failure on line 47 in .github/workflows/continuous-integration.yml

View workflow run for this annotation

GitHub Actions / Continuous Integration

Invalid workflow file

The workflow is not valid. .github/workflows/continuous-integration.yml (Line: 47, Col: 22): Unrecognized named-value: 'env'. Located at position 31 within expression: fromJson(inputs.old_stable || env.DEFAULT_OLD_STABLE) .github/workflows/continuous-integration.yml (Line: 47, Col: 22): Unexpected value '${{ fromJson(inputs.old_stable || env.DEFAULT_OLD_STABLE) }}'
dependencies: [highest, lowest]
os: [ubuntu-latest]
experimental: [false]
include:
# For workflow_call: inputs.current_stable is required and its value is used.
# For push/pull_request/workflow_dispatch (where inputs.current_stable is an empty string "" if not set via dispatch UI):
# - The `|| env.DEFAULT_CURRENT_STABLE` provides the default current stable version because "" is falsy.
- php-version: ${{ inputs.current_stable || env.DEFAULT_CURRENT_STABLE }}
os: windows-latest
dependencies: highest
experimental: false
- php-version: ${{ inputs.current_stable || env.DEFAULT_CURRENT_STABLE }}
os: ubuntu-latest
dependencies: highest
experimental: false
# Note: Current stable PHP version with lowest dependencies is intentionally excluded
# to avoid aura/sql v5 compatibility issues with the latest PHP version
exclude:
# Skip lowest dependencies test for current stable PHP version
# This prevents aura/sql ^5 from being installed on the latest PHP version where it may not be fully compatible
- php-version: ${{ inputs.current_stable || env.DEFAULT_CURRENT_STABLE }}
dependencies: lowest
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Disable autocrlf on Windows
if: ${{ contains(matrix.os, 'windows') }}
run: git config --global core.autocrlf false
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
ini-values: |
zend.assertions=1
memory_limit=512M
opcache.jit=0
opcache.jit_buffer_size=0
opcache.enable=0
opcache.enable_cli=0
extensions: pdo,pdo_mysql,pdo_sqlite
- name: Get composer cache directory
id: composer-cache
shell: bash
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json', '**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
${{ runner.os }}-php${{ matrix.php-version }}-composer-
${{ runner.os }}-composer-
- name: Set platform requirements
shell: bash
run: |
composer config platform.php ${{ matrix.php-version }}
- name: Handle lowest dependencies update
if: ${{ matrix.dependencies == 'lowest' }}
shell: bash
run: echo COMPOSER_UPDATE_FLAGS="$COMPOSER_UPDATE_FLAGS --prefer-lowest" >> $GITHUB_ENV
- name: Remove platform config for dependency resolution
if: ${{ matrix.dependencies == 'highest' }}
shell: bash
run: composer config platform --unset
- name: Update dependencies
shell: bash
run: |
composer validate --no-check-all --strict
composer update ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}
- name: Run test suite
shell: bash
run: vendor/bin/phpunit --coverage-clover=coverage.xml
env:
XDEBUG_MODE: coverage # pcov uses XDEBUG_MODE=coverage for activation
- name: Upload coverage report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
- name: Run additional script
# Run if inputs.script is not an empty string and also not null (which it can be if not provided in workflow_call)
if: ${{ inputs.script != '' && inputs.script != null }}
shell: bash
run: php ${{ inputs.script }}