This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-constants.php
executable file
·228 lines (199 loc) · 6.82 KB
/
update-constants.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env php
<?php
/**
* This file is part of phpcq/travis-configuration-check.
*
* (c) 2014 Christian Schiffler, Tristan Lins
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package phpcq/travis-configuration-check
* @author Christian Schiffler <[email protected]>
* @author Tristan Lins <[email protected]>
* @copyright Christian Schiffler <[email protected]>, Tristan Lins <[email protected]>
* @link https://github.com/phpcq/travis-configuration-check
* @license https://github.com/phpcq/travis-configuration-check/blob/master/LICENSE MIT
* @filesource
*/
error_reporting(E_ALL);
/**
* Try to load the autoloader from the given file.
*
* @param string $file The file to include.
*
* @return bool|\Composer\Autoload\ClassLoader
*
* @codingStandardsIgnoreStart
*/
function includeIfExists($file)
{
return file_exists($file) ? include $file : false;
}
if ((!$loader = includeIfExists(__DIR__.'/vendor/autoload.php'))
&& (!$loader = includeIfExists(__DIR__.'/../../autoload.php'))
) {
echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
'php composer.phar install'.PHP_EOL;
exit(1);
}
set_error_handler(
function ($errno, $errstr, $errfile, $errline) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
);
// @codingStandardsIgnoreEnd
/**
* Download the given url and return as string.
*
* @param string $url The url to download.
*
* @return null|string
*
* @throws \Exception When a redirect location could not be retrieved.
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*
* @codingStandardsIgnoreStart
*/
function fgetDownload($url)
{
$return = file_get_contents($url);
// $http_response_header becomes available by magic when issuing the fopen() call above.
$headers = $http_response_header;
$firstHeaderLine = $headers[0];
$firstHeaderLineParts = explode(' ', $firstHeaderLine);
if ($firstHeaderLineParts[1] == 301 || $firstHeaderLineParts[1] == 302) {
foreach ($headers as $header) {
$matches = array();
preg_match('/^Location:(.*?)$/', $header, $matches);
$url = trim(array_pop($matches));
return fgetDownload($url);
}
throw new \Exception('Can\'t get the redirect location');
}
return $return;
}
// @codingStandardsIgnoreEnd
use PhpCodeQuality\TravisConfigurationCheck\TravisEnvironmentInformation;
use Symfony\Component\Process\Process;
echo "Checking information for travis-ci...\n";
$travisBuildSetup = fgetDownload(
'https://raw.githubusercontent.com/travis-ci/docs-travis-ci-com/gh-pages/user/ci-environment.md'
);
$phpSection = substr($travisBuildSetup, (strpos($travisBuildSetup, '## PHP VM images') + 16));
$phpSection = substr($phpSection, 0, strpos($phpSection, "\n## ", 5) ?: 10);
$sections = array();
$pos = strpos($phpSection, '### ');
while ($pos !== false) {
$eol = strpos($phpSection, "\n", $pos);
$title = strtolower(trim(substr($phpSection, ($pos + 4), ($eol - $pos - 4))));
$pos = strpos($phpSection, '### ', $eol);
$sections[$title] = trim(substr($phpSection, $eol, ($pos - $eol)));
}
preg_match_all("!^\*\s([0-9.]*)\n!m", $sections['php versions'], $matches, PREG_PATTERN_ORDER);
$time = date('D Y-m-d H-n-s');
$versions = implode(',', $matches[1]);
$extensions = implode(',', array_filter(array_map(
function ($val) {
// skip subsection.
if (strpos($val, '[') !== false) {
return null;
}
return strtolower(trim($val));
},
explode("\n", $sections['extensions'])
)));
// @codingStandardsIgnoreStart
echo "Checking versions for php.net...\n";
$content =
substr(
file_get_contents(
'https://raw.githubusercontent.com/php/web-php/master/include/version.inc'
),
5
);
eval($content);
$branches = array();
foreach ($GLOBALS['RELEASES'] as $major => $releases) {
foreach ($releases as $version => $release) {
if (empty($release['eol'])) {
// This branch isn't EOL: add it to our array.
$branches[] = implode('.', array_slice(explode('.', $version), 0, 2));
}
}
}
sort($branches);
$activePHPVersions = implode(',', $branches);
// @codingStandardsIgnoreEnd
if (($activePHPVersions == TravisEnvironmentInformation::PHP_VERSIONS_MAINTAINED)
&& ($versions == TravisEnvironmentInformation::PHP_VERSIONS)
&& ($extensions == TravisEnvironmentInformation::PHP_EXTENSIONS)
) {
echo "No changes at travis-ci or php.net found - TravisEnvironmentInformation.php not updated.\n";
return;
}
file_put_contents(
__DIR__ . '/src/TravisEnvironmentInformation.php',
<<<EOF
<?php
/*
* This file is auto generated, DO NOT MODIFY!!!!!!
*
* Run update-travis-constants.php from the project root to update the information.
*
* Last time generated: $time
*
* This file is part of phpcq/travis-configuration-check.
*
* (c) 2014 Christian Schiffler, Tristan Lins
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package phpcq/travis-configuration-check
* @author Christian Schiffler <[email protected]>
* @author Tristan Lins <[email protected]>
* @copyright Christian Schiffler <[email protected]>, Tristan Lins <[email protected]>
* @link https://github.com/phpcq/travis-configuration-check
* @license https://github.com/phpcq/travis-configuration-check/blob/master/LICENSE MIT
* @filesource
*/
namespace PhpCodeQuality\TravisConfigurationCheck;
/**
* Simple container to keep hold of the versions of PHP in travis-ci and the active extensions.
*
* Auto generated via update-travis-constants.php.
*
* @author Christian Schiffler <[email protected]>
*/
interface TravisEnvironmentInformation
{
/**
* The PHP versions currently maintained by php.org.
*/
const PHP_VERSIONS_MAINTAINED = '$activePHPVersions';
/**
* The PHP versions in use at travis-ci.
*/
const PHP_VERSIONS = '$versions';
/**
* The PHP extensions available at travis-ci.
* @codingStandardsIgnoreStart
*/
const PHP_EXTENSIONS = '$extensions';
// @codingStandardsIgnoreEnd
}
EOF
);
echo "TravisEnvironmentInformation.php has been updated with the latest information.\n";
echo "Please commit the new version to git and tag a release.\n";
$process = new Process('git diff');
$process->run();
echo $process->getOutput();
exit(1);