Skip to content

Commit

Permalink
Refactor CI workflow for improved clarity and flexibility
Browse files Browse the repository at this point in the history
Simplified dependency resolution, updated caching, and revamped matrix strategy to support more OS combinations. Enhanced readability with consistent naming and conditional logic improvements. Updated actions versions and streamlined demo script execution.
  • Loading branch information
koriym committed Jan 21, 2025
1 parent b942f72 commit 9b7dcd3
Showing 1 changed file with 45 additions and 69 deletions.
114 changes: 45 additions & 69 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,81 @@ name: Continuous Integration
on:
push:
paths-ignore:
- '**.md'
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'
workflow_dispatch:

env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist --no-plugins"
COMPOSER_UPDATE_FLAGS: ""
script: demo/run.php
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
SCRIPT: "demo/run.php"

jobs:
phpunit:
name: PHPUnit
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
name: PHPUnit (${{ matrix.os }} - PHP ${{ matrix.php-version }} - ${{ matrix.dependencies }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php-version: [8.2, 8.3, 8.4]
dependencies: [highest, lowest]
os: [ubuntu-latest]
include:
- php-version: 8.1
os: windows-latest
os: [ubuntu-latest, windows-latest, macos-latest]
php-version: [8.1, 8.2, 8.3, 8.4]
dependencies: [lowest, highest]
exclude:
- php-version: 8.1
os: macos-latest
- php-version: 8.2
dependencies: lowest
os: ubuntu-latest
- php-version: 8.2
dependencies: highest
os: ubuntu-latest
- php-version: 8.3
dependencies: highest
os: ubuntu-latest
- php-version: 8.3
dependencies: lowest
os: ubuntu-latest
- php-version: 8.4
dependencies: highest
os: ubuntu-latest
- php-version: 8.4
- php-version: 8.1
dependencies: lowest
os: ubuntu-latest

services:
redis:
image: redis
ports: [6379:6379]
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 3
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check out repository
uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
ini-values: zend.assertions=1

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
tools: composer

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Handle lowest dependencies update
if: contains(matrix.dependencies, 'lowest')
run: echo COMPOSER_UPDATE_FLAGS=$COMPOSER_UPDATE_FLAGS --prefer-lowest >> $GITHUB_ENV

- name: Handle ignore-platform-reqs dependencies update
if: contains(matrix.dependencies, 'ignore')
run: echo COMPOSER_FLAGS=$COMPOSER_FLAGS --ignore-platform-req=php >> $GITHUB_ENV
path: ~/.composer/cache
key: ${{ runner.os }}-php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php-version }}-composer-
- name: Remove platform config to get latest dependencies for current PHP version
if: contains(matrix.dependencies, 'highest') || contains(matrix.dependencies, 'lowest')
run: composer config platform --unset

- name: Allow alpha releases for latest-deps builds to catch problems earlier
if: contains(matrix.dependencies, 'ignore')
run: composer config minimum-stability alpha
- name: Configure dependency resolution
run: |
composer config platform --unset
- name: Update dependencies
run: composer update ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}
run: composer update ${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }} ${{ env.COMPOSER_FLAGS }}

- name: Run test suite
- name: Run PHPUnit tests
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml

- name: Update dependencies for demo
run: composer require doctrine/cache ^1 ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}
files: coverage.xml
fail_ci_if_error: true

- name: Run additional script
if: ${{ env.script }}
run: php ${{ env.script }}
- name: Prepare and run demo
if: ${{ env.SCRIPT != '' && matrix.os == 'ubuntu-latest' }}
run: |
composer require doctrine/cache:"^1.12" --no-update
composer update ${{ env.COMPOSER_FLAGS }}
php ${{ env.SCRIPT }}

0 comments on commit 9b7dcd3

Please sign in to comment.