Skip to content

Commit

Permalink
[CI] Test ux.symfony.com with local UX packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal authored and kbond committed Aug 14, 2024
1 parent 92ad2de commit 1386749
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
57 changes: 28 additions & 29 deletions .github/build-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,50 @@
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)) {
passthru(sprintf('composer validate %s', $composerFile->getPathname()));
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) {
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/ux.symfony.com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1386749

Please sign in to comment.