|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Though this script attempts to simplify, it borrows heavily from Symfony's approach. |
| 6 | + * |
| 7 | + * @see https://github.com/symfony/symfony/blob/7.2/.github/build-packages.php |
| 8 | + */ |
| 9 | + |
| 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 | +} |
| 28 | + |
| 29 | +$composerPackages = [ |
| 30 | + 'packages' => [], |
| 31 | +]; |
| 32 | + |
| 33 | +foreach ($tempestPackages as $package) { |
| 34 | + $composerPath = sprintf('%s/composer.json', $package['directory']); |
| 35 | + $composerFile = json_decode(file_get_contents($composerPath), true); |
| 36 | + |
| 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'])); |
| 41 | + |
| 42 | + $composerFile['version'] = $devVersion; |
| 43 | + $composerFile['dist']['type'] = 'tar'; |
| 44 | + $composerFile['dist']['url'] = 'file://'. $package['directory'] . '/package.tar'; |
| 45 | + |
| 46 | + // Add the package details to the root "packages.json." |
| 47 | + $composerPackages['packages'][$composerFile['name']][$composerFile['version']] = $composerFile; |
| 48 | + |
| 49 | + // Load the packages from the root "packages.json" file we will write in a second. |
| 50 | + $composerFile['repositories'] = [ |
| 51 | + [ |
| 52 | + 'type' => 'composer', |
| 53 | + 'url' => realpath(__DIR__ . '/../'), |
| 54 | + ] |
| 55 | + ]; |
| 56 | + |
| 57 | + file_put_contents($composerPath, json_encode($composerFile, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
| 58 | +} |
| 59 | + |
| 60 | +file_put_contents(__DIR__ . '/../packages.json', json_encode($composerPackages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); |
| 61 | + |
| 62 | +var_dump(file_get_contents(__DIR__ . '/../packages.json')); |
0 commit comments