Validate contents of VERSION file
This commit is contained in:
parent
dbf0a7be85
commit
bdc1a6e6a5
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Composer\Semver\Comparator;
|
use Composer\Semver\Comparator;
|
||||||
use Composer\Semver\Semver;
|
use Composer\Semver\Semver;
|
||||||
|
use Composer\Semver\VersionParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file does the following things:
|
* This file does the following things:
|
||||||
|
@ -13,9 +14,25 @@ use Composer\Semver\Semver;
|
||||||
* 4. Returns the current version, as HTML (stored in pair of invisible div tags)
|
* 4. Returns the current version, as HTML (stored in pair of invisible div tags)
|
||||||
*/
|
*/
|
||||||
class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract {
|
class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract {
|
||||||
|
|
||||||
public function versionNotify()
|
/**
|
||||||
{
|
* @var VersionParser
|
||||||
|
*/
|
||||||
|
private $versionParser;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->versionParser = new VersionParser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare data for update notifier widget
|
||||||
|
*
|
||||||
|
* Grabs the version from the VERSION file created by build.sh and compares
|
||||||
|
* it against the versions available from github using the semver code from
|
||||||
|
* the composer project.
|
||||||
|
*/
|
||||||
|
public function versionNotify() {
|
||||||
|
|
||||||
$config = Config::getConfig();
|
$config = Config::getConfig();
|
||||||
|
|
||||||
// retrieve and validate current and latest versions,
|
// retrieve and validate current and latest versions,
|
||||||
|
@ -24,15 +41,9 @@ class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract {
|
||||||
$link = Application_Model_Preference::GetLatestLink();
|
$link = Application_Model_Preference::GetLatestLink();
|
||||||
|
|
||||||
$isGitRelease = preg_match('/^[[:alnum:]]{7,}$/i', $current) === 1;
|
$isGitRelease = preg_match('/^[[:alnum:]]{7,}$/i', $current) === 1;
|
||||||
$currentParts = array();
|
$currentParts = $this->normalizeVersion($current, $isGitRelease);
|
||||||
if (!$isGitRelease) {
|
|
||||||
$currentParts = preg_split("/(\.|-)/", $current);
|
|
||||||
}
|
|
||||||
if (count($currentParts) < 3) {
|
|
||||||
$currentParts = array(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
$isPreRelease = $isGitRelease || array_key_exists(4, $currentParts);
|
$isPreRelease = $isGitRelease || array_key_exists(4, $currentParts);
|
||||||
|
|
||||||
// we are always interested in a major when we pre-release, hence the isPreRelease part
|
// we are always interested in a major when we pre-release, hence the isPreRelease part
|
||||||
$majorCandidates = SemVer::satisfiedBy($latest, sprintf('>=%1$s-stable', $currentParts[0] + ($isPreRelease ? 0 : 1)));
|
$majorCandidates = SemVer::satisfiedBy($latest, sprintf('>=%1$s-stable', $currentParts[0] + ($isPreRelease ? 0 : 1)));
|
||||||
$minorCandidates = SemVer::satisfiedBy($latest, sprintf('~%1$s.%2$s', $currentParts[0], $currentParts[1] + 1));
|
$minorCandidates = SemVer::satisfiedBy($latest, sprintf('~%1$s.%2$s', $currentParts[0], $currentParts[1] + 1));
|
||||||
|
@ -78,4 +89,23 @@ class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract {
|
||||||
. "<div id='version-icon' class='" . $class . "'></div>";
|
. "<div id='version-icon' class='" . $class . "'></div>";
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function normalizeVersion($version, $isGit) {
|
||||||
|
try {
|
||||||
|
$this->versionParser->normalize($version);
|
||||||
|
} catch(UnexpectedValueException $e) {
|
||||||
|
// recover by assuming an unknown version
|
||||||
|
$version= '0.0.0';
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = array();
|
||||||
|
if (!$isGit) {
|
||||||
|
$parts = preg_split("/(\.|-)/", $version);
|
||||||
|
}
|
||||||
|
if (count($parts) < 3) {
|
||||||
|
$parts = array(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $parts;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
9
build.sh
9
build.sh
|
@ -17,11 +17,12 @@ if [ "${git_build}" = "y" ]; then
|
||||||
echo ${git_version} > VERSION
|
echo ${git_version} > VERSION
|
||||||
else
|
else
|
||||||
# if no file was in tarball we create one letting the user know
|
# if no file was in tarball we create one letting the user know
|
||||||
# travis should release tarballs with a pre-written VERSION file
|
# if you run in to this you should grab an enriched tarball built
|
||||||
# at some stage
|
# by travis. It already contains the VERSION file and also bundles
|
||||||
|
# all the PHP you vendors files making the install much faster on
|
||||||
|
# your part.
|
||||||
if [ ! -f VERSION ]; then
|
if [ ! -f VERSION ]; then
|
||||||
folder_name=$(basename `pwd`)
|
echo "could not detect version for VERSION file" > VERSION
|
||||||
echo "tarball install from folder ${folder_name}" > VERSION
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue