-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathupdate.php
101 lines (79 loc) · 2.4 KB
/
update.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
<?php
$php = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'php' : '/usr/bin/php8.2-cli';
exec($php . ' composer.phar self-update');
exec($php . ' composer.phar update');
include 'vendor/autoload.php';
if ('php' != $php)
{
// get the latest
$repo = new \Gitonomy\Git\Repository(__DIR__);
$repo->run('checkout', ['main']);
$repo->run('pull');
}
// download the yaml file and save it
$url = 'https://api.cc.email/v3/swagger.yaml';
$yaml = file_get_contents($url);
if (empty($yaml))
{
echo "Error reading {$url}\n";
exit;
}
$file = __DIR__ . '/yaml/swagger.yaml';
echo "Update {$file}\n";
file_put_contents($file, $yaml);
// assume it has changed and run Generator
$yaml = \Symfony\Component\Yaml\Yaml::parseFile($file);
$generator = new \Tool\Generator();
$generator->deleteClasses(strtoupper($yaml['basePath']));
$generator->deleteDefinitions();
$generator->makeDefinitions($yaml['definitions']);
$generator->makeClasses($yaml['basePath'], $yaml['paths']);
echo "Generated files\n";
// don't update git if running under Windows
if ('php' == $php)
{
echo "running under Windows, exiting\n";
exit;
}
// style the code
exec($php . ' vendor\bin\php-cs-fixer fix -vv --allow-risky=yes');
echo "Cleaned code\n";
// Stage all changed files
$repo->run('add', ['.']);
// if any files are staged, then make new version, else bail as we are done
$output = $repo->run('status', ['--porcelain']);
echo "Git output {$output}\n";
if (! strlen(trim($output)))
{
echo "No changes found, exiting\n";
exit;
}
// figure out the next version number
$tags = $repo->getReferences()->getTags();
$highest = 0;
$proposed = (int)date('y') * 10000 + (int)date('n') * 100;
foreach ($tags as $tag)
{
$parts = explode('.', trim($tag->getName(), 'V'));
$number = 0;
foreach ($parts as $index => $part)
{
$number = $number * 100 + (int)$part;
}
$highest = max($number, $highest);
}
if ($highest >= $proposed)
{
$proposed = $highest + 1;
}
$proposed = "{$proposed}";
$version = 'V' . substr($proposed, 0, 2) . '.' . substr($proposed, 2, 2) . '.' . substr($proposed, 4, 2);
$version = str_replace('.0', '.', $version);
echo "Proposed version: {$version}\n";
// commit and tag it with version number
$date = date('Y-m-d');
$repo->run('commit', ['-m', "{$version} - {$date}"]);
$repo->run('tag', ['-a', $version, '-m', "Auto generated on {$date}"]);
// push and publish
$repo->run('push', ['--follow-tags']);
echo "Updated to {$version}\n";