From 9f2574e6fbb61dac4e1a4252dff30017685da5f0 Mon Sep 17 00:00:00 2001
From: Yassine Doghri <yassine@doghri.fr>
Date: Mon, 26 Oct 2020 11:48:17 +0000
Subject: [PATCH] feat: display castopod version in admin footer

add CP_VERSION constant in app/Config/Constants.php that updates upon release through
prepare-release.sh script

closes #68
---
 .releaserc.json             | 1 +
 app/Config/Constants.php    | 9 +++++++++
 app/Views/admin/_layout.php | 7 ++++---
 prepare-release.sh          | 3 +++
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/.releaserc.json b/.releaserc.json
index f0773bf10e..6507490fcf 100644
--- a/.releaserc.json
+++ b/.releaserc.json
@@ -19,6 +19,7 @@
       "@semantic-release/git",
       {
         "assets": [
+          "app/Config/Constants.php",
           "composer.json",
           "package.json",
           "package-lock.json",
diff --git a/app/Config/Constants.php b/app/Config/Constants.php
index f890af0e9f..c5ab4b2a91 100644
--- a/app/Config/Constants.php
+++ b/app/Config/Constants.php
@@ -1,5 +1,14 @@
 <?php
 
+//--------------------------------------------------------------------------
+// Castopod Version
+//--------------------------------------------------------------------------
+// The Castopod version number to display.
+//
+// NOTE: this constant is updated upon release with Continuous Integration.
+//
+defined('CP_VERSION') || define('CP_VERSION', '1.0.0-alpha.8');
+
 //--------------------------------------------------------------------
 // App Namespace
 //--------------------------------------------------------------------
diff --git a/app/Views/admin/_layout.php b/app/Views/admin/_layout.php
index cc46a59136..6a8d170667 100644
--- a/app/Views/admin/_layout.php
+++ b/app/Views/admin/_layout.php
@@ -41,10 +41,11 @@
         </div>
     </main>
     <footer class="px-2 py-2 mx-auto text-xs text-right holy-grail-footer">
-        <small><?= lang('Common.powered_by', [
+        <?= lang('Common.powered_by', [
             'castopod' =>
-                '<a class="underline hover:no-underline" href="https://castopod.org/" target="_blank" rel="noreferrer noopener">Castopod</a>',
-        ]) ?></small>
+                '<a class="underline hover:no-underline" href="https://castopod.org/" target="_blank" rel="noreferrer noopener">Castopod</a> v' .
+                CP_VERSION,
+        ]) ?>
     </footer>
     <button
         type="button"
diff --git a/prepare-release.sh b/prepare-release.sh
index f81598f6ff..93d53ae77d 100644
--- a/prepare-release.sh
+++ b/prepare-release.sh
@@ -6,6 +6,9 @@ COMPOSER_VERSION=$(echo "$VERSION" | perl -pe 's/(?<=[alpha|beta])\.//g')
 # replace composer.json version using jq
 echo "$( jq '.version = "'$COMPOSER_VERSION'"' composer.json )" > composer.json
 
+# replace CP_VERSION constant in app/config/constants
+sed -i "s/^defined('CP_VERSION').*/defined('CP_VERSION') || define('CP_VERSION', '$VERSION');/" ./app/Config/Constants.php
+
 # download GeoLite2-City archive and extract it to writable/uploads
 wget -c "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=v3PguJMcmZMb9Ld0&suffix=tar.gz" -O - | tar -xz -C ./writable/uploads/
 
-- 
GitLab