Skip to content

Commit c40daac

Browse files
committed
Improce CI
1 parent 49190f9 commit c40daac

File tree

6 files changed

+131
-109
lines changed

6 files changed

+131
-109
lines changed

.github/workflows/CI.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: 'CI'
2+
23
on: # Build any PRs and main branch changes
34
workflow_dispatch: # Allows to run the workflow manually from the Actions tab
45
pull_request:
@@ -18,10 +19,16 @@ on: # Build any PRs and main branch changes
1819
schedule:
1920
- cron: '0 0 1 * *' # Every month
2021

22+
permissions:
23+
contents: read
24+
2125
concurrency:
2226
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
2327
cancel-in-progress: true
2428

29+
env:
30+
TEST_OUTPUT_STYLE: pretty
31+
2532
jobs:
2633
tests:
2734
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ on:
1717
- '.github/workflows/reusable-CI-workflow.yml'
1818
- '.github/workflows/reusable-coverage-upload-workflow.yml'
1919

20+
permissions:
21+
contents: read
22+
checks: write # For the check run creation !
23+
2024
concurrency:
2125
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
2226
cancel-in-progress: true
@@ -29,7 +33,7 @@ jobs:
2933
uses: ./.github/workflows/reusable-CI-workflow.yml
3034

3135
upload:
32-
name: Upload
36+
name: Coverage
3337
needs: [tests]
3438
permissions:
3539
contents: read

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

Lines changed: 101 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,109 @@ 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 }} & Symfony ${{ matrix.symfony-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-
- symfony-version: '4.4'
23-
php-version: '8.0'
24-
composer-flag: --prefer-lowest
25-
# Up to date versions => Latest versions allowed by composer config
26-
- symfony-version: '5.4'
27-
php-version: '8.2'
28-
# Late symfony migration => Lowest symfony version with latest minor php version allowed by composer config
29-
- symfony-version: '4.4'
30-
php-version: '8.2'
31-
composer-flag: --prefer-lowest
32-
# Late php migration => Latest symfony version with lowest minor php version allowed by composer config
33-
- symfony-version: '5.4'
34-
php-version: '8.0'
35-
# Symfony 6.0 latest
36-
- symfony-version: '6.0'
37-
php-version: '8.2'
38-
# Symfony 6.0 lowest
39-
- symfony-version: '6.0'
40-
php-version: '8.0'
41-
composer-flag: --prefer-lowest
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 }}'
4254
steps:
4355
- name: Check out code
4456
uses: actions/checkout@v4
4557

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
4660
- name: Enable coverage
47-
if: ${{ matrix.php-version == '8.2' }}
61+
if: ${{ matrix.php-version == needs.fetch-supported-versions.outputs.php-max }}
4862
run: |
49-
echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV
5063
echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV
5164
5265
- name: Setup PHP ${{ matrix.php-version }}
66+
id: setup-php
5367
uses: shivammathur/setup-php@v2
5468
env:
55-
update: true # Always use latest available patch for the version
69+
update: true # whether to use latest available patch for the version or not
5670
fail-fast: true # step will fail if an extension or tool fails to set up
5771
with:
58-
php-version: '${{ matrix.php-version }}'
72+
php-version: ${{ matrix.php-version }}
5973
tools: composer
6074
coverage: ${{ env.COVERAGE_TYPE }}
6175

62-
- name: Setup cache
63-
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 }}
6481
uses: actions/cache@v4
6582
with:
6683
path: |
67-
~/.composer
68-
./vendor
69-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
70-
key: tests-${{ matrix.php-version }}-${{ matrix.symfony-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') }}
7187

72-
- name: Build
73-
run: |
74-
SF_VERSION=${{ matrix.symfony-version }}
75-
# Issue with ParamterBag below 4.4.30 => https://github.com/symfony/symfony/commit/3eca446b21607ea1c7a865ece2dd8254c33679cc
76-
test '${{ matrix.symfony-version }}' = '4.4' && test '${{ matrix.php-version }}' = '8.2' && SF_VERSION=4.4.30
77-
composer require -W ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \
78-
symfony/validator:^$SF_VERSION \
79-
symfony/intl:^$SF_VERSION \
80-
symfony/expression-language:^$SF_VERSION \
81-
&& composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \
82-
&& make build
88+
- name: Build with PHP ${{ steps.setup-php.outputs.php-version }}
89+
run: make build
8390

8491
- name: Tests
8592
run: make test-unit && make test-functional
8693

8794
- name: Create "unit tests" reports group
8895
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
89-
id: unit-tests-coverage-group
90-
uses: yoanm/temp-reports-group-workspace/gha-create@v0
96+
uses: yoanm/temp-reports-group-workspace/create-group@v0
9197
with:
9298
name: unit-tests
9399
format: clover
94100
files: build/coverage-phpunit/unit.clover
95101
flags: |
96102
unit-tests
97103
php-${{ matrix.php-version }}
98-
sf-${{ matrix.symfony-version }}
99104
path: build/coverage-groups
100105

101-
- name: Create "functional tests" coverage group
106+
- name: Create "functional tests" reports group
102107
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
103-
id: functional-tests-coverage-group
104-
uses: yoanm/temp-reports-group-workspace/gha-create@v0
108+
uses: yoanm/temp-reports-group-workspace/create-group@v0
105109
with:
106110
name: functional-tests
107111
format: clover
@@ -111,43 +115,51 @@ jobs:
111115
flags: |
112116
functional-tests
113117
php-${{ matrix.php-version }}
114-
sf-${{ matrix.symfony-version }}
115118
path: build/coverage-groups
116119

117120
- name: Upload coverage reports
118121
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
119122
uses: actions/upload-artifact@v4
120123
with:
121-
name: coverage-groups-php${{ matrix.php-version }}-sf${{ matrix.symfony-version }}
124+
name: coverage-groups-php${{ steps.setup-php.outputs.php-version }}
122125
path: build/coverage-groups
123126
if-no-files-found: error
124127

125128
static-checks:
126129
name: Static analysis
130+
needs: [fetch-supported-versions]
127131
runs-on: ubuntu-latest
132+
permissions:
133+
contents: read
134+
env:
135+
PHP_VERSION: ${{ needs.fetch-supported-versions.outputs.php-max }}
128136
steps:
129137
- uses: actions/checkout@v4
130138

131-
- name: Setup PHP 8.2
139+
- name: Setup PHP ${{ env.PHP_VERSION }}
140+
id: setup-php
132141
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
133145
with:
134-
php-version: 8.2 # Latest supported
146+
php-version: ${{ env.PHP_VERSION }}
135147
tools: composer
136148
coverage: none
137-
env:
138-
# Always use latest available patch for the version
139-
update: true
140149

141-
- name: Setup cache
142-
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 }}
143155
uses: actions/cache@v4
144156
with:
145157
path: |
146-
~/.composer
147-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
148-
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') }}
149161

150-
- name: Build
162+
- name: Build with PHP ${{ steps.setup-php.outputs.php-version }}
151163
run: make build
152164

153165
- name: ComposerRequireChecker
@@ -158,59 +170,45 @@ jobs:
158170
uses: actions/dependency-review-action@v4
159171

160172
nightly-tests:
161-
name: Nightly - PHP ${{ matrix.php-version }} & Symfony ${{ matrix.symfony-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') ) }}
162176
runs-on: ubuntu-latest
163-
env:
164-
COMPOSER_OPTIONS: '--optimize-autoloader --ignore-platform-req=php+'
177+
permissions:
178+
contents: read
165179
continue-on-error: true
166-
needs: [ static-checks, tests ]
167-
strategy:
168-
fail-fast: false
169-
max-parallel: 4
170-
matrix:
171-
php-version:
172-
- '8.3' # Current php dev version
173-
symfony-version:
174-
- '4.4' # Lowest LTS
175-
- '5.4' # Latest LTS
176-
- '6.0' # Current major version
177-
include:
178-
- symfony-version: '6.3' # Next symfony minor version to manage with latest supported PHP version
179-
php-version: '8.2'
180-
180+
env:
181+
PHP_VERSION: ${{ needs.fetch-supported-versions.outputs.php-next }}
182+
COMPOSER_IGNORE_PLATFORM_REQ: 'php+'
181183
steps:
182184
- name: Check out code
183-
uses: actions/checkout@v4
185+
uses: actions/checkout@v5
184186

185-
- name: Setup PHP ${{ matrix.php-version }}
187+
- name: Setup PHP ${{ env.PHP_VERSION }}
188+
id: setup-php
186189
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
187193
with:
188-
php-version: '${{ matrix.php-version }}'
194+
php-version: ${{ env.PHP_VERSION }}
189195
tools: composer
190196
coverage: none
191-
env:
192-
# Always use latest available patch for the version
193-
update: true
194197

195-
- name: Setup cache
196-
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 }}
197203
uses: actions/cache@v4
198204
with:
199205
path: |
200-
~/.composer
201-
./vendor
202-
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
203-
key: tests-${{ matrix.php-version }}-${{ matrix.symfony-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') }}
204209

205-
- name: Build
206-
run: |
207-
composer config minimum-stability dev \
208-
&& composer require -W ${{ env.COMPOSER_OPTIONS }} \
209-
symfony/validator:^${{ matrix.symfony-version }} \
210-
symfony/intl:^${{ matrix.symfony-version }} \
211-
symfony/expression-language:^${{ matrix.symfony-version }} \
212-
&& composer update ${{ env.COMPOSER_OPTIONS }} \
213-
&& make build
210+
- name: Build with PHP ${{ steps.setup-php.outputs.php-version }}
211+
run: make build
214212

215213
- name: Test
216214
run: make test-unit && make test-functional

0 commit comments

Comments
 (0)