Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 19, 2022
1 parent 51ba29e commit f40f184
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
4 changes: 3 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@

<copy file="${basedir}/phpunit.xsd" tofile="${basedir}/build/tmp/phar/phpunit.xsd"/>

<exec executable="${basedir}/build/scripts/phar-manifest.php" output="${basedir}/build/tmp/phar/manifest.txt" failonerror="true"/>
<exec executable="${basedir}/build/scripts/phar-manifest.php" failonerror="true">
<arg path="${basedir}/build/tmp/phar/manifest.txt"/>
</exec>

<copy file="${basedir}/vendor/phpunit/php-code-coverage/LICENSE" tofile="${basedir}/build/tmp/phar/php-code-coverage/LICENSE"/>
<copy todir="${basedir}/build/tmp/phar/php-code-coverage">
Expand Down
64 changes: 48 additions & 16 deletions build/scripts/phar-manifest.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
print 'phpunit/phpunit: ';
if ($argc !== 2) {
fwrite(
STDERR,
sprintf(
'%s /path/to/manifest.txt' . PHP_EOL,
$argv[0]
)
);

$tag = @\exec('git describe --tags 2>&1');

if (\strpos($tag, '-') === false && \strpos($tag, 'No names found') === false) {
print $tag;
} else {
$branch = @\exec('git rev-parse --abbrev-ref HEAD');
$hash = @\exec('git log -1 --format="%H"');
print $branch . '@' . $hash;
exit(1);
}

print "\n";
$dependencies = dependencies();
$version = version();

manifest($argv[1], $version, $dependencies);

function manifest(string $outputFilename, string $version, array $dependencies): void
{
$buffer = 'phpunit/phpunit: ' . $version . "\n";

$lock = \json_decode(\file_get_contents(__DIR__ . '/../../composer.lock'));
foreach ($dependencies as $dependency) {
$buffer .= $dependency['name'] . ': ' . $dependency['version'];

foreach ($lock->packages as $package) {
print $package->name . ': ' . $package->version;
if (!preg_match('/^[v= ]*(([0-9]+)(\\.([0-9]+)(\\.([0-9]+)(-([0-9]+))?(-?([a-zA-Z-+][a-zA-Z0-9.\\-:]*)?)?)?)?)$/', $dependency['version'])) {
$buffer .= '@' . $dependency['source']['reference'];
}

if (!\preg_match('/^[v= ]*(([0-9]+)(\\.([0-9]+)(\\.([0-9]+)(-([0-9]+))?(-?([a-zA-Z-+][a-zA-Z0-9\\.\\-:]*)?)?)?)?)$/', $package->version)) {
print '@' . $package->source->reference;
$buffer .= "\n";
}

print "\n";
file_put_contents($outputFilename, $buffer);
}

function dependencies(): array
{
return json_decode(
file_get_contents(
__DIR__ . '/../../composer.lock'
),
true
)['packages'];
}

function version(): string
{
$tag = @exec('git describe --tags 2>&1');

if (strpos($tag, '-') === false && strpos($tag, 'No names found') === false) {
return $tag;
}

$branch = @exec('git rev-parse --abbrev-ref HEAD');
$hash = @exec('git log -1 --format="%H"');

return $branch . '@' . $hash;
}

0 comments on commit f40f184

Please sign in to comment.