Skip to content

Commit 6bab0c1

Browse files
Merge branch '2.8' into 3.4
* 2.8: [travis] fix composer.lock invalidation for deps=low
2 parents 2c863c6 + 68c00ad commit 6bab0c1

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

.github/rm-invalid-lowest-lock-files.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
error_reporting(-1);
4+
set_error_handler(function ($type, $message, $file, $line) {
5+
if (error_reporting()) {
6+
throw new \ErrorException($message, 0, $type, $file, $line);
7+
}
8+
});
39
array_shift($_SERVER['argv']);
410
$dirs = $_SERVER['argv'];
511

@@ -59,6 +65,8 @@ function getContentHash(array $composerJson)
5965
$composerJsons[$composerJson['name']] = array($dir, $composerLock['packages'], getRelevantContent($composerJson));
6066
}
6167

68+
$referencedCommits = array();
69+
6270
foreach ($composerJsons as list($dir, $lockedPackages)) {
6371
foreach ($lockedPackages as $lockedJson) {
6472
if (0 !== strpos($version = $lockedJson['version'], 'dev-') && '-dev' !== substr($version, -4)) {
@@ -83,5 +91,59 @@ function getContentHash(array $composerJson)
8391
@unlink($dir.'/composer.lock');
8492
continue 2;
8593
}
94+
95+
$referencedCommits[$name][$lockedJson['source']['reference']][] = $dir;
96+
}
97+
}
98+
99+
if (!$referencedCommits || (isset($_SERVER['TRAVIS_PULL_REQUEST']) && 'false' === $_SERVER['TRAVIS_PULL_REQUEST'])) {
100+
// cached commits cannot be stale for PRs
101+
return;
102+
}
103+
104+
@mkdir($_SERVER['HOME'].'/.cache/composer/repo/https---repo.packagist.org', 0777, true);
105+
106+
$ch = null;
107+
$mh = curl_multi_init();
108+
$sh = curl_share_init();
109+
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
110+
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
111+
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
112+
$chs = array();
113+
114+
foreach ($referencedCommits as $name => $dirsByCommit) {
115+
$chs[] = $ch = array(curl_init(), fopen($_SERVER['HOME'].'/.cache/composer/repo/https---repo.packagist.org/provider-'.strtr($name, '/', '$').'.json', 'wb'));
116+
curl_setopt($ch[0], CURLOPT_URL, 'https://repo.packagist.org/p/'.$name.'.json');
117+
curl_setopt($ch[0], CURLOPT_FILE, $ch[1]);
118+
curl_setopt($ch[0], CURLOPT_SHARE, $sh);
119+
curl_multi_add_handle($mh, $ch[0]);
120+
}
121+
122+
do {
123+
curl_multi_exec($mh, $active);
124+
curl_multi_select($mh);
125+
} while ($active);
126+
127+
foreach ($chs as list($ch, $fd)) {
128+
curl_multi_remove_handle($mh, $ch);
129+
curl_close($ch);
130+
fclose($fd);
131+
}
132+
133+
foreach ($referencedCommits as $name => $dirsByCommit) {
134+
$repo = file_get_contents($_SERVER['HOME'].'/.cache/composer/repo/https---repo.packagist.org/provider-'.strtr($name, '/', '$').'.json');
135+
$repo = json_decode($repo, true);
136+
137+
foreach ($repo['packages'][$name] as $version) {
138+
unset($referencedCommits[$name][$version['source']['reference']]);
139+
}
140+
}
141+
142+
foreach ($referencedCommits as $name => $dirsByCommit) {
143+
foreach ($dirsByCommit as $dirs) {
144+
foreach ($dirs as $dir) {
145+
echo "$dir/composer.lock references old commit for $name.\n";
146+
@unlink($dir.'/composer.lock');
147+
}
86148
}
87149
}

0 commit comments

Comments
 (0)