Update .github/workflows/continuous-integration.yml #924
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
workflow_call: # Enable calling from other workflows | |
inputs: | |
old_stable: | |
required: false | |
type: string | |
default: "[]" # Example: '["8.1", "8.2", "8.3"]' | |
current_stable: | |
required: true | |
type: string # Example: "8.4" | |
script: | |
required: false | |
type: string | |
env: | |
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist --no-plugins" | |
COMPOSER_UPDATE_FLAGS: "" | |
jobs: | |
phpunit: | |
name: PHPUnit | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
php-version: ${{ fromJson(inputs.old_stable) }} | |
dependencies: [highest, lowest] | |
os: [ubuntu-latest] | |
experimental: [false] | |
include: | |
- php-version: ${{ inputs.current_stable }} # Should be 8.4 for the special handling | |
os: windows-latest | |
dependencies: highest | |
experimental: false | |
- php-version: ${{ inputs.current_stable }} # Should be 8.4 for the special handling | |
os: ubuntu-latest | |
dependencies: highest | |
experimental: false | |
- php-version: ${{ inputs.current_stable }} # Should be 8.4 for the special handling | |
os: ubuntu-latest | |
dependencies: lowest # This is the target for aura/sql modification | |
experimental: false | |
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 # Not strictly necessary for this change but good practice | |
- 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 | |
# --- Start of aura/sql specific modification --- | |
- name: Temporarily modify composer.json for PHP 8.4 lowest dependencies | |
id: prepare_php84_lowest_aura_sql | |
# This step runs only for PHP 8.4 with lowest dependencies. | |
# Assumes inputs.current_stable will be '8.4' when testing PHP 8.4 | |
if: ${{ matrix['php-version'] == inputs.current_stable && inputs.current_stable == '8.4' && matrix.dependencies == 'lowest' }} | |
shell: bash | |
run: | | |
echo "PHP version is ${{ matrix.php-version }} and dependencies are 'lowest'. Modifying composer.json for aura/sql ^6.0." | |
if [ ! -f composer.json ]; then | |
echo "Error: composer.json not found!" | |
exit 1 | |
fi | |
cp composer.json composer.json.bak-aura-sql-patch | |
# Use PHP to modify composer.json, ensuring JSON validity and handling potential errors. | |
php -r '$composerJsonPath = "composer.json"; $config = json_decode(file_get_contents($composerJsonPath), true); if (json_last_error() !== JSON_ERROR_NONE) { fwrite(STDERR, "Error decoding composer.json: " . json_last_error_msg() . "\n"); exit(1); } if (isset($config["require"]["aura/sql"])) { $config["require"]["aura/sql"] = "^6.0"; $jsonOutput = json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); if (json_last_error() !== JSON_ERROR_NONE) { fwrite(STDERR, "Error encoding composer.json: " . json_last_error_msg() . "\n"); exit(1); } file_put_contents($composerJsonPath, $jsonOutput); echo "composer.json modified: aura/sql constraint changed to ^6.0.\n"; echo "modified=true" >> $GITHUB_OUTPUT; } else { echo "Warning: aura/sql not found in require section of composer.json. No modification made.\n"; echo "modified=false" >> $GITHUB_OUTPUT; }' | |
# Check if PHP script itself failed (e.g., syntax error, or explicit exit(1)) | |
if [ $? -ne 0 ]; then | |
echo "Error: PHP script to modify composer.json failed." | |
# Restore immediately if PHP script indicated failure, to ensure clean state for next steps or retry | |
if [ -f composer.json.bak-aura-sql-patch ]; then | |
mv composer.json.bak-aura-sql-patch composer.json | |
echo "Restored composer.json from backup due to script failure." | |
fi | |
exit 1 # Fail the step | |
fi | |
# --- End of aura/sql specific modification --- | |
- 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 | |
# --- Start of composer.json reversion --- | |
- name: Revert composer.json modification | |
# This step always runs to ensure composer.json is restored if it was modified. | |
# It checks if the modification step was successful and if it actually set the 'modified' output to true. | |
if: always() && steps.prepare_php84_lowest_aura_sql.outcome == 'success' && steps.prepare_php84_lowest_aura_sql.outputs.modified == 'true' | |
shell: bash | |
run: | | |
echo "Attempting to revert composer.json modification." | |
if [ -f composer.json.bak-aura-sql-patch ]; then | |
mv composer.json.bak-aura-sql-patch composer.json | |
echo "composer.json has been successfully reverted." | |
else | |
echo "Warning: Backup file composer.json.bak-aura-sql-patch not found. No reversion performed or backup was not created." | |
fi | |
# --- End of composer.json reversion --- | |
- name: Upload coverage report | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
fail_ci_if_error: false | |
- name: Run additional script | |
if: ${{ inputs.script != '' }} | |
shell: bash | |
run: php ${{ inputs.script }} |