Skip to content

Commit

Permalink
minor #2063 [CI] Test ux.symfony.com with local UX packages (Kocal)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.x branch.

Discussion
----------

[CI] Test ux.symfony.com with local UX packages

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Issues        | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

<!--
Replace this notice by a description of your feature/bugfix.
This will help reviewers and should be a good start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - For new features, provide some code snippets to help understand usage.
 - Features and deprecations must be submitted against branch main.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
 - Never break backward compatibility (see https://symfony.com/bc).
-->

Following #1965 and #2060, I was a bit surprised to see ux.symfony.com tests were executed with UX packages coming from `2.x` branch, instead of UX packages from the same PR.

I believe doing this could help us for the future and prevent some regressions.

I've updated the script `.github/build-packages.php` to automatically replaces **all UX packages requires(-dev)** from all significant `composer.json` files from the repo:
<img width="1270" alt="image" src="https://github.com/user-attachments/assets/e04ff73f-7558-46cc-91e2-bf49c26a7f04">

Commits
-------

1386749 [CI] Test ux.symfony.com with local UX packages
  • Loading branch information
kbond committed Aug 14, 2024
2 parents 0659a10 + 1386749 commit 90c390b
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 90c390b

Please sign in to comment.