-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-readme.php
152 lines (129 loc) · 4.06 KB
/
update-readme.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
declare(strict_types=1);
$versions = ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4'];
\arsort($versions);
$dev = '8.5';
$latest = '8.4';
$variants = ['cli', 'fpm', 'zts'];
$extensions = [
// 'database' => ['mysql','pgsql'],
'code-coverage' => ['pcov'],
'extension' => [
// 'openswoole',
// 'roadrunner',
// 'frankenphp'
],
];
function terminalTemplate(string $phpVersion): string
{
return \sprintf(
'#### ![Terminal](resource/icons/terminal.svg) Pull & Run `PHP %s` image from the command line',
$phpVersion
) . \PHP_EOL;
}
function codeTemplate(string $phpVersion): string
{
return \sprintf('#### ![Code](resource/icons/code.svg) Use `PHP %s` image in Dockerfile', $phpVersion) . \PHP_EOL;
}
function versionTemplate(string $version, array $variants, array $extensions): string
{
$body = $code = $sh = [];
$code[] = \dockerFile($version);
$sh[] = \dockerPull($version);
$sh[] = \dockerRun($version);
foreach ($variants as $variant) {
$code[] = \dockerFile($version, $variant);
$sh[] = \dockerPull($version, $variant);
$sh[] = \dockerRun($version, $variant);
}
$body[] = \sprintf('### PHP %s', $version) . \PHP_EOL;
$body[] = \codeTemplate($version);
$body[] = \implode(\PHP_EOL, $code) . \PHP_EOL;
$body[] = \terminalTemplate($version);
$body[] = \implode(\PHP_EOL, $sh) . \PHP_EOL;
return \implode(\PHP_EOL, $body);
}
function dockerFile(string $phpVersion, ?string $variant = null): string
{
if ($variant === null) {
return \sprintf(
<<<EOT
```Dockerfile
FROM ghcr.io/ghostwriter/php:%s # %s-cli with additional development tools
```
EOT
,
$phpVersion,
$phpVersion,
);
}
return \sprintf(
<<<EOT
```Dockerfile
FROM ghcr.io/ghostwriter/php:%s-%s
```
EOT
,
$phpVersion,
$variant,
);
}
function dockerRun(string $phpVersion, ?string $variant = null): string
{
return \sprintf(
<<<EOT
```sh
docker run -it --rm -v \$PWD:/opt/app -w /opt/app ghcr.io/ghostwriter/php:%s%s vendor/bin/phpunit
```
EOT
,
$phpVersion,
$variant ? '-' . $variant : '',
);
}
function dockerPull(string $phpVersion, ?string $variant = null): string
{
return \sprintf(
<<<EOT
```sh
docker pull ghcr.io/ghostwriter/php:%s%s
```
EOT
,
$phpVersion,
$variant ? '-' . $variant : '',
);
}
function printREADME(array $versions, array $variants, array $extensions): string
{
$body[] = <<<EOT
# PHP for Docker [![Docker CI/CD](https://github.com/ghostwriter/php/actions/workflows/docker-build-push.yml/badge.svg)](https://github.com/ghostwriter/php/actions/workflows/docker-build-push.yml)
Development and Production-ready PHP Images for Docker
**Special thanks to [@mlocati](https://github.com/mlocati) for creating the fantastic [`mlocati/docker-php-extension-installer`](https://github.com/mlocati/docker-php-extension-installer) tool, which made all of this possible!**
EOT;
$body[] = \sprintf(
'%s> **Supported versions: %s**%s',
\PHP_EOL,
\implode(
', ',
\array_map(
static fn (string $version): string => \sprintf(
'[`%s`](#-use-php-%s-image-in-dockerfile)',
$version,
\str_replace('.', '', \mb_strtolower($version))
),
$versions
)
),
\PHP_EOL
);
foreach ($versions as $version) {
$body[] = \versionTemplate($version, $variants, $extensions) . \PHP_EOL;
}
return \implode(\PHP_EOL, $body);
}
$readme = \printREADME($versions, $variants, $extensions);
//die($readme);
\file_put_contents('README.md', $readme);
print 'README.md updated' . \PHP_EOL;
exit(0);