Skip to content

Commit bec3f0a

Browse files
committed
Optimize CI workflow for flexibility and efficiency
Refactored the CI workflow to improve maintainability and support multiple OS and PHP versions. Adjusted matrix configurations, streamlined dependency management, and introduced environment-based conditions. Updated step names and enhanced Composer caching for better performance.
1 parent b942f72 commit bec3f0a

1 file changed

Lines changed: 56 additions & 70 deletions

File tree

.github/workflows/continuous-integration.yml

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,103 +5,89 @@ on:
55
paths-ignore:
66
- '**.md'
77
pull_request:
8+
paths-ignore:
9+
- '**.md'
810
workflow_dispatch:
911

1012
env:
11-
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist --no-plugins"
12-
COMPOSER_UPDATE_FLAGS: ""
13-
script: demo/run.php
13+
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
14+
SCRIPT_PATH: "demo/run.php"
1415

1516
jobs:
1617
phpunit:
17-
name: PHPUnit
18-
runs-on: ubuntu-latest
19-
services:
20-
redis:
21-
image: redis
22-
ports:
23-
- 6379:6379
24-
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
18+
name: PHPUnit (${{ matrix.os }} - PHP ${{ matrix.php }} - ${{ matrix.dependencies }})
19+
runs-on: ${{ matrix.os }}
2520
strategy:
2621
matrix:
27-
php-version: [8.2, 8.3, 8.4]
22+
php: [8.1, 8.2, 8.3, 8.4]
2823
dependencies: [highest, lowest]
29-
os: [ubuntu-latest]
30-
include:
31-
- php-version: 8.1
32-
os: windows-latest
33-
- php-version: 8.1
34-
os: macos-latest
35-
- php-version: 8.2
36-
dependencies: lowest
37-
os: ubuntu-latest
38-
- php-version: 8.2
39-
dependencies: highest
24+
os: [ubuntu-latest, windows-latest, macos-latest]
25+
exclude:
26+
- php: 8.1
4027
os: ubuntu-latest
41-
- php-version: 8.3
42-
dependencies: highest
43-
os: ubuntu-latest
44-
- php-version: 8.3
28+
- php: 8.1
4529
dependencies: lowest
46-
os: ubuntu-latest
47-
- php-version: 8.4
48-
dependencies: highest
49-
os: ubuntu-latest
50-
- php-version: 8.4
30+
os: windows-latest
31+
- php: 8.1
5132
dependencies: lowest
33+
os: macos-latest
34+
include:
35+
- php: 8.4
5236
os: ubuntu-latest
37+
experimental: true
38+
39+
services:
40+
redis:
41+
image: redis
42+
ports: [6379:6379]
43+
options: >-
44+
--health-cmd "redis-cli ping"
45+
--health-interval 10s
46+
--health-timeout 5s
47+
--health-retries 3
48+
5349
steps:
54-
- name: Checkout
55-
uses: actions/checkout@v3
50+
- name: Checkout code
51+
uses: actions/checkout@v4
5652

57-
- name: Setup PHP ${{ matrix.php-version }}
53+
- name: Setup PHP
5854
uses: shivammathur/setup-php@v2
5955
with:
60-
php-version: ${{ matrix.php-version }}
56+
php-version: ${{ matrix.php }}
6157
coverage: pcov
6258
ini-values: zend.assertions=1
59+
tools: composer
60+
experimental: ${{ contains(matrix.experimental, 'true') }}
6361

64-
- name: Get composer cache directory
65-
id: composer-cache
66-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
67-
68-
- name: Cache dependencies
69-
uses: actions/cache@v2
62+
- name: Cache Composer dependencies
63+
uses: actions/cache@v4
7064
with:
71-
path: ${{ steps.composer-cache.outputs.dir }}
72-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
73-
restore-keys: ${{ runner.os }}-composer-
74-
75-
- name: Handle lowest dependencies update
76-
if: contains(matrix.dependencies, 'lowest')
77-
run: echo COMPOSER_UPDATE_FLAGS=$COMPOSER_UPDATE_FLAGS --prefer-lowest >> $GITHUB_ENV
65+
path: ~/.composer/cache
66+
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
67+
restore-keys: |
68+
${{ runner.os }}-php-${{ matrix.php }}-composer-
7869
79-
- name: Handle ignore-platform-reqs dependencies update
80-
if: contains(matrix.dependencies, 'ignore')
81-
run: echo COMPOSER_FLAGS=$COMPOSER_FLAGS --ignore-platform-req=php >> $GITHUB_ENV
70+
- name: Configure dependency strategy
71+
run: |
72+
if [ "${{ matrix.dependencies }}" = "lowest" ]; then
73+
composer config prefer-stable true
74+
composer config prefer-lowest true
75+
fi
8276
83-
- name: Remove platform config to get latest dependencies for current PHP version
84-
if: contains(matrix.dependencies, 'highest') || contains(matrix.dependencies, 'lowest')
85-
run: composer config platform --unset
86-
87-
- name: Allow alpha releases for latest-deps builds to catch problems earlier
88-
if: contains(matrix.dependencies, 'ignore')
89-
run: composer config minimum-stability alpha
90-
91-
- name: Update dependencies
92-
run: composer update ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}
77+
- name: Install dependencies
78+
run: composer update ${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }} ${{ env.COMPOSER_FLAGS }}
9379

9480
- name: Run test suite
9581
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml
9682

97-
- name: Upload coverage report
83+
- name: Upload coverage to Codecov
9884
uses: codecov/codecov-action@v3
9985
with:
100-
file: ./coverage.xml
101-
102-
- name: Update dependencies for demo
103-
run: composer require doctrine/cache ^1 ${{ env.COMPOSER_UPDATE_FLAGS }} ${{ env.COMPOSER_FLAGS }}
86+
files: coverage.xml
87+
fail_ci_if_error: true
10488

105-
- name: Run additional script
106-
if: ${{ env.script }}
107-
run: php ${{ env.script }}
89+
- name: Prepare demo environment
90+
if: matrix.os == 'ubuntu-latest' && env.SCRIPT_PATH
91+
run: |
92+
composer require doctrine/cache ^1
93+
php ${{ env.SCRIPT_PATH }}

0 commit comments

Comments
 (0)