8000 minor #28146 [travis] cache composer.lock files for deps=low (nicolas… · alex-dev/symfony@8b5317f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b5317f

Browse files
minor symfony#28146 [travis] cache composer.lock files for deps=low (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [travis] cache composer.lock files for deps=low | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - I just realized that the resolved package versions for lowest deps depends only on the root composer.json, and not on transitive deps. This means we can cache the lock files and save ~10 minutes required to resolve the lowest deps of the SecurityBundle. Commits ------- caaa74c [travis] cache composer.lock files for deps=low
1 parent f2a1614 commit 8b5317f

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
array_shift($_SERVER['argv']);
4+
$dirs = $_SERVER['argv'];
5+
6+
function getContentHash($composerJson)
7+
{
8+
$relevantKeys = array(
9+
'name',
10+
'require',
11+
'require-dev',
12+
'conflict',
13+
'replace',
14+
'provide',
15+
'minimum-stability',
16+
'prefer-stable',
17+
'repositories',
18+
'extra',
19+
);
20+
21+
$relevantContent = array();
22+
23+
foreach (array_intersect($relevantKeys, array_keys($composerJson)) as $key) {
24+
$relevantContent[$key] = $composerJson[$key];
25+
}
26+
if (isset($composerJson['config']['platform'])) {
27+
$relevantContent['config']['platform'] = $composerJson['config']['platform'];
28+
}
29+
30+
ksort($relevantContent);
31+
32+
return md5(json_encode($relevantContent));
33+
}
34+
35+
$composerLocks = array();
36+
37+
foreach ($dirs as $dir) {
38+
if (!file_exists($dir.'/composer.lock') || !$composerLock = @json_decode(file_get_contents($dir.'/composer.lock'), true)) {
39+
echo "$dir/composer.lock not found or invalid.\n";
40+
@unlink($dir.'/composer.lock');
41+
continue;
42+
}
43+
if (!file_exists($dir.'/composer.json') || !$composerJson = @json_decode(file_get_contents($dir.'/composer.json'), true)) {
44+
echo "$dir/composer.json not found or invalid.\n";
45+
@unlink($dir.'/composer.lock');
46+
continue;
47+
}
48+
if (!isset($composerLock['content-hash']) || getContentHash($composerJson) !== $composerLock['content-hash']) {
49+
echo "$dir/composer.lock is outdated.\n";
50+
@unlink($dir.'/composer.lock');
51+
continue;
52+
}
53+
$composerLocks[$composerJson['name']] = array($dir, $composerLock, $composerJson);
54+
}
55+
56+
foreach ($composerLocks as list($dir, $composerLock)) {
57+
foreach ($composerLock['packages'] as $composerJson) {
58+
if (0 !== strpos($version = $composerJson['version'], 'dev-') && '-dev' !== substr($version, -4)) {
59+
continue;
60+
}
61+
62+
if (!isset($composerLocks[$name = $composerJson['name']])) {
63+
echo "$dir/composer.lock references missing $name.\n";
64+
@unlink($dir.'/composer.lock');
65+
continue 2;
66+
}
67+
68+
foreach (array('minimum-stability', 'prefer-stable', 'repositories') as $key) {
69+
if (array_key_exists($key, $composerLocks[$name][2])) {
70+
$composerJson[$key] = $composerLocks[$name][2][$key];
71+
}
72+
}
73+
74+
if (getContentHash($composerJson) !== $composerLocks[$name][1]['content-hash']) {
75+
echo "$dir/composer.lock is not in sync with $name.\n";
76+
@unlink($dir.'/composer.lock');
77+
continue 2;
78+
}
79+
}
80+
}

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ install:
202202
if [[ $deps = high ]]; then
203203
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP && $PHPUNIT_X$LEGACY'"
204204
elif [[ $deps = low ]]; then
205-
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP --prefer-lowest --prefer-stable && $PHPUNIT_X'"
205+
[[ -e ~/php-ext/composer-lowest.lock.tar ]] && tar -xf ~/php-ext/composer-lowest.lock.tar
206+
tar -cf ~/php-ext/composer-lowest.lock.tar --files-from /dev/null
207+
php .github/rm-invalid-lowest-lock-files.php $COMPONENTS
208+
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && ([ -e composer.lock ] && ${COMPOSER_UP/update/install} || $COMPOSER_UP --prefer-lowest --prefer-stable) && $PHPUNIT_X'"
209+
echo "$COMPONENTS" | xargs -n1 -I{} tar --append -f ~/php-ext/composer-lowest.lock.tar {}/composer.lock
206210
else
207211
echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}"
208212
tfold src/Symfony/Component/Console.tty $PHPUNIT src/Symfony/Component/Console --group tty

0 commit comments

Comments
 (0)
0