Skip to content

Commit 30468ff

Browse files
authored
ci: build changed packages
1 parent bf2a2f0 commit 30468ff

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

.github/workflows/isolated-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ jobs:
5050
steps:
5151
- name: Checkout code
5252
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 2
5355

5456
- name: Setup PHP
5557
uses: shivammathur/setup-php@v2

bin/build-changed-packages

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,40 @@
55
* Though this script attempts to simplify, it borrows heavily from Symfony's approach.
66
*
77
* @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.
810
*/
911

1012
$tempestPackages = json_decode(
11-
json: exec(__DIR__ . '/get-packages'),
12-
associative: true
13+
json: exec(__DIR__ . '/get-packages'),
14+
associative: true
1315
);
1416

15-
$composerPackages = [];
17+
$composerPackages = [
18+
'packages' => [],
19+
];
1620

1721
foreach ($tempestPackages as $package) {
1822
// Find out if there are changes in this package.
1923
$diff = exec(sprintf('git diff --name-only HEAD^ -- %s', $package['directory']));
2024

21-
// If there are not any changes, move on to the next package.
22-
if (empty($diff)) {
23-
continue;
24-
}
25-
26-
// Bundle the current package as a tar file.
27-
passthru(sprintf("cd %s && tar -cf package.tar --exclude='package.tar' *", $package['directory']));
28-
2925
$composerPath = sprintf('%s/composer.json', $package['directory']);
3026
$composerFile = json_decode(file_get_contents($composerPath), true);
3127

32-
// TODO: Update this version.
33-
$composerFile['version'] = 'dev-main';
34-
$composerFile['dist']['type'] = 'tar';
35-
$composerFile['dist']['source'] = $package['directory'] . '/package.tar';
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']));
33+
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';
38+
39+
// Add the package details to the root "packages.json."
40+
$composerPackages['packages'][$composerFile['name']][$composerFile['version']] = $composerFile;
41+
}
3642

3743
// Load the packages from the root "packages.json" file we will write in a second.
3844
$composerFile['repositories'] = [
@@ -42,10 +48,9 @@ foreach ($tempestPackages as $package) {
4248
]
4349
];
4450

45-
// Add the package details to the root "packages.json."
46-
$composerPackages[$composerFile['name']][$composerFile['version']] = $composerFile;
51+
file_put_contents($composerPath, json_encode($composerFile, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
4752
}
4853

49-
file_put_contents(__DIR__ . '/../packages.json', json_encode($composerPackages, JSON_PRETTY_PRINT));
54+
file_put_contents(__DIR__ . '/../packages.json', json_encode($composerPackages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
5055

5156
var_dump(file_get_contents(__DIR__ . '/../packages.json'));

0 commit comments

Comments
 (0)