|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Updates inter-package dependencies to use the current branch. |
| 6 | + * |
| 7 | + * Usage: bin/update-branch-deps [branch] |
| 8 | + * |
| 9 | + * If no branch is specified, uses the current git branch. |
| 10 | + * This is useful when creating version branches (e.g., 3.x) that need |
| 11 | + * inter-package dependencies to reference dev-3.x instead of dev-main. |
| 12 | + */ |
| 13 | + |
| 14 | +$branch = $argv[1] ?? trim(exec('git rev-parse --abbrev-ref HEAD')); |
| 15 | +$devBranch = "dev-{$branch}"; |
| 16 | + |
| 17 | +echo "Updating inter-package dependencies to {$devBranch}\n\n"; |
| 18 | + |
| 19 | +$output = shell_exec(__DIR__ . '/get-packages'); |
| 20 | +$tempestPackages = json_decode($output, associative: true); |
| 21 | + |
| 22 | +$packageNames = array_map(fn($p) => $p['package'], $tempestPackages); |
| 23 | + |
| 24 | +foreach ($tempestPackages as $package) { |
| 25 | + $composerPath = sprintf('%s/composer.json', $package['directory']); |
| 26 | + $composerFile = json_decode(file_get_contents($composerPath), true); |
| 27 | + $modified = false; |
| 28 | + |
| 29 | + foreach (['require', 'require-dev'] as $section) { |
| 30 | + if (!isset($composerFile[$section])) { |
| 31 | + continue; |
| 32 | + } |
| 33 | + |
| 34 | + foreach ($composerFile[$section] as $dep => $version) { |
| 35 | + if (in_array($dep, $packageNames, true) && $version !== $devBranch) { |
| 36 | + $composerFile[$section][$dep] = $devBranch; |
| 37 | + $modified = true; |
| 38 | + echo " {$package['name']}: {$dep} -> {$devBranch}\n"; |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + if ($modified) { |
| 44 | + file_put_contents( |
| 45 | + $composerPath, |
| 46 | + json_encode($composerFile, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n" |
| 47 | + ); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +echo "\nDone.\n"; |
0 commit comments