Skip to content

Commit d29c52c

Browse files
committed
[CI] Test ux.symfony.com with local UX packages
1 parent 92ad2de commit d29c52c

File tree

3 files changed

+92
-29
lines changed

3 files changed

+92
-29
lines changed

.github/build-packages.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,50 @@
99
use Symfony\Component\Finder\Finder;
1010

1111
$finder = (new Finder())
12-
->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/'])
12+
->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/', __DIR__.'/../ux.symfony.com/'])
1313
->depth(0)
1414
->name('composer.json')
1515
;
1616

17+
// 1. Find all UX packages
18+
$uxPackages = [];
1719
foreach ($finder as $composerFile) {
1820
$json = file_get_contents($composerFile->getPathname());
1921
if (null === $packageData = json_decode($json, true)) {
2022
passthru(sprintf('composer validate %s', $composerFile->getPathname()));
2123
exit(1);
2224
}
2325

24-
$repositories = [];
26+
if (str_starts_with($composerFile->getPathname(), __DIR__ . '/../src/')) {
27+
$packageName = $packageData['name'];
2528

26-
if (isset($packageData['require']['symfony/ux-twig-component'])
27-
|| isset($packageData['require-dev']['symfony/ux-twig-component'])
28-
) {
29-
$repositories[] = [
30-
'type' => 'path',
31-
'url' => '../TwigComponent',
29+
$uxPackages[$packageName] = [
30+
'path' => realpath($composerFile->getPath()),
3231
];
33-
$key = isset($packageData['require']['symfony/ux-twig-component']) ? 'require' : 'require-dev';
34-
$packageData[$key]['symfony/ux-twig-component'] = '@dev';
3532
}
33+
}
3634

37-
if (isset($packageData['require']['symfony/stimulus-bundle'])
38-
|| isset($packageData['require-dev']['symfony/stimulus-bundle'])
39-
) {
40-
$repositories[] = [
41-
'type' => 'path',
42-
'url' => '../StimulusBundle',
43-
];
44-
$key = isset($packageData['require']['symfony/stimulus-bundle']) ? 'require' : 'require-dev';
45-
$packageData[$key]['symfony/stimulus-bundle'] = '@dev';
35+
// 2. Update all composer.json files from the repository, to use the local version of the UX packages
36+
foreach ($finder as $composerFile) {
37+
$json = file_get_contents($composerFile->getPathname());
38+
if (null === $packageData = json_decode($json, true)) {
39+
passthru(sprintf('composer validate %s', $composerFile->getPathname()));
40+
exit(1);
4641
}
47-
48-
if (isset($packageData['require']['symfony/ux-map'])
49-
|| isset($packageData['require-dev']['symfony/ux-map'])
50-
) {
51-
$repositories[] = [
52-
'type' => 'path',
53-
'url' => '../../../',
54-
];
55-
$key = isset($packageData['require']['symfony/ux-map']) ? 'require' : 'require-dev';
56-
$packageData[$key]['symfony/ux-map'] = '@dev';
42+
43+
$repositories = $packageData['repositories'] ?? [];
44+
45+
foreach ($uxPackages as $packageName => $packageInfo) {
46+
if (isset($packageData['require'][$packageName])
47+
|| isset($packageData['require-dev'][$packageName])
48+
) {
49+
$repositories[] = [
50+
'type' => 'path',
51+
'url' => $packageInfo['path'],
52+
];
53+
$key = isset($packageData['require'][$packageName]) ? 'require' : 'require-dev';
54+
$packageData[$key][$packageName] = '@dev';
55+
}
5756
}
5857

5958
if ($repositories) {

.github/reinstall-packages.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* Read the composer.json file from the current working directory, and reinstall the UX packages to the local version.
5+
*/
6+
7+
require __DIR__.'/../vendor/autoload.php';
8+
9+
use Symfony\Component\Finder\Finder;
10+
11+
$finder = (new Finder())
12+
->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/'])
13+
->depth(0)
14+
->name('composer.json')
15+
;
16+
17+
// 1. Find all UX packages
18+
$uxPackages = [];
19+
foreach ($finder as $composerFile) {
20+
$json = file_get_contents($composerFile->getPathname());
21+
if (null === $packageData = json_decode($json, true)) {
22+
passthru(sprintf('composer validate %s', $composerFile->getPathname()));
23+
exit(1);
24+
}
25+
26+
$uxPackages[] = $packageData['name'];
27+
}
28+
29+
// 2. Reinstall all UX packages
30+
$composerFile = getcwd().'/composer.json';
31+
if (!file_exists($composerFile)) {
32+
echo 'No "composer.json" file found in the current working directory.'.PHP_EOL;
33+
exit(1);
34+
}
35+
$json = file_get_contents($composerFile);
36+
if (null === $packageData = json_decode($json, true)) {
37+
passthru(sprintf('composer validate %s', $composerFile));
38+
exit(1);
39+
}
40+
41+
$toUpdate = [
42+
...array_intersect($uxPackages, array_keys($packageData['require'] ?? [])),
43+
...array_intersect($uxPackages, array_keys($packageData['require-dev'] ?? [])),
44+
];
45+
46+
if ($toUpdate) {
47+
passthru(sprintf('composer update %s', implode(' ', $toUpdate)));
48+
}

.github/workflows/ux.symfony.com.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ on:
44
push:
55
paths:
66
- 'ux.symfony.com/**'
7+
- 'src/*/**'
8+
- '!src/*/doc/**'
9+
- '.github/**'
710
pull_request:
811
paths:
912
- 'ux.symfony.com/**'
13+
- 'src/*/**'
14+
- '!src/*/doc/**'
15+
- '.github/**'
1016

1117
jobs:
1218

@@ -58,10 +64,20 @@ jobs:
5864
- uses: shivammathur/setup-php@v2
5965
with:
6066
php-version: '8.3'
67+
- name: Install root dependencies
68+
uses: ramsey/composer-install@v3
69+
with:
70+
working-directory: ${{ github.workspace }}
71+
- name: Build root packages
72+
run: php .github/build-packages.php
73+
working-directory: ${{ github.workspace }}
6174
- name: Install dependencies
6275
uses: ramsey/composer-install@v3
6376
with:
6477
working-directory: ux.symfony.com
78+
dependency-versions: 'highest'
79+
# - name: Re-install root packages, to force local packages to be used
80+
# run: php ../.github/reinstall-packages.php
6581
- name: Importmap dependencies
6682
run: php bin/console importmap:install
6783
- name: Build Sass assets

0 commit comments

Comments
 (0)