@@ -3,68 +3,97 @@ name: 'CI reusable workflow'
33on :
44 workflow_call :
55
6+ permissions :
7+ contents : read
8+
69env :
10+ COMPOSER_PREFER_STABLE : ' 1'
711 TEST_OUTPUT_STYLE : pretty
8- COMPOSER_OPTIONS : --optimize-autoloader
912
1013jobs :
14+ fetch-supported-versions :
15+ name : Fetch supported versions
16+ runs-on : ubuntu-latest
17+ permissions :
18+ contents : read
19+ outputs :
20+ php-min : ${{ steps.fetch-php-versions.outputs.min }}
21+ php-max : ${{ steps.fetch-php-versions.outputs.max }}
22+ php-next : ${{ steps.fetch-php-versions.outputs.next }}
23+ steps :
24+ - name : Fetch supported versions file
25+ id : fetch-file
26+ uses : yoanm/gha-supported-versions-parser/github-downloader@v1
27+ with :
28+ file-path : .github/workflows/supported-versions.json
29+
30+ - name : Fetch PHP supported versions
31+ id : fetch-php-versions
32+ uses : yoanm/gha-supported-versions-parser@v1
33+ with :
34+ path : ${{ steps.fetch-file.outputs.path }}
35+ dependency : php
36+
1137 tests :
12- name : PHP ${{ matrix.php-version }}
38+ name : ${{ matrix.job-name }}
39+ needs : [fetch-supported-versions]
1340 runs-on : ubuntu-latest
41+ permissions :
42+ contents : read
1443 env :
1544 COVERAGE_TYPE : none
45+ COVERAGE_OUTPUT_STYLE : clover
1646 strategy :
1747 fail-fast : true
18- max-parallel : 4
1948 matrix :
2049 include :
21- # Bare minimum => Lowest versions allowed by composer config
22- - php-version : ' 8.0'
23- composer-flag : --prefer-lowest
24- # Up to date versions => Latest versions allowed by composer config
25- - php-version : ' 8.2'
50+ - job-name : Up to date versions # => Highest versions allowed by composer config
51+ php-version : ' ${{ needs.fetch-supported-versions.outputs.php-max }}'
52+ - job-name : Bare minimum # => Lowest versions allowed by composer config
53+ php-version : ' ${{ needs.fetch-supported-versions.outputs.php-min }}'
2654 steps :
2755 - name : Check out code
2856 uses : actions/checkout@v4
2957
58+ # Enable coverage only for specific version(s) !
59+ # Usually highest version(s), plus additional ones in case of code used only with specific versions
3060 - name : Enable coverage
31- if : ${{ matrix.php-version == '8.2' }}
61+ if : ${{ matrix.php-version == needs.fetch-supported-versions.outputs.php-max }}
3262 run : |
33- echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV
3463 echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV
3564
3665 - name : Setup PHP ${{ matrix.php-version }}
66+ id : setup-php
3767 uses : shivammathur/setup-php@v2
3868 env :
39- update : true # Always use latest available patch for the version
69+ update : true # whether to use latest available patch for the version or not
4070 fail-fast : true # step will fail if an extension or tool fails to set up
4171 with :
42- php-version : ' ${{ matrix.php-version }}'
72+ php-version : ${{ matrix.php-version }}
4373 tools : composer
4474 coverage : ${{ env.COVERAGE_TYPE }}
4575
46- - name : Setup cache
47- id : cache
76+ - name : Get composer cache directory
77+ id : composer-cache
78+ run : echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
79+
80+ - name : Setup cache for PHP ${{ steps.setup-php.outputs.php-version }}
4881 uses : actions/cache@v4
4982 with :
5083 path : |
51- ~/.composer
52- ./vendor
53- # Clear the cache if composer json (as composer.lock is in the repo) has been updated
54- key : tests-${{ matrix.php-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }}
84+ ${{ steps.composer-cache.outputs.dir }}
85+ # Clear the cache if composer.json (as composer.lock is not available) has been updated
86+ key : tests-php${{ steps.setup-php.outputs.php-version }}-${{ hashFiles('composer.json') }}
5587
56- - name : Build
57- run : |
58- composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \
59- && make build
88+ - name : Build with PHP ${{ steps.setup-php.outputs.php-version }}
89+ run : make build
6090
6191 - name : Tests
6292 run : make test-unit && make test-functional
6393
6494 - name : Create "unit tests" reports group
6595 if : ${{ env.COVERAGE_TYPE == 'xdebug' }}
66- id : unit-tests-coverage-group
67- uses : yoanm/temp-reports-group-workspace/gha-create@v0
96+ uses : yoanm/temp-reports-group-workspace/create-group@v0
6897 with :
6998 name : unit-tests
7099 format : clover
@@ -74,10 +103,9 @@ jobs:
74103 php-${{ matrix.php-version }}
75104 path : build/coverage-groups
76105
77- - name : Create "functional tests" coverage group
106+ - name : Create "functional tests" reports group
78107 if : ${{ env.COVERAGE_TYPE == 'xdebug' }}
79- id : functional-tests-coverage-group
80- uses : yoanm/temp-reports-group-workspace/gha-create@v0
108+ uses : yoanm/temp-reports-group-workspace/create-group@v0
81109 with :
82110 name : functional-tests
83111 format : clover
@@ -93,36 +121,45 @@ jobs:
93121 if : ${{ env.COVERAGE_TYPE == 'xdebug' }}
94122 uses : actions/upload-artifact@v4
95123 with :
96- name : coverage-groups-php${{ matrix .php-version }}
124+ name : coverage-groups-php${{ steps.setup-php.outputs .php-version }}
97125 path : build/coverage-groups
98126 if-no-files-found : error
99127
100128 static-checks :
101129 name : Static analysis
130+ needs : [fetch-supported-versions]
102131 runs-on : ubuntu-latest
132+ permissions :
133+ contents : read
134+ env :
135+ PHP_VERSION : ${{ needs.fetch-supported-versions.outputs.php-max }}
103136 steps :
104137 - uses : actions/checkout@v4
105138
106- - name : Setup PHP 8.2
139+ - name : Setup PHP ${{ env.PHP_VERSION }}
140+ id : setup-php
107141 uses : shivammathur/setup-php@v2
142+ env :
143+ update : true # Always use latest available patch for the version
144+ fail-fast : true # step will fail if an extension or tool fails to set up
108145 with :
109- php-version : 8.2 # Latest supported
146+ php-version : ${{ env.PHP_VERSION }}
110147 tools : composer
111148 coverage : none
112- env :
113- # Always use latest available patch for the version
114- update : true
115149
116- - name : Setup cache
117- id : cache
150+ - name : Get composer cache directory
151+ id : composer-cache
152+ run : echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
153+
154+ - name : Setup cache for PHP ${{ steps.setup-php.outputs.php-version }}
118155 uses : actions/cache@v4
119156 with :
120157 path : |
121- ~/ .composer
122- # Clear the cache if composer json (as composer.lock is in the repo ) has been updated
123- key : tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}
158+ ${{ steps .composer-cache.outputs.dir }}
159+ # Clear the cache if composer. json (as composer.lock is not available ) has been updated
160+ key : tests-php ${{ steps.setup-php.outputs.php-version }}-${{ hashFiles('composer.json') }}
124161
125- - name : Build
162+ - name : Build with PHP ${{ steps.setup-php.outputs.php-version }}
126163 run : make build
127164
128165 - name : ComposerRequireChecker
@@ -133,47 +170,45 @@ jobs:
133170 uses : actions/dependency-review-action@v4
134171
135172 nightly-tests :
136- name : Nightly - PHP ${{ matrix.php-version }}
173+ name : Nightly
174+ needs : [ fetch-supported-versions, tests ]
175+ if : ${{ github.event_name == 'push' || ( github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'with-nightly-tests') ) }}
137176 runs-on : ubuntu-latest
138- env :
139- COMPOSER_OPTIONS : ' --optimize-autoloader --ignore-platform-req=php+ '
177+ permissions :
178+ contents : read
140179 continue-on-error : true
141- needs : [ static-checks, tests ]
142- strategy :
143- fail-fast : false
144- max-parallel : 4
145- matrix :
146- php-version :
147- - ' 8.3' # Current php dev version
148-
180+ env :
181+ PHP_VERSION : ${{ needs.fetch-supported-versions.outputs.php-next }}
182+ COMPOSER_IGNORE_PLATFORM_REQ : ' php+'
149183 steps :
150184 - name : Check out code
151185 uses : actions/checkout@v4
152186
153- - name : Setup PHP ${{ matrix.php-version }}
187+ - name : Setup PHP ${{ env.PHP_VERSION }}
188+ id : setup-php
154189 uses : shivammathur/setup-php@v2
190+ env :
191+ update : true # whether to use latest available patch for the version or not
192+ fail-fast : true # step will fail if an extension or tool fails to set up
155193 with :
156- php-version : ' ${{ matrix.php-version }}'
194+ php-version : ${{ env.PHP_VERSION }}
157195 tools : composer
158196 coverage : none
159- env :
160- # Always use latest available patch for the version
161- update : true
162197
163- - name : Setup cache
164- id : cache
198+ - name : Get composer cache directory
199+ id : composer-cache
200+ run : echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
201+
202+ - name : Setup cache for PHP ${{ steps.setup-php.outputs.php-version }}
165203 uses : actions/cache@v4
166204 with :
167205 path : |
168- ~/.composer
169- ./vendor
170- # Clear the cache if composer json (as composer.lock is in the repo) has been updated
171- key : tests-${{ matrix.php-version }}-${{ hashFiles('composer.json') }}
206+ ${{ steps.composer-cache.outputs.dir }}
207+ # Clear the cache if composer.json (as composer.lock is not available) has been updated
208+ key : tests-php${{ steps.setup-php.outputs.php-version }}-${{ hashFiles('composer.json') }}
172209
173- - name : Build
174- run : |
175- composer update ${{ env.COMPOSER_OPTIONS }} \
176- && make build
210+ - name : Build with PHP ${{ steps.setup-php.outputs.php-version }}
211+ run : make build
177212
178213 - name : Test
179214 run : make test-unit && make test-functional
0 commit comments