|
1 | 1 | #!/usr/bin/env php
|
2 | 2 | <?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 | + ); |
4 | 11 |
|
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); |
13 | 13 | }
|
14 | 14 |
|
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"; |
16 | 23 |
|
17 |
| -$lock = \json_decode(\file_get_contents(__DIR__ . '/../../composer.lock')); |
| 24 | + foreach ($dependencies as $dependency) { |
| 25 | + $buffer .= $dependency['name'] . ': ' . $dependency['version']; |
18 | 26 |
|
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 | + } |
21 | 30 |
|
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"; |
24 | 32 | }
|
25 | 33 |
|
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; |
27 | 59 | }
|
0 commit comments