Commit 8a6d0700 authored by Aaron Wells's avatar Aaron Wells
Browse files

Add support for checking plugin versions as well

Change-Id: I73b5f89f75770ebcdd7314d59df3d2d8942aaf82
parent bec598d9
......@@ -19,19 +19,49 @@
* and XX is a sequential integer starting with 0.
*
* In a stable branch, the YYYYMMDD is frozen and only the XX should increment.
*
* See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy#Version_bumps_and_database_upgrades
*/
error_reporting(0);
define('INTERNAL', 1);
require('htdocs/lib/version.php');
$newconfig = get_mahara_version('HEAD');
$oldconfig = get_mahara_version('HEAD~');
$error = false;
validate_version('htdocs/lib/version.php', 'htdocs/lib/db/upgrade.php');
// Check versions of plugins
require_once('htdocs/lib/mahara.php');
foreach (plugin_types() as $type) {
// Find installed instances
$dirhandle = opendir("htdocs/{$type}");
while (false != ($plugin = readdir($dirhandle))) {
if ($plugin[0] == '.' || $plugin == 'CSV') {
continue;
}
$dir = "htdocs/{$type}/{$plugin}";
if (!is_dir($dir)) {
continue;
}
validate_version("$dir/version.php", "$dir/db/upgrade.php");
}
if ($type == 'artefact') {
}
}
function get_mahara_version($gitversion) {
exec("git show {$gitversion}:htdocs/lib/version.php", $lines, $returnval);
/**
* Find out the version number in a particular version.php file at a particular git revision
* @param string $gitversion
* @param string $pathtofile
*/
function get_mahara_version($gitrevision, $pathtofile) {
global $error;
exec("git show {$gitrevision}:{$pathtofile}", $lines, $returnval);
if ($returnval !== 0) {
echo "ERROR (test/versioncheck.php): Couldn't locate version.php file in {$gitversion}.";
exit(1);
$error = true;
}
array_shift($lines);
......@@ -39,49 +69,54 @@ function get_mahara_version($gitversion) {
return $config;
}
if ($oldconfig->version != $newconfig->version) {
echo "Bumping lib/version.php...\n";
echo "Old version: {$oldconfig->version}\n";
echo "New version: {$newconfig->version}\n";
}
if ($newconfig->version < $oldconfig->version) {
echo "(test/versioncheck.php) ERROR: Version number in lib/version.php has decreased!\n";
exit(2);
}
function validate_version($versionfile, $upgradefile) {
$newconfig = get_mahara_version('HEAD', $versionfile);
$oldconfig = get_mahara_version('HEAD~', $versionfile);
// Determine if we're on a stable branch or not.
if (substr($newconfig->release, -3) == 'dev') {
$stablebranch = false;
}
else {
$stablebranch = true;
}
if ($oldconfig->version != $newconfig->version) {
echo "Bumping {$versionfile}...\n";
echo "Old version: {$oldconfig->version}\n";
echo "New version: {$newconfig->version}\n";
}
if (strlen($newconfig->version) != 10) {
echo "(test/versioncheck.php) ERROR: Version number in lib/version.php should be exactly 10 digits.\n";
exit(4);
}
if ($newconfig->version < $oldconfig->version) {
echo "(test/versioncheck.php) ERROR: Version number in {$versionfile} has decreased!\n";
$error = true;
}
if ($stablebranch && substr($newconfig->version, 0, 8) != substr($oldconfig->version, 0, 8)) {
echo "(test/versioncheck.php) ERROR: Version number in lib/version.php has gone up too much for a stable branch!\n";
exit(3);
}
// Determine if we're on a stable branch or not.
if (substr($newconfig->release, -3) == 'dev') {
$stablebranch = false;
}
else {
$stablebranch = true;
}
// If they added new code to lib/db/upgrade.php, make sure the last block in it matches the new version number
if ($newconfig->version > $oldconfig->version) {
$p = popen('git show -- htdocs/lib/db/upgrade.php', 'r');
$upgradeversion = false;
while (!feof($p)) {
$buffer = fgets($p);
if (1 == preg_match('#\$oldversion.*\b(\d{10})\b#', $buffer, $matches)) {
$upgradeversion = $matches[1];
echo "New lib/db/upgrade.php: {$upgradeversion}\n";
}
if (strlen($newconfig->version) != 10) {
echo "(test/versioncheck.php) ERROR: Version number in {$versionfile} should be exactly 10 digits.\n";
$error = true;
}
else if ($stablebranch && substr($newconfig->version, 0, 8) > substr($oldconfig->version, 0, 8)) {
echo "(test/versioncheck.php) ERROR: Version number in {$versionfile} has gone up too much for a stable branch!\n";
$error = true;
}
pclose($p);
if ($upgradeversion != $newconfig->version) {
echo "(test/versioncheck.php) ERROR: Version in lib/version.php should match version of last new section in lib/db/upgrade.php\n";
die(5);
// If they added new code to lib/db/upgrade.php, make sure the last block in it matches the new version number
if ($newconfig->version != $oldconfig->version) {
$p = popen("git show -- {$upgradefile}", 'r');
$upgradeversion = false;
while (!feof($p)) {
$buffer = fgets($p);
if (1 == preg_match('#\$oldversion.*\b(\d{10})\b#', $buffer, $matches)) {
$upgradeversion = $matches[1];
echo "New {$upgradefile}: {$upgradeversion}\n";
}
}
pclose($p);
if ($upgradeversion !== false && $upgradeversion != $newconfig->version) {
echo "(test/versioncheck.php) ERROR: Version in {$versionfile} should match version of last new section in {$upgradefile}\n";
$error = true;
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment