diff --git a/.github/build-packages.php b/.github/build-packages.php index d9dc870b006..65bf0c27c32 100644 --- a/.github/build-packages.php +++ b/.github/build-packages.php @@ -9,11 +9,13 @@ use Symfony\Component\Finder\Finder; $finder = (new Finder()) - ->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/']) + ->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/', __DIR__.'/../ux.symfony.com/']) ->depth(0) ->name('composer.json') ; +// 1. Find all UX packages +$uxPackages = []; foreach ($finder as $composerFile) { $json = file_get_contents($composerFile->getPathname()); if (null === $packageData = json_decode($json, true)) { @@ -21,39 +23,36 @@ exit(1); } - $repositories = []; + if (str_starts_with($composerFile->getPathname(), __DIR__ . '/../src/')) { + $packageName = $packageData['name']; - if (isset($packageData['require']['symfony/ux-twig-component']) - || isset($packageData['require-dev']['symfony/ux-twig-component']) - ) { - $repositories[] = [ - 'type' => 'path', - 'url' => '../TwigComponent', + $uxPackages[$packageName] = [ + 'path' => realpath($composerFile->getPath()), ]; - $key = isset($packageData['require']['symfony/ux-twig-component']) ? 'require' : 'require-dev'; - $packageData[$key]['symfony/ux-twig-component'] = '@dev'; } +} - if (isset($packageData['require']['symfony/stimulus-bundle']) - || isset($packageData['require-dev']['symfony/stimulus-bundle']) - ) { - $repositories[] = [ - 'type' => 'path', - 'url' => '../StimulusBundle', - ]; - $key = isset($packageData['require']['symfony/stimulus-bundle']) ? 'require' : 'require-dev'; - $packageData[$key]['symfony/stimulus-bundle'] = '@dev'; +// 2. Update all composer.json files from the repository, to use the local version of the UX packages +foreach ($finder as $composerFile) { + $json = file_get_contents($composerFile->getPathname()); + if (null === $packageData = json_decode($json, true)) { + passthru(sprintf('composer validate %s', $composerFile->getPathname())); + exit(1); } - - if (isset($packageData['require']['symfony/ux-map']) - || isset($packageData['require-dev']['symfony/ux-map']) - ) { - $repositories[] = [ - 'type' => 'path', - 'url' => '../../../', - ]; - $key = isset($packageData['require']['symfony/ux-map']) ? 'require' : 'require-dev'; - $packageData[$key]['symfony/ux-map'] = '@dev'; + + $repositories = $packageData['repositories'] ?? []; + + foreach ($uxPackages as $packageName => $packageInfo) { + if (isset($packageData['require'][$packageName]) + || isset($packageData['require-dev'][$packageName]) + ) { + $repositories[] = [ + 'type' => 'path', + 'url' => $packageInfo['path'], + ]; + $key = isset($packageData['require'][$packageName]) ? 'require' : 'require-dev'; + $packageData[$key][$packageName] = '@dev'; + } } if ($repositories) { diff --git a/.github/workflows/ux.symfony.com.yaml b/.github/workflows/ux.symfony.com.yaml index 48ec0b31ba4..0506ec5ad4b 100644 --- a/.github/workflows/ux.symfony.com.yaml +++ b/.github/workflows/ux.symfony.com.yaml @@ -4,9 +4,15 @@ on: push: paths: - 'ux.symfony.com/**' + - 'src/*/**' + - '!src/*/doc/**' + - '.github/**' pull_request: paths: - 'ux.symfony.com/**' + - 'src/*/**' + - '!src/*/doc/**' + - '.github/**' jobs: @@ -58,10 +64,18 @@ jobs: - uses: shivammathur/setup-php@v2 with: php-version: '8.3' + - name: Install root dependencies + uses: ramsey/composer-install@v3 + with: + working-directory: ${{ github.workspace }} + - name: Build root packages + run: php .github/build-packages.php + working-directory: ${{ github.workspace }} - name: Install dependencies uses: ramsey/composer-install@v3 with: working-directory: ux.symfony.com + dependency-versions: 'highest' - name: Importmap dependencies run: php bin/console importmap:install - name: Build Sass assets