Repository navigation
Expand file tree
/
Copy pathsymfony-docker-pin.php
More file actions
executable file
·61 lines (49 loc) · 1.75 KB
/
Copy pathsymfony-docker-pin.php
File metadata and controls
executable file
·61 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env php
<?php
declare(strict_types=1);
// CLI front-end to SymfonyDockerPin, used by .github/workflows/symfony-docker-bump.yml.
//
// ref print the pinned symfony-docker commit
// pin <sha> repin the scaffold to <sha>
// filter read upstream paths on stdin, print those the scaffold copies
use ApiPlatform\Installer\Scaffold\SymfonyDockerPin;
require_once \dirname(__DIR__).'/vendor/autoload.php';
$scaffold = \dirname(__DIR__).'/src/Scaffold/SymfonyScaffold.php';
function fail(string $message): never
{
fwrite(\STDERR, $message."\n");
exit(1);
}
function read_source(string $path): string
{
$contents = file_get_contents($path);
if (false === $contents) {
fail(sprintf('Could not read %s.', $path));
}
return $contents;
}
try {
switch ($argv[1] ?? '') {
case 'ref':
fwrite(\STDOUT, SymfonyDockerPin::read(read_source($scaffold))."\n");
break;
case 'pin':
$sha = $argv[2] ?? fail('Usage: symfony-docker-pin.php pin <sha>');
$patched = SymfonyDockerPin::replace(read_source($scaffold), $sha);
if (false === file_put_contents($scaffold, $patched)) {
fail(sprintf('Could not write %s.', $scaffold));
}
break;
case 'filter':
$stdin = stream_get_contents(\STDIN);
$paths = preg_split('/\R/', false === $stdin ? '' : trim($stdin), -1, \PREG_SPLIT_NO_EMPTY) ?: [];
foreach (SymfonyDockerPin::copiedPaths($paths) as $path) {
fwrite(\STDOUT, $path."\n");
}
break;
default:
fail('Usage: symfony-docker-pin.php <ref|pin <sha>|filter>');
}
} catch (Throwable $e) {
fail($e->getMessage());
}