Files
gantry5/bin/build

64 lines
2.0 KiB
Plaintext
Raw Permalink Normal View History

#!/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
* @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');
$hasVersion = false;
2021-04-27 12:37:56 +03:00
$isProd = true;
2022-01-19 11:48:46 +02:00
array_shift($argv);
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-27 12:37:56 +03:00
$base = dirname(__DIR__);
if (false === $hasVersion) {
$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);
$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';
}
$version .= '-' . $commitShort;
2021-04-27 12:37:56 +03:00
$argv[] = '-Dstr.fileversion=_' . $branch;
$argv[] = '-Dcommit=' . $commit;
}
$argv[] = '-Dxml.version=' . $version;
}
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
}