@@ -3,68 +3,97 @@ name: 'CI reusable workflow'
3
3
on :
4
4
workflow_call :
5
5
6
+ permissions :
7
+ contents : read
8
+
6
9
env :
10
+ COMPOSER_PREFER_STABLE : ' 1'
7
11
TEST_OUTPUT_STYLE : pretty
8
- COMPOSER_OPTIONS : --optimize-autoloader
9
12
10
13
jobs :
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
+
11
37
tests :
12
- name : PHP ${{ matrix.php-version }}
38
+ name : ${{ matrix.job-name }}
39
+ needs : [fetch-supported-versions]
13
40
runs-on : ubuntu-latest
41
+ permissions :
42
+ contents : read
14
43
env :
15
44
COVERAGE_TYPE : none
45
+ COVERAGE_OUTPUT_STYLE : clover
16
46
strategy :
17
47
fail-fast : true
18
- max-parallel : 4
19
48
matrix :
20
49
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 }}'
26
54
steps :
27
55
- name : Check out code
28
56
uses : actions/checkout@v4
29
57
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
30
60
- name : Enable coverage
31
- if : ${{ matrix.php-version == '8.2' }}
61
+ if : ${{ matrix.php-version == needs.fetch-supported-versions.outputs.php-max }}
32
62
run : |
33
- echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV
34
63
echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV
35
64
36
65
- name : Setup PHP ${{ matrix.php-version }}
66
+ id : setup-php
37
67
uses : shivammathur/setup-php@v2
38
68
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
40
70
fail-fast : true # step will fail if an extension or tool fails to set up
41
71
with :
42
- php-version : ' ${{ matrix.php-version }}'
72
+ php-version : ${{ matrix.php-version }}
43
73
tools : composer
44
74
coverage : ${{ env.COVERAGE_TYPE }}
45
75
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 }}
48
81
uses : actions/cache@v4
49
82
with :
50
83
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') }}
55
87
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
60
90
61
91
- name : Tests
62
92
run : make test-unit && make test-functional
63
93
64
94
- name : Create "unit tests" reports group
65
95
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
68
97
with :
69
98
name : unit-tests
70
99
format : clover
@@ -74,10 +103,9 @@ jobs:
74
103
php-${{ matrix.php-version }}
75
104
path : build/coverage-groups
76
105
77
- - name : Create "functional tests" coverage group
106
+ - name : Create "functional tests" reports group
78
107
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
81
109
with :
82
110
name : functional-tests
83
111
format : clover
@@ -93,36 +121,45 @@ jobs:
93
121
if : ${{ env.COVERAGE_TYPE == 'xdebug' }}
94
122
uses : actions/upload-artifact@v4
95
123
with :
96
- name : coverage-groups-php${{ matrix .php-version }}
124
+ name : coverage-groups-php${{ steps.setup-php.outputs .php-version }}
97
125
path : build/coverage-groups
98
126
if-no-files-found : error
99
127
100
128
static-checks :
101
129
name : Static analysis
130
+ needs : [fetch-supported-versions]
102
131
runs-on : ubuntu-latest
132
+ permissions :
133
+ contents : read
134
+ env :
135
+ PHP_VERSION : ${{ needs.fetch-supported-versions.outputs.php-max }}
103
136
steps :
104
137
- uses : actions/checkout@v4
105
138
106
- - name : Setup PHP 8.2
139
+ - name : Setup PHP ${{ env.PHP_VERSION }}
140
+ id : setup-php
107
141
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
108
145
with :
109
- php-version : 8.2 # Latest supported
146
+ php-version : ${{ env.PHP_VERSION }}
110
147
tools : composer
111
148
coverage : none
112
- env :
113
- # Always use latest available patch for the version
114
- update : true
115
149
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 }}
118
155
uses : actions/cache@v4
119
156
with :
120
157
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') }}
124
161
125
- - name : Build
162
+ - name : Build with PHP ${{ steps.setup-php.outputs.php-version }}
126
163
run : make build
127
164
128
165
- name : ComposerRequireChecker
@@ -133,47 +170,45 @@ jobs:
133
170
uses : actions/dependency-review-action@v4
134
171
135
172
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') ) }}
137
176
runs-on : ubuntu-latest
138
- env :
139
- COMPOSER_OPTIONS : ' --optimize-autoloader --ignore-platform-req=php+ '
177
+ permissions :
178
+ contents : read
140
179
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+'
149
183
steps :
150
184
- name : Check out code
151
185
uses : actions/checkout@v4
152
186
153
- - name : Setup PHP ${{ matrix.php-version }}
187
+ - name : Setup PHP ${{ env.PHP_VERSION }}
188
+ id : setup-php
154
189
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
155
193
with :
156
- php-version : ' ${{ matrix.php-version }}'
194
+ php-version : ${{ env.PHP_VERSION }}
157
195
tools : composer
158
196
coverage : none
159
- env :
160
- # Always use latest available patch for the version
161
- update : true
162
197
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 }}
165
203
uses : actions/cache@v4
166
204
with :
167
205
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') }}
172
209
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
177
212
178
213
- name : Test
179
214
run : make test-unit && make test-functional
0 commit comments