-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
build.php
117 lines (97 loc) · 3.6 KB
/
build.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
<?php
/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
chdir(__DIR__);
$currentBranch = 'master';
if (preg_match('/On branch ([^\n]+)\n/', shell_exec('git status'), $match)) {
$currentBranch = $match[1];
}
shell_exec('git fetch --all --tags --prune');
$remotes = explode("\n", trim(shell_exec('git remote')));
$tagsCommand = \count($remotes)
? 'git ls-remote --tags '.(\in_array('upstream', $remotes, true) ? 'upstream' : (\in_array('origin', $remotes, true) ? 'origin' : $remotes[0]))
: 'git tag';
$tags = array_map(function ($ref) {
$ref = explode('refs/tags/', $ref);
return $ref[1] ?? $ref[0];
}, array_filter(explode("\n", trim(shell_exec($tagsCommand))), function ($ref) {
return substr($ref, -3) !== '^{}';
}));
usort($tags, 'version_compare');
$tag = isset($argv[1]) && !\in_array($argv[1], ['last', 'latest']) ? $argv[1] : end($tags);
if (strtolower($tag) !== 'all') {
if (!\in_array($tag, $tags, true)) {
echo "Tag must be one of remote tags available:\n";
foreach ($tags as $_tag) {
echo " - $_tag\n";
}
echo "\"$tag\" does not match.\n";
exit(1);
}
$tags = [$tag];
}
function getPhpLevel($tag)
{
if (version_compare($tag, '2.0.0-dev', '<')) {
return '5.3.9';
}
if (version_compare($tag, '3.0.0-dev', '<')) {
return '7.1.8';
}
return '8.1.0';
}
foreach ($tags as $tag) {
$archive = "Carbon-$tag.zip";
if (isset($argv[2]) && $argv[2] === 'missing' && file_exists($archive)) {
continue;
}
$branch = "build-$tag";
shell_exec('git stash');
shell_exec("git branch -d $branch");
shell_exec("git checkout tags/$tag -b $branch");
$phpVersion = getPhpLevel($tag);
shell_exec("composer config platform.php $phpVersion");
shell_exec('composer remove friendsofphp/php-cs-fixer --dev');
shell_exec('composer remove kylekatarnls/multi-tester --dev');
shell_exec('composer remove phpmd/phpmd --dev');
shell_exec('composer remove phpstan/phpstan --dev');
shell_exec('composer remove phpunit/phpunit --dev');
shell_exec('composer remove squizlabs/php_codesniffer --dev');
shell_exec('composer update --no-interaction --no-dev --optimize-autoloader');
$zip = new ZipArchive();
$zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach (['src', 'vendor', 'Carbon', 'lazy'] as $directory) {
if (is_dir($directory)) {
$directory = realpath($directory);
$base = \dirname($directory);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($directory),
RecursiveIteratorIterator::LEAVES_ONLY,
);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$zip->addFile($filePath, substr($filePath, \strlen($base) + 1));
}
}
}
}
$autoload = 'autoload.php';
file_put_contents($autoload, "<?php\n\n/**\n * @version $tag\n */\n\nrequire __DIR__.'/vendor/autoload.php';\n");
$zip->addFile($autoload, $autoload);
$zip->close();
unlink($autoload);
shell_exec('git checkout .');
shell_exec("git checkout $currentBranch");
shell_exec("git branch -d $branch");
shell_exec('git stash pop');
shell_exec('composer config platform.php 8.1.0');
shell_exec('composer update --no-interaction');
}
exit(0);