|
5 | 5 | * Though this script attempts to simplify, it borrows heavily from Symfony's approach. |
6 | 6 | * |
7 | 7 | * @see https://github.com/symfony/symfony/blob/7.2/.github/build-packages.php |
8 | | - * |
9 | | - * TODO: This script is not really optimized, because it runs on every unit test action. |
10 | 8 | */ |
11 | 9 |
|
12 | | -$tempestPackages = json_decode( |
13 | | - json: exec(__DIR__ . '/get-packages'), |
14 | | - associative: true |
15 | | -); |
| 10 | +$output = shell_exec(__DIR__ . '/get-packages'); |
| 11 | +$tempestPackages = json_decode($output, associative: true); |
| 12 | + |
| 13 | +// Determine the dev version from inter-package dependencies. |
| 14 | +// This ensures we bundle packages with the same version that deps expect. |
| 15 | +$devVersion = 'dev-main'; |
| 16 | + |
| 17 | +foreach ($tempestPackages as $package) { |
| 18 | + $composerPath = sprintf('%s/composer.json', $package['directory']); |
| 19 | + $composerFile = json_decode(file_get_contents($composerPath), true); |
| 20 | + |
| 21 | + foreach ($composerFile['require'] ?? [] as $dep => $version) { |
| 22 | + if (str_starts_with($dep, 'tempest/') && str_starts_with($version, 'dev-')) { |
| 23 | + $devVersion = $version; |
| 24 | + break 2; |
| 25 | + } |
| 26 | + } |
| 27 | +} |
16 | 28 |
|
17 | 29 | $composerPackages = [ |
18 | 30 | 'packages' => [], |
19 | 31 | ]; |
20 | 32 |
|
21 | 33 | foreach ($tempestPackages as $package) { |
22 | | - // Find out if there are changes in this package. |
23 | | - $diff = exec(sprintf('git diff --name-only HEAD^ -- %s', $package['directory'])); |
24 | | - |
25 | 34 | $composerPath = sprintf('%s/composer.json', $package['directory']); |
26 | 35 | $composerFile = json_decode(file_get_contents($composerPath), true); |
27 | 36 |
|
28 | | - // If there are changes, bundle the package and |
29 | | - // add it to our root packages.json file. |
30 | | - if (empty($diff) === false) { |
31 | | - // Bundle the current package as a tar file. |
32 | | - passthru(sprintf("cd %s && tar -cf package.tar --exclude='package.tar' *", $package['directory'])); |
| 37 | + // Bundle ALL packages as tar files to ensure consistent versions. |
| 38 | + // This ensures all inter-package dependencies (e.g., dev-3.x) can be |
| 39 | + // resolved from the local repository. |
| 40 | + passthru(sprintf("cd %s && tar -cf package.tar --exclude='package.tar' *", $package['directory'])); |
33 | 41 |
|
34 | | - // TODO: Update the package version. |
35 | | - $composerFile['version'] = 'dev-main'; |
36 | | - $composerFile['dist']['type'] = 'tar'; |
37 | | - $composerFile['dist']['url'] = 'file://'. $package['directory'] . '/package.tar'; |
| 42 | + $composerFile['version'] = $devVersion; |
| 43 | + $composerFile['dist']['type'] = 'tar'; |
| 44 | + $composerFile['dist']['url'] = 'file://'. $package['directory'] . '/package.tar'; |
38 | 45 |
|
39 | | - // Add the package details to the root "packages.json." |
40 | | - $composerPackages['packages'][$composerFile['name']][$composerFile['version']] = $composerFile; |
41 | | - } |
| 46 | + // Add the package details to the root "packages.json." |
| 47 | + $composerPackages['packages'][$composerFile['name']][$composerFile['version']] = $composerFile; |
42 | 48 |
|
43 | 49 | // Load the packages from the root "packages.json" file we will write in a second. |
44 | 50 | $composerFile['repositories'] = [ |
|
0 commit comments