Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc7fb5c

Browse files
minor #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
2 parents a81d7d9 + caaa74c commit fc7fb5c

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
@@ -216,7 +216,11 @@ install:
216216
if [[ $deps = high ]]; then
217217
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP && $PHPUNIT_X$LEGACY'"
218218
elif [[ $deps = low ]]; then
219-
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && $COMPOSER_UP --prefer-lowest --prefer-stable && $PHPUNIT_X'"
219+
[[ -e ~/php-ext/composer-lowest.lock.tar ]] && tar -xf ~/php-ext/composer-lowest.lock.tar
220+
tar -cf ~/php-ext/composer-lowest.lock.tar --files-from /dev/null
221+
php .github/rm-invalid-lowest-lock-files.php $COMPONENTS
222+
echo "$COMPONENTS" | parallel --gnu -j10% "tfold {} 'cd {} && ([ -e composer.lock ] && ${COMPOSER_UP/update/install} || $COMPOSER_UP --prefer-lowest --prefer-stable) && $PHPUNIT_X'"
223+
echo "$COMPONENTS" | xargs -n1 -I{} tar --append -f ~/php-ext/composer-lowest.lock.tar {}/composer.lock
220224
elif [[ $PHP = hhvm* ]]; then
221225
$PHPUNIT --exclude-group no-hhvm,benchmark,intl-data
222226
else

0 commit comments

Comments
 (0)