Permalink
Browse files

Stop hard-coding version information in constants.php

* setup.sh: Move main thread code after function declarations
* setup.sh: Store version information in cache
* constants.php: Use cached information to determine BETA vs PROD version, update base.php template
  • Loading branch information...
flodolo committed Nov 14, 2015
1 parent 4551662 commit b7dbe66c4837ef557a40c57ee5baab86dff2d353
Showing with 60 additions and 44 deletions.
  1. +1 −0 .gitignore
  2. +9 −4 app/inc/constants.php
  3. +48 −32 app/scripts/setup.sh
  4. +2 −8 app/views/templates/base.php
View
@@ -5,6 +5,7 @@ app/config/sources/*.txt
cache/*.cache
cache/lastdataupdate.txt
cache/stats_*.json
+cache/version.txt
composer.lock
composer.phar
logs/*.log
View
@@ -1,8 +1,5 @@
<?php
-// Bump this constant with each new release
-const VERSION = '3.10';
-
// Constants for the project
define('DATA_ROOT', realpath($server_config['root']) . '/');
define('HG', realpath($server_config['local_hg']) . '/');
@@ -21,6 +18,14 @@
define('CACHE_PATH', INSTALL_ROOT . 'cache/');
define('APP_SCHEME', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://');
+if (file_exists(CACHE_PATH . 'version.txt')) {
+ define('VERSION', file_get_contents(CACHE_PATH . 'version.txt'));
+ define('BETA_VERSION', strstr(VERSION, 'dev'));
+} else {
+ define('VERSION', 'unknown.dev');
+ define('BETA_VERSION', true);
+}
+
if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
define('CACHE_TIME', time() - filemtime(CACHE_PATH . 'lastdataupdate.txt'));
} else {
@@ -29,7 +34,7 @@
}
// Special modes for the app
-define('DEBUG', strstr(VERSION, 'dev') || isset($_GET['debug']));
+define('DEBUG', BETA_VERSION || isset($_GET['debug']));
define('LOCAL_DEV', isset($server_config['dev']) && $server_config['dev']);
// Set perf_check=true in config.ini to log page time generation and memory used while in DEBUG mode
View
@@ -23,38 +23,6 @@ function echogreen() {
echo -e "$GREEN$*$NORMAL"
}
-# Store current directory path to be able to call this script from anywhere
-DIR=$(dirname "$0")
-# Convert .ini file in bash variables
-eval $(cat $DIR/../config/config.ini | $DIR/ini_to_bash.py)
-
-# Generate sources (gaia versions, supported locales)
-echogreen "Generate list of locales and supported Gaia versions"
-$DIR/generate_sources $config
-
-# Check if we have sources
-echogreen "Checking if Transvision sources are available..."
-if ! $(ls $config/sources/*.txt &> /dev/null)
-then
- echored "CRITICAL ERROR: no sources available, aborting."
- echored "Check the value for l10nwebservice in your config.ini"
- exit
-fi
-
-# Create all bash variables
-source $DIR/bash_variables.sh
-
-# Make sure that we have the file structure ($folders is defined in bash_variables.sh)
-echogreen "Checking folders..."
-for folder in "${folders[@]}"
-do
- if [ ! -d $folder ]
- then
- echogreen "Creating folder: $folder"
- mkdir -p "$folder"
- fi
-done
-
function createSymlinks() {
branches=( trunk aurora beta release )
@@ -262,6 +230,54 @@ function initGaiaRepo () {
fi
}
+# Store current directory path to be able to call this script from anywhere
+DIR=$(dirname "$0")
+# Convert .ini file in bash variables
+eval $(cat $DIR/../config/config.ini | $DIR/ini_to_bash.py)
+
+# Generate sources (gaia versions, supported locales)
+echogreen "Generate list of locales and supported Gaia versions"
+$DIR/generate_sources $config
+
+# Check if we have sources
+echogreen "Checking if Transvision sources are available..."
+if ! $(ls $config/sources/*.txt &> /dev/null)
+then
+ echored "CRITICAL ERROR: no sources available, aborting."
+ echored "Check the value for l10nwebservice in your config.ini"
+ exit
+fi
+
+# Create all bash variables
+source $DIR/bash_variables.sh
+
+# Make sure that we have the file structure ($folders is defined in bash_variables.sh)
+echogreen "Checking folders..."
+for folder in "${folders[@]}"
+do
+ if [ ! -d $folder ]
+ then
+ echogreen "Creating folder: $folder"
+ mkdir -p "$folder"
+ fi
+done
+
+# Store version information in cache
+DEV_VERSION="dev"
+if [ ! -d ${install}/.git ]
+then
+ CURRENT_TIP="unknown"
+else
+ cd "${install}"
+ CURRENT_TIP=$(git rev-parse HEAD)
+ LATEST_TAG=$(git for-each-ref refs/tags --sort='-committerdate' --format='%(objectname)' --count=1)
+ if [ "${CURRENT_TIP}" = "${LATEST_TAG}" ]
+ then
+ DEV_VERSION=""
+ fi
+fi
+echo "${CURRENT_TIP:0:7}${DEV_VERSION}" > "${install}/cache/version.txt"
+
checkoutSilme
initDesktopSourceRepo "central"
@@ -55,13 +55,7 @@
</div>
';
-if (strpos(VERSION, 'dev') !== false) {
- $beta_version = true;
- $title_productname = 'Transvision Beta';
-} else {
- $beta_version = false;
- $title_productname = 'Transvision';
-}
+$title_productname = BETA_VERSION ? 'Transvision Beta' : 'Transvision';
if (file_exists(CACHE_PATH . 'lastdataupdate.txt')) {
$last_update = "<p>Data last updated: " .
@@ -96,7 +90,7 @@
<a href="" class="menu-button" id="links-top-button" title="Hide Transvision Menu"><span>menu</span></a>
</div>
<?php
- if ($beta_version) {
+ if (BETA_VERSION) {
print "<div id='beta-badge'><span>BETA VERSION</span></div>\n";
}
?>

0 comments on commit b7dbe66

Please sign in to comment.