Skip to content

Commit fb87cfa

Browse files
authored
Improve CI (#47)
1 parent 4e0d5e6 commit fb87cfa

File tree

7 files changed

+130
-76
lines changed

7 files changed

+130
-76
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ on: # Build any PRs and main branch changes
1010
# In case of updates to those workflows, they must be pre-checked by `pre-check-CI-updates.yml` rather than this workflow !
1111
# Any updates on those workflows are expected to be restricted to those workflows only ! (no update on code for instance)
1212
- '.github/workflows/pre-check-CI-updates.yml'
13-
- '.github/workflows/CI.yml'
14-
- '.github/workflows/coverage-upload.yml'
1513
- '.github/workflows/reusable-CI-workflow.yml'
1614
- '.github/workflows/reusable-coverage-upload-workflow.yml'
1715
push:
1816
branches: [ master ]
1917
schedule:
2018
- cron: '0 0 1 * *' # Every month
2119

20+
permissions:
21+
contents: read
22+
2223
concurrency:
2324
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
2425
cancel-in-progress: true
2526

27+
env:
28+
TEST_OUTPUT_STYLE: pretty
29+
2630
jobs:
2731
tests:
2832
name: Tests

.github/workflows/coverage-upload.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ on:
44
workflows: ["CI"]
55
types: [completed]
66

7+
permissions:
8+
contents: read
9+
checks: write # For the check run creation !
10+
711
jobs:
812
upload:
9-
name: Upload
13+
name: Coverage
1014
permissions:
1115
contents: read
1216
checks: write # For the check run creation !

.github/workflows/pre-check-CI-updates.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ on:
1212
branches: [master] # Only for PR targeting master branch
1313
paths: # /!\ Duplicate the same list as `on.pull_request.paths-ignore` property value for CI workflow !
1414
- '.github/workflows/pre-check-CI-updates.yml' # This workflow
15-
- '.github/workflows/CI.yml'
16-
- '.github/workflows/coverage-upload.yml'
1715
- '.github/workflows/reusable-CI-workflow.yml'
1816
- '.github/workflows/reusable-coverage-upload-workflow.yml'
1917

18+
permissions:
19+
contents: read
20+
checks: write # For the check run creation !
21+
2022
concurrency:
2123
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
2224
cancel-in-progress: true
@@ -29,7 +31,7 @@ jobs:
2931
uses: ./.github/workflows/reusable-CI-workflow.yml
3032

3133
upload:
32-
name: Upload
34+
name: Coverage
3335
needs: [tests]
3436
permissions:
3537
contents: read

.github/workflows/reusable-CI-workflow.yml

Lines changed: 100 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,97 @@ name: 'CI reusable workflow'
33
on:
44
workflow_call:
55

6+
permissions:
7+
contents: read
8+
69
env:
10+
COMPOSER_PREFER_STABLE: '1'
711
TEST_OUTPUT_STYLE: pretty
8-
COMPOSER_OPTIONS: --optimize-autoloader
912

1013
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+
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

.github/workflows/reusable-coverage-upload-workflow.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
CODECOV_TOKEN:
99
required: true
1010

11+
permissions:
12+
contents: read
13+
checks: write # For the check run creation !
14+
1115
jobs:
1216
fetch-info:
1317
name: Fetch triggering workflow metadata
@@ -17,17 +21,19 @@ jobs:
1721
checks: write # For the check run creation !
1822
steps:
1923
- name: 'Check run ○'
20-
uses: yoanm/temp-reports-group-workspace/gha-attach-check-run-to-triggering-workflow@v0
24+
uses: yoanm/temp-reports-group-workspace/utils/attach-check-run-to-triggering-workflow@v0
2125
with:
22-
name: 'Fetch coverage info'
26+
name: 'Fetch triggering workflow metadata'
2327
fails-on-triggering-workflow-failure: true
2428

25-
- uses: yoanm/temp-reports-group-workspace/gha-fetch-workflow-metadata@v0
29+
- uses: yoanm/temp-reports-group-workspace/utils/fetch-workflow-metadata@v0
2630
id: fetch-workflow-metadata
2731

2832
outputs:
2933
commit-sha: ${{ steps.fetch-workflow-metadata.outputs.commit-sha }}
3034
run-id: ${{ steps.fetch-workflow-metadata.outputs.run-id }}
35+
branch: ${{ steps.fetch-workflow-metadata.outputs.branch }}
36+
pull-request: ${{ steps.fetch-workflow-metadata.outputs.pull-request }}
3137

3238
codacy-uploader:
3339
name: Codacy
@@ -60,6 +66,6 @@ jobs:
6066
run-id: ${{ needs.fetch-info.outputs.run-id }}
6167
force-git-commit: ${{ needs.fetch-info.outputs.commit-sha }}
6268
force-git-branch: ${{ needs.fetch-info.outputs.branch }}
63-
force-gh-pr: ${{ needs.fetch-info.outputs.pr-number }}
69+
force-gh-pr: ${{ needs.fetch-info.outputs.pull-request }}
6470
force-uploader-build: ${{ needs.fetch-info.outputs.run-id }}
6571
force-uploader-build-url: ${{ needs.fetch-info.outputs.run-url }}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"php": {"min": "8.0", "max": "8.2", "next": "8.3"}
3+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"require-dev": {
3939
"ext-json": "*",
40-
"behat/behat": "^3.9.0",
40+
"behat/behat": "^3.9.0,<=3.16.1",
4141
"dvdoug/behat-code-coverage": "^5.0",
4242
"phpspec/prophecy": "^1.15",
4343
"phpspec/prophecy-phpunit": "^2.0",

0 commit comments

Comments
 (0)