emit github action formatted error messages (#9120)
parent
c845d66818
commit
fdff3aeaba
|
@ -11,6 +11,7 @@ on:
|
||||||
env:
|
env:
|
||||||
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
|
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
|
||||||
COMPOSER_UPDATE_FLAGS: ""
|
COMPOSER_UPDATE_FLAGS: ""
|
||||||
|
COMPOSER_TESTS_ARE_RUNNING: "1"
|
||||||
SYMFONY_PHPUNIT_VERSION: "8.3"
|
SYMFONY_PHPUNIT_VERSION: "8.3"
|
||||||
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1"
|
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: "1"
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use Symfony\Component\Console\Helper\QuestionHelper;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Seld\JsonLint\ParsingException;
|
||||||
use Composer\Command;
|
use Composer\Command;
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
use Composer\Factory;
|
use Composer\Factory;
|
||||||
|
@ -191,6 +192,20 @@ class Application extends BaseApplication
|
||||||
}
|
}
|
||||||
} catch (NoSslException $e) {
|
} catch (NoSslException $e) {
|
||||||
// suppress these as they are not relevant at this point
|
// suppress these as they are not relevant at this point
|
||||||
|
} catch (ParsingException $e) {
|
||||||
|
$details = $e->getDetails();
|
||||||
|
|
||||||
|
$file = realpath(Factory::getComposerFile());
|
||||||
|
|
||||||
|
$line = null;
|
||||||
|
if ($details && isset($details['line'])) {
|
||||||
|
$line = $details['line'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$ghe = new GithubActionError($this->io);
|
||||||
|
$ghe->emit($e->getMessage(), $file, $line);
|
||||||
|
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hasPluginCommands = true;
|
$this->hasPluginCommands = true;
|
||||||
|
@ -307,8 +322,13 @@ class Application extends BaseApplication
|
||||||
} catch (ScriptExecutionException $e) {
|
} catch (ScriptExecutionException $e) {
|
||||||
return (int) $e->getCode();
|
return (int) $e->getCode();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$ghe = new GithubActionError($this->io);
|
||||||
|
$ghe->emit($e->getMessage());
|
||||||
|
|
||||||
$this->hintCommonErrors($e);
|
$this->hintCommonErrors($e);
|
||||||
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Composer\Console;
|
||||||
|
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
|
|
||||||
|
final class GithubActionError
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var IOInterface
|
||||||
|
*/
|
||||||
|
protected $io;
|
||||||
|
|
||||||
|
public function __construct(IOInterface $io)
|
||||||
|
{
|
||||||
|
$this->io = $io;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @param null|string $file
|
||||||
|
* @param null|int $line
|
||||||
|
*/
|
||||||
|
public function emit($message, $file = null, $line = null)
|
||||||
|
{
|
||||||
|
if (getenv('GITHUB_ACTIONS') && !getenv('COMPOSER_TESTS_ARE_RUNNING')) {
|
||||||
|
// newlines need to be encoded
|
||||||
|
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
|
||||||
|
$message = str_replace("\n", '%0A', $message);
|
||||||
|
|
||||||
|
if ($file && $line) {
|
||||||
|
$this->io->write("::error file=". $file .",line=". $line ."::". $message);
|
||||||
|
} elseif ($file) {
|
||||||
|
$this->io->write("::error file=". $file ."::". $message);
|
||||||
|
} else {
|
||||||
|
$this->io->write("::error ::". $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@
|
||||||
namespace Composer;
|
namespace Composer;
|
||||||
|
|
||||||
use Composer\Autoload\AutoloadGenerator;
|
use Composer\Autoload\AutoloadGenerator;
|
||||||
|
use Composer\Console\GithubActionError;
|
||||||
use Composer\DependencyResolver\DefaultPolicy;
|
use Composer\DependencyResolver\DefaultPolicy;
|
||||||
use Composer\DependencyResolver\LocalRepoTransaction;
|
use Composer\DependencyResolver\LocalRepoTransaction;
|
||||||
use Composer\DependencyResolver\LockTransaction;
|
use Composer\DependencyResolver\LockTransaction;
|
||||||
|
@ -412,12 +413,18 @@ class Installer
|
||||||
$ruleSetSize = $solver->getRuleSetSize();
|
$ruleSetSize = $solver->getRuleSetSize();
|
||||||
$solver = null;
|
$solver = null;
|
||||||
} catch (SolverProblemsException $e) {
|
} catch (SolverProblemsException $e) {
|
||||||
$this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>', true, IOInterface::QUIET);
|
$err = 'Your requirements could not be resolved to an installable set of packages.';
|
||||||
$this->io->writeError($e->getPrettyString($repositorySet, $request, $pool, $this->io->isVerbose()));
|
$prettyProblem = $e->getPrettyString($repositorySet, $request, $pool, $this->io->isVerbose());
|
||||||
|
|
||||||
|
$this->io->writeError('<error>'. $err .'</error>', true, IOInterface::QUIET);
|
||||||
|
$this->io->writeError($prettyProblem);
|
||||||
if (!$this->devMode) {
|
if (!$this->devMode) {
|
||||||
$this->io->writeError('<warning>Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.</warning>', true, IOInterface::QUIET);
|
$this->io->writeError('<warning>Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.</warning>', true, IOInterface::QUIET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ghe = new GithubActionError($this->io);
|
||||||
|
$ghe->emit($err."\n".$prettyProblem);
|
||||||
|
|
||||||
return max(1, $e->getCode());
|
return max(1, $e->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,10 +578,16 @@ class Installer
|
||||||
$nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
|
$nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
|
||||||
$solver = null;
|
$solver = null;
|
||||||
} catch (SolverProblemsException $e) {
|
} catch (SolverProblemsException $e) {
|
||||||
$this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET);
|
$err = 'Unable to find a compatible set of packages based on your non-dev requirements alone.';
|
||||||
|
$prettyProblem = $e->getPrettyString($repositorySet, $request, $pool, $this->io->isVerbose(), true);
|
||||||
|
|
||||||
|
$this->io->writeError('<error>'. $err .'</error>', true, IOInterface::QUIET);
|
||||||
$this->io->writeError('Your requirements can be resolved successfully when require-dev packages are present.');
|
$this->io->writeError('Your requirements can be resolved successfully when require-dev packages are present.');
|
||||||
$this->io->writeError('You may need to move packages from require-dev or some of their dependencies to require.');
|
$this->io->writeError('You may need to move packages from require-dev or some of their dependencies to require.');
|
||||||
$this->io->writeError($e->getPrettyString($repositorySet, $request, $pool, $this->io->isVerbose(), true));
|
$this->io->writeError($prettyProblem);
|
||||||
|
|
||||||
|
$ghe = new GithubActionError($this->io);
|
||||||
|
$ghe->emit($err."\n".$prettyProblem);
|
||||||
|
|
||||||
return max(1, $e->getCode());
|
return max(1, $e->getCode());
|
||||||
}
|
}
|
||||||
|
@ -637,8 +650,14 @@ class Installer
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} catch (SolverProblemsException $e) {
|
} catch (SolverProblemsException $e) {
|
||||||
$this->io->writeError('<error>Your lock file does not contain a compatible set of packages. Please run composer update.</error>', true, IOInterface::QUIET);
|
$err = 'Your lock file does not contain a compatible set of packages. Please run composer update.';
|
||||||
$this->io->writeError($e->getPrettyString($repositorySet, $request, $pool, $this->io->isVerbose()));
|
$prettyProblem = $e->getPrettyString($repositorySet, $request, $pool, $this->io->isVerbose());
|
||||||
|
|
||||||
|
$this->io->writeError('<error>'. $err .'</error>', true, IOInterface::QUIET);
|
||||||
|
$this->io->writeError($prettyProblem);
|
||||||
|
|
||||||
|
$ghe = new GithubActionError($this->io);
|
||||||
|
$ghe->emit($err."\n".$prettyProblem);
|
||||||
|
|
||||||
return max(1, $e->getCode());
|
return max(1, $e->getCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue