From 10e757d6b08b27915185ed5ad12cca25932efc8b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 26 Oct 2022 12:27:24 +0200 Subject: [PATCH] Add extra debug info when running GH Actions and an archive extraction fails, refs #11148 --- src/Composer/Downloader/FileDownloader.php | 13 +++++++++++++ src/Composer/Downloader/ZipDownloader.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index b8907553a..6704cb486 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -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> + * @private + * @internal + */ + public static $responseHeaders = []; /** * @var array 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); diff --git a/src/Composer/Downloader/ZipDownloader.php b/src/Composer/Downloader/ZipDownloader.php index 4a4095e5d..725e6468d 100644 --- a/src/Composer/Downloader/ZipDownloader.php +++ b/src/Composer/Downloader/ZipDownloader.php @@ -151,6 +151,19 @@ class ZipDownloader extends ArchiveDownloader $io->writeError(' '.$processError->getMessage().''); $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(' Additional debug info, please report to https://github.com/composer/composer/issues/11148 if you see this:'); + $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);