Skip to content

Commit f40f184

Browse files
Refactor
1 parent 51ba29e commit f40f184

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

build.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@
131131

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

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

136138
<copy file="${basedir}/vendor/phpunit/php-code-coverage/LICENSE" tofile="${basedir}/build/tmp/phar/php-code-coverage/LICENSE"/>
137139
<copy todir="${basedir}/build/tmp/phar/php-code-coverage">

build/scripts/phar-manifest.php

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,59 @@
11
#!/usr/bin/env php
22
<?php declare(strict_types=1);
3-
print 'phpunit/phpunit: ';
3+
if ($argc !== 2) {
4+
fwrite(
5+
STDERR,
6+
sprintf(
7+
'%s /path/to/manifest.txt' . PHP_EOL,
8+
$argv[0]
9+
)
10+
);
411

5-
$tag = @\exec('git describe --tags 2>&1');
6-
7-
if (\strpos($tag, '-') === false && \strpos($tag, 'No names found') === false) {
8-
print $tag;
9-
} else {
10-
$branch = @\exec('git rev-parse --abbrev-ref HEAD');
11-
$hash = @\exec('git log -1 --format="%H"');
12-
print $branch . '@' . $hash;
12+
exit(1);
1313
}
1414

15-
print "\n";
15+
$dependencies = dependencies();
16+
$version = version();
17+
18+
manifest($argv[1], $version, $dependencies);
19+
20+
function manifest(string $outputFilename, string $version, array $dependencies): void
21+
{
22+
$buffer = 'phpunit/phpunit: ' . $version . "\n";
1623

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

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

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

26-
print "\n";
34+
file_put_contents($outputFilename, $buffer);
35+
}
36+
37+
function dependencies(): array
38+
{
39+
return json_decode(
40+
file_get_contents(
41+
__DIR__ . '/../../composer.lock'
42+
),
43+
true
44+
)['packages'];
45+
}
46+
47+
function version(): string
48+
{
49+
$tag = @exec('git describe --tags 2>&1');
50+
51+
if (strpos($tag, '-') === false && strpos($tag, 'No names found') === false) {
52+
return $tag;
53+
}
54+
55+
$branch = @exec('git rev-parse --abbrev-ref HEAD');
56+
$hash = @exec('git log -1 --format="%H"');
57+
58+
return $branch . '@' . $hash;
2759
}

0 commit comments

Comments
 (0)