-
Notifications
You must be signed in to change notification settings - Fork 23
/
version.php
executable file
·40 lines (32 loc) · 1.08 KB
/
version.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
<?php
global $availableVersions;
$availableVersions = getAvailableVersions();
$newestVersion = getNewestVersion();
global $currentVersion;
$currentVersion = getCurrentVersion();
define( 'DOCS_VERSION', $currentVersion );
function getAvailableVersions() {
$commandBranches = 'git branch --list "*source*" -r --no-color';
$branches = [];
$retValue = 0;
exec($commandBranches, $branches, $retValue);
if ($retValue != 0) {
die("Could not fetch branch names. Is git installed? Output was: \n".implode("\n", $output));
}
return array_map('getVersionFromBranchName', $branches);
}
function getNewestVersion() {
$commandHead = 'git branch --list "*source*" -r --no-color --points-at HEAD';
return getVersionFromBranchName(exec($commandHead));
}
function getCurrentVersion() {
$commandHead = 'git rev-parse --abbrev-ref HEAD';
return getVersionFromBranchName(exec($commandHead));
}
function getVersionFromBranchName($branch) {
$parts = explode('/', $branch);
$source = array_pop($parts);
$parts = explode('-', $branch);
$version = array_pop($parts);
return $version;
}