Skip to content

Commit 925b565

Browse files
committed
[CI] Rework tests-php job matrix, better covers different PHP/SF versions, test all components in a single job
1 parent 00fa069 commit 925b565

File tree

2 files changed

+65
-55
lines changed

2 files changed

+65
-55
lines changed

.github/workflows/test.yaml

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
- 'src/**/*.md'
1313
- 'ux.symfony.com/**'
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
18+
1519
jobs:
1620
coding-style-js:
1721
name: JavaScript Coding Style
@@ -50,75 +54,80 @@ jobs:
5054
echo "The Git workspace is clean. No changes detected."
5155
fi
5256
53-
tests-php-components:
54-
runs-on: ubuntu-latest
55-
outputs:
56-
components: ${{ steps.components.outputs.components }}
57-
steps:
58-
- uses: actions/checkout@v4
59-
60-
- id: components
61-
run: |
62-
components=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | jq -R -s -c 'split("\n")[:-1] | map(. | sub("^src/";"")) | sort')
63-
echo "$components"
64-
echo "components=$components" >> $GITHUB_OUTPUT
65-
6657
tests-php:
6758
runs-on: ubuntu-latest
68-
needs: tests-php-components
6959
strategy:
7060
fail-fast: false
7161
matrix:
72-
php-version: ['8.1', '8.3', '8.4']
73-
minimum-stability: ['stable', 'dev']
62+
php-version: ['8.1', '8.2', '8.3', '8.4']
63+
composer-flags: ['']
64+
symfony-version: ['']
65+
minimum-stability: ['stable']
7466
include:
75-
- php-version: '8.1'
76-
dependency-version: 'lowest'
77-
- php-version: '8.3'
78-
dependency-version: 'highest'
79-
- php-version: '8.4'
80-
dependency-version: 'highest'
81-
component: ${{ fromJson(needs.tests-php-components.outputs.components )}}
82-
exclude:
83-
- php-version: '8.1'
84-
minimum-stability: 'dev'
85-
- php-version: '8.3'
86-
minimum-stability: 'dev'
87-
- component: Swup # has no tests
88-
- component: Turbo # has its own workflow (test-turbo.yml)
89-
- component: Typed # has no tests
90-
67+
# dev packages (probably not needed to have multiple such jobs)
68+
- minimum-stability: 'dev'
69+
php-version: '8.4'
70+
# lowest deps
71+
- php-version: '8.1'
72+
composer-flags: '--prefer-lowest'
73+
# LTS version of Symfony
74+
- php-version: '8.1'
75+
symfony-version: '6.4.*'
76+
77+
env:
78+
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
9179
steps:
9280
- uses: actions/checkout@v4
9381

94-
- uses: shivammathur/setup-php@v2
82+
- name: Configure environment
83+
run: |
84+
echo COLUMNS=120 >> $GITHUB_ENV
85+
echo COMPOSER_MIN_STAB='composer config minimum-stability ${{ matrix.minimum-stability || 'stable' }} --ansi' >> $GITHUB_ENV
86+
echo COMPOSER_UP='composer update ${{ matrix.composer-flags }} --no-progress --no-interaction --ansi' >> $GITHUB_ENV
87+
echo PHPUNIT='vendor/bin/simple-phpunit' >> $GITHUB_ENV
88+
89+
# Swup and Typed have no tests, Turbo has its own workflow file
90+
PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | sed 's/^src\///' | grep -Ev "Swup|Turbo|Typed" | sort | tr '\n' ' ')
91+
echo "Packages: $PACKAGES"
92+
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
93+
94+
- name: Setup PHP
95+
uses: shivammathur/setup-php@v2
9596
with:
9697
php-version: ${{ matrix.php-version }}
98+
tools: flex
9799

98-
- name: Install root packages
99-
uses: ramsey/composer-install@v3
100-
with:
101-
working-directory: ${{ github.workspace }}
102-
dependency-versions: ${{ matrix.dependency-version }}
100+
- name: Install root dependencies
101+
run: composer install
103102

104103
- name: Build root packages
105104
run: php .github/build-packages.php
106-
working-directory: ${{ github.workspace }}
107-
108-
- name: Configure ${{ matrix.minimum-stability }} stability
109-
if: ${{ matrix.minimum-stability }}
110-
run: composer config minimum-stability ${{ matrix.minimum-stability }}
111-
working-directory: "src/${{ matrix.component }}"
112105

113-
- name: Install ${{ matrix.component }} packages
114-
uses: ramsey/composer-install@v3
115-
with:
116-
working-directory: "src/${{ matrix.component }}"
117-
dependency-versions: ${{ matrix.dependency-version }}
118-
119-
- name: ${{ matrix.component }} Tests
120-
working-directory: "src/${{ matrix.component }}"
121-
run: vendor/bin/simple-phpunit
106+
- name: Run packages tests
107+
run: |
108+
_run_task() {
109+
local ok=0
110+
local title="$1"
111+
local start=$(date -u +%s)
112+
OUTPUT=$(bash -xc "$2" 2>&1) || ok=$?
113+
local end=$(date -u +%s)
114+
115+
if [[ $ok -ne 0 ]]; then
116+
printf "\n%-70s%10s\n" $title $(($end-$start))s
117+
echo "$OUTPUT"
118+
echo "Job exited with: $ok"
119+
echo -e "\n::error::KO $title\\n"
120+
else
121+
printf "::group::%-68s%10s\n" $title $(($end-$start))s
122+
echo "$OUTPUT"
123+
echo -e "\n\\e[32mOK\\e[0m $title\\n\\n::endgroup::"
124+
fi
125+
126+
exit $ok
127+
}
128+
export -f _run_task
129+
130+
echo "$PACKAGES" | xargs -n1 | parallel -j +3 "_run_task {} '(cd src/{} && $COMPOSER_MIN_STAB && $COMPOSER_UP && $PHPUNIT)'"
122131
123132
tests-js:
124133
runs-on: ubuntu-latest

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"dev"
66
],
77
"require-dev": {
8-
"symfony/filesystem": "^5.2|^6.0|^7.0",
9-
"symfony/finder": "^5.4|^6.0|^7.0",
8+
"php": ">=8.1",
9+
"symfony/filesystem": "^6.4|^7.0",
10+
"symfony/finder": "^6.4|^7.0",
1011
"php-cs-fixer/shim": "^3.62"
1112
}
1213
}

0 commit comments

Comments
 (0)