Skip to content

Commit ea8ae64

Browse files
minor symfony#60680 Fix building packages in the CI (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- Fix building packages in the CI | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Instead of symfony#60672 Commits ------- 51205c8 Fix building packages in the CI
2 parents 17fa1fd + 51205c8 commit ea8ae64

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

.github/build-packages.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?php
22

3-
require __DIR__.'/vendor/autoload.php';
4-
5-
use Composer\MetadataMinifier\MetadataMinifier;
3+
// Logic inspired from composer/metadata-minifier
4+
function expandComposerMetadata(array $versions): array
5+
{
6+
array_reduce($versions, function ($carry, $version) use (&$expandedVersions) {
7+
return $expandedVersions[] = array_filter(array_merge($carry, $version), fn ($v) => '__unset' !== $v);
8+
}, []);
9+
10+
return $expandedVersions ?? [];
11+
}
612

713
if (3 > $_SERVER['argc']) {
814
echo "Usage: branch version dir1 dir2 ... dirN\n";
@@ -56,24 +62,14 @@
5662

5763
$packages[$package->name][$package->version] = $package;
5864

59-
if (false !== $taggedReleases = @file_get_contents('https://repo.packagist.org/p2/'.$package->name.'.json')) {
60-
$versions = MetadataMinifier::expand(json_decode($taggedReleases, true)['packages'][$package->name]);
65+
foreach (['.json', '~dev.json'] as $ext) {
66+
$versions = @file_get_contents('https://repo.packagist.org/p2/'.$package->name.$ext) ?: '[]';
67+
$versions = json_decode($versions, true)['packages'][$package->name] ?? [];
6168

62-
foreach ($versions as $v => $p) {
63-
$packages[$package->name] += [$v => $p];
69+
foreach (expandComposerMetadata($versions) as $p) {
70+
$packages[$package->name] += [$p['version'] => $p];
6471
}
6572
}
66-
67-
if (false !== $devReleases = @file_get_contents('https://repo.packagist.org/p2/'.$package->name.'~dev.json')) {
68-
$versions = MetadataMinifier::expand(json_decode($taggedReleases, true)['packages'][$package->name]);
69-
} else {
70-
$versions = sprintf('{"packages":{"%s":{"%s":%s}}}', $package->name, $package->version, file_get_contents($dir.'/composer.json'));
71-
$versions = json_decode($versions, true)['packages'][$package->name];
72-
}
73-
74-
foreach ($versions as $v => $p) {
75-
$packages[$package->name] += [$v => $p];
76-
}
7773
}
7874

7975
file_put_contents('packages.json', json_encode(compact('packages'), $flags));

.github/composer.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,12 @@ jobs:
9292
9393
# Create local composer packages for each patched components and reference them in composer.json files when cross-testing components
9494
if [[ ! "${{ matrix.mode }}" = *-deps ]]; then
95-
cd .github
96-
composer install
97-
php ./build-packages.php HEAD^ $SYMFONY_VERSION src/Symfony/Bridge/PhpUnit
98-
cd ..
95+
php .github/build-packages.php HEAD^ $SYMFONY_VERSION src/Symfony/Bridge/PhpUnit
9996
else
10097
echo SYMFONY_DEPRECATIONS_HELPER=weak >> $GITHUB_ENV
10198
cp composer.json composer.json.orig
10299
echo -e '{\n"require":{'"$(grep phpunit-bridge composer.json)"'"php":"*"},"minimum-stability":"dev"}' > composer.json
103-
cd .github
104-
composer install
105-
php ./build-packages.php HEAD^ $SYMFONY_VERSION $(find src/Symfony -mindepth 2 -type f -name composer.json -printf '%h\n' | grep -v src/Symfony/Component/Intl/Resources/emoji)
106-
cd ..
100+
php .github/build-packages.php HEAD^ $SYMFONY_VERSION $(find src/Symfony -mindepth 2 -type f -name composer.json -printf '%h\n' | grep -v src/Symfony/Component/Intl/Resources/emoji)
107101
mv composer.json composer.json.phpunit
108102
mv composer.json.orig composer.json
109103
fi

0 commit comments

Comments
 (0)