2021-04-26 11:45:20 +03:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @package Gantry5
|
|
|
|
|
* @author RocketTheme http://www.rockettheme.com
|
2022-01-19 11:33:25 +02:00
|
|
|
* @copyright Copyright (C) 2007 - 2022 RocketTheme, LLC
|
2021-04-26 11:45:20 +03:00
|
|
|
* @license Dual License: MIT or GNU/GPLv2 and later
|
|
|
|
|
*
|
|
|
|
|
* http://opensource.org/licenses/MIT
|
|
|
|
|
* http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
*
|
|
|
|
|
* Gantry Framework code that extends GPL code is considered GNU/GPLv2 and later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
setlocale(LC_ALL, ['en_GB.utf8', 'en_GB']);
|
|
|
|
|
date_default_timezone_set('America/Denver');
|
2021-04-27 11:01:12 +03:00
|
|
|
chdir(__DIR__ . '/builder');
|
2021-04-26 11:45:20 +03:00
|
|
|
|
|
|
|
|
$hasVersion = false;
|
2021-04-27 12:37:56 +03:00
|
|
|
$isProd = true;
|
2022-01-19 11:48:46 +02:00
|
|
|
array_shift($argv);
|
2021-04-26 11:45:20 +03:00
|
|
|
foreach ($argv as $arg) {
|
2021-04-27 12:37:56 +03:00
|
|
|
if (strpos($arg, '-') === 0) {
|
|
|
|
|
if (strpos($arg, '-Dxml.version=') === 0) {
|
|
|
|
|
$hasVersion = true;
|
|
|
|
|
}
|
|
|
|
|
} elseif (strpos($arg, 'dev') !== false) {
|
|
|
|
|
$isProd = false;
|
2021-04-26 11:45:20 +03:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 12:37:56 +03:00
|
|
|
|
|
|
|
|
$base = dirname(__DIR__);
|
2021-04-26 11:45:20 +03:00
|
|
|
if (false === $hasVersion) {
|
2023-05-22 23:56:37 +02:00
|
|
|
$file = fopen("{$base}/CHANGELOG.md",'rb');
|
2021-09-23 15:19:46 +03:00
|
|
|
if (preg_match('/^# (\d\.\d+.\d+(-[a-z0-9.]+)?)\s*$/i', fgets($file), $matches) !== 1) {
|
|
|
|
|
echo 'First line of CHANGELOG.md has wrong Gantry version format, aborting';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
$version = $matches[1];
|
|
|
|
|
|
2021-04-27 12:37:56 +03:00
|
|
|
if (false === $isProd && is_file("{$base}/.git/HEAD")) {
|
|
|
|
|
$head = preg_replace('!^ref: (\S+)\s+$!m', '\\1', file_get_contents("{$base}/.git/HEAD"));
|
|
|
|
|
$branch = basename($head);
|
2021-09-27 15:04:15 +03:00
|
|
|
$commit = is_file("{$base}/.git/{$head}") ? trim(file_get_contents("{$base}/.git/{$head}")) : '';
|
|
|
|
|
$commitShort = substr($commit, 0, 9);
|
2021-04-27 12:37:56 +03:00
|
|
|
if ($branch !== 'develop') {
|
2021-09-23 15:19:46 +03:00
|
|
|
$branch = 'dev-' . $branch;
|
2021-04-27 12:37:56 +03:00
|
|
|
}
|
2021-09-23 15:19:46 +03:00
|
|
|
if (!strpos($version, '-dev')) {
|
|
|
|
|
$version .= '-dev';
|
|
|
|
|
}
|
2021-09-27 15:04:15 +03:00
|
|
|
$version .= '-' . $commitShort;
|
2021-04-27 12:37:56 +03:00
|
|
|
|
|
|
|
|
$argv[] = '-Dstr.fileversion=_' . $branch;
|
2023-05-22 23:56:37 +02:00
|
|
|
$argv[] = '-Dcommit=' . $commit;
|
2021-04-26 11:45:20 +03:00
|
|
|
}
|
2023-05-22 23:56:37 +02:00
|
|
|
|
|
|
|
|
$argv[] = '-Dxml.version=' . $version;
|
2021-04-26 11:45:20 +03:00
|
|
|
}
|
|
|
|
|
|
2022-01-19 11:48:46 +02:00
|
|
|
$command = 'vendor/bin/phing ' . implode(' ', $argv);
|
|
|
|
|
if (false === system($command, $result) || $result) {
|
|
|
|
|
throw new \RuntimeException('Failed to run build script');
|
2023-04-04 01:09:33 +02:00
|
|
|
}
|