Projekt

Obecné

Profil

Stáhnout (2.71 KB) Statistiky
| Větev: | Revize:
1 cb15593b Cajova-Houba
<?php
2
3
chdir(__DIR__);
4
$currentBranch = 'master';
5
if (preg_match('/On branch ([^\n]+)\n/', shell_exec('git status'), $match)) {
6
    $currentBranch = $match[1];
7
}
8
shell_exec('git fetch --all --tags --prune');
9
$remotes = explode("\n", trim(shell_exec('git remote')));
10
$tagsCommand = count($remotes)
11
    ? 'git ls-remote --tags '.(in_array('upstream', $remotes) ? 'upstream' : (in_array('origin', $remotes) ? 'origin' : $remotes[0]))
12
    : 'git tag';
13
$tags = array_map(function ($ref) {
14
    $ref = explode('refs/tags/', $ref);
15
16
    return isset($ref[1]) ? $ref[1] : $ref[0];
17
}, array_filter(explode("\n", trim(shell_exec($tagsCommand))), function ($ref) {
18
    return substr($ref, -3) !== '^{}';
19
}));
20
usort($tags, 'version_compare');
21
22
$tag = isset($argv[1]) && !in_array($argv[1], array('last', 'latest')) ? $argv[1] : end($tags);
23
24
if (strtolower($tag) !== 'all') {
25
    if (!in_array($tag, $tags)) {
26
        echo "Tag must be one of remote tags available:\n";
27
        foreach ($tags as $_tag) {
28
            echo "  - $_tag\n";
29
        }
30
        echo "\"$tag\" does not match.\n";
31
32
        exit(1);
33
    }
34
35
    $tags = array($tag);
36
}
37
38
foreach ($tags as $tag) {
39
    $archive = "Carbon-$tag.zip";
40
    if (isset($argv[2]) && $argv[2] === 'missing' && file_exists($archive)) {
41
        continue;
42
    }
43
44
    $branch = "build-$tag";
45
    shell_exec('git stash');
46
    shell_exec("git branch -d $branch");
47
    shell_exec("git checkout tags/$tag -b $branch");
48
    shell_exec('composer config platform.php 5.3.9');
49
    shell_exec('composer update --no-interaction --no-dev --optimize-autoloader');
50
    $zip = new ZipArchive();
51
52
    $zip->open($archive, ZipArchive::CREATE | ZipArchive::OVERWRITE);
53
54
    foreach (array('src', 'vendor', 'Carbon') as $directory) {
55
        if (is_dir($directory)) {
56
            $directory = realpath($directory);
57
            $base = dirname($directory);
58
59
            $files = new RecursiveIteratorIterator(
60
                new RecursiveDirectoryIterator($directory),
61
                RecursiveIteratorIterator::LEAVES_ONLY
62
            );
63
64
            foreach ($files as $name => $file) {
65
                if (!$file->isDir()) {
66
                    $filePath = $file->getRealPath();
67
68
                    $zip->addFile($filePath, substr($filePath, strlen($base) + 1));
69
                }
70
            }
71
        }
72
    }
73
74
    $autoload = 'autoload.php';
75
    file_put_contents($autoload, "<?php\n\n/**\n * @version $tag\n */\n\nrequire __DIR__.'/vendor/autoload.php';\n");
76
    $zip->addFile($autoload, $autoload);
77
    $zip->close();
78
    unlink($autoload);
79
80
    shell_exec('git checkout .');
81
    shell_exec("git checkout $currentBranch");
82
    shell_exec("git branch -d $branch");
83
    shell_exec('git stash pop');
84
    shell_exec('composer update --no-interaction');
85
}
86
87
exit(0);