1
0
Fork 0

Add extra debug info when running GH Actions and an archive extraction fails, refs #11148

pull/11156/head
Jordi Boggiano 2022-10-26 12:27:24 +02:00
parent 923ff98ea0
commit 10e757d6b0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 26 additions and 0 deletions

View File

@ -64,6 +64,15 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
* @internal
*/
public static $downloadMetadata = [];
/**
* Collects response headers when running on GH Actions
*
* @see https://github.com/composer/composer/issues/11148
* @var array<string, array<string>>
* @private
* @internal
*/
public static $responseHeaders = [];
/**
* @var array<string, string> Map of package name to cache key
@ -222,6 +231,10 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$cacheKey = $url['cacheKey'];
FileDownloader::$downloadMetadata[$package->getName()] = @filesize($fileName) ?: $response->getHeader('Content-Length') ?: '?';
if (Platform::getEnv('GITHUB_ACTIONS') !== false && Platform::getEnv('COMPOSER_TESTS_ARE_RUNNING') === false) {
FileDownloader::$responseHeaders[$package->getName()] = $response->getHeaders();
}
if ($cache && !$cache->isReadOnly()) {
$this->lastCacheWrites[$package->getName()] = $cacheKey;
$cache->copyFrom($cacheKey, $fileName);

View File

@ -151,6 +151,19 @@ class ZipDownloader extends ArchiveDownloader
$io->writeError(' <warning>'.$processError->getMessage().'</warning>');
$io->writeError(' The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)');
$io->writeError(' Unzip with '.$executable.' command failed, falling back to ZipArchive class');
// additional debug data to try to figure out GH actions issues https://github.com/composer/composer/issues/11148
if (Platform::getEnv('GITHUB_ACTIONS') !== false && Platform::getEnv('COMPOSER_TESTS_ARE_RUNNING') === false) {
$io->writeError(' <warning>Additional debug info, please report to https://github.com/composer/composer/issues/11148 if you see this:</warning>');
$io->writeError('File size: '.@filesize($file));
$io->writeError('File SHA1: '.hash_file('sha1', $file));
$io->writeError('First 100 bytes (hex): '.bin2hex(substr((string) file_get_contents($file), 0, 100)));
$io->writeError('Last 100 bytes (hex): '.bin2hex(substr((string) file_get_contents($file), -100)));
if (strlen((string) $package->getDistUrl()) > 0) {
$io->writeError('Origin URL: '.$this->processUrl($package, (string) $package->getDistUrl()));
$io->writeError('Response Headers: '.json_encode(FileDownloader::$responseHeaders[$package->getName()] ?? []));
}
}
}
return $this->extractWithZipArchive($package, $file, $path);