From 545fc9df252cffe6fc9327e00df5fe19d03ab3bc Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 25 Apr 2016 15:14:00 -0700 Subject: [PATCH] tools/bin/scripts/set-version.php - Add helper script This is similar to the function `do_update` in `releaser`, except that : * It it doesn't care if you use the `$workdir/$version/export` directory structure or something else * It it doesn't care if you push directly to the canonical repo or use a pull-request --- tools/bin/scripts/set-version.php | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 tools/bin/scripts/set-version.php diff --git a/tools/bin/scripts/set-version.php b/tools/bin/scripts/set-version.php new file mode 100755 index 0000000000..ebc4a5d057 --- /dev/null +++ b/tools/bin/scripts/set-version.php @@ -0,0 +1,92 @@ +#!/usr/bin/env php +version_no; +if (!isVersionValid($oldVersion)) { + fatal("failed to read old version from \"xml/version.xml\"\n"); +} + +$newVersion = @$argv[1]; +if (!isVersionValid($newVersion)) { + fatal("failed to read new version\n"); +} + +switch (@$argv[2]) { + case '--commit': + $doCommit = 1; + break; + case '--no-commit': + $doCommit = 0; + break; + default: + fatal("Must specify --commit or --no-commit\n"); +} + +/* *********************************************************************** */ +/* Main */ + +echo "Updating from $oldVersion to $newVersion...\n"; + +updateFile("xml/version.xml", function ($content) use ($newVersion, $oldVersion) { + return str_replace($oldVersion, $newVersion, $content); +}); + +updateFile("sql/civicrm_generated.mysql", function ($content) use ($newVersion, $oldVersion) { + return str_replace($oldVersion, $newVersion, $content); +}); + +$sqlFile = "CRM/Upgrade/Incremental/sql/{$newVersion}.mysql.tpl"; +if (!file_exists($sqlFile)) { + echo "Create \"$sqlFile\"\n"; + file_put_contents($sqlFile, "{* file to handle db changes in $newVersion during upgrade *}\n"); +} + +if ($doCommit) { + $files = "xml/version.xml sql/civicrm_generated.mysql " . escapeshellarg($sqlFile); + passthru("git add $files"); + passthru("git commit $files -m " . escapeshellarg("Set version to $newVersion")); +} + +/* *********************************************************************** */ +/* Helper functions */ + +function updateFile($file, $callback) { + if (!file_exists($file)) { + die("File does not exist: $file\n"); + } + echo "Update \"$file\"\n"; + $content = file_get_contents($file); + $content = $callback($content); + file_put_contents($file, $content); +} + +function isVersionValid($v) { + return $v && preg_match('/^[0-9a-z\.\-]+$/', $v); +} + +/** + * @param $error + */ +function fatal($error) { + echo $error; + echo "usage: set-version.php [--commit|--no-commit]\n"; + echo " With --commit, any changes will be committed automatically the current git branch.\n"; + echo " With --no-commit, any changes will be left uncommitted.\n"; + exit(1); +} -- 2.25.1