Skip to content

Commit

Permalink
autodetect current version of the application
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Feb 15, 2020
1 parent 16f21f4 commit cef18e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 0 additions & 1 deletion VERSION.json

This file was deleted.

34 changes: 25 additions & 9 deletions survey/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@

import os
import json
import subprocess
from csskp.settings import BASE_DIR


def get_version(request):
try:
with open(os.path.join(BASE_DIR,'VERSION.json'), 'r') as json_file:
data = json.load(json_file)
version = "{}.{}.{}".format(data['major'], data['minor'],
data['hotfix'])
except:
version = "0.0.0"
version = (
os.environ.get("PKGVER")
or subprocess.run(["git",
"-C",
BASE_DIR,
"describe",
"--tags"], stdout=subprocess.PIPE)
.stdout.decode()
.strip()
)
version = version.split("-")
if len(version) == 1:
app_version = version[0]
version_url = "https://github.com/CASES-LU/Fit4Cybersecurity/releases/tag/{}".format(
version[0]
)
else:
app_version = "{} - {}".format(version[0], version[2][1:])
version_url = "https://github.com/CASES-LU/Fit4Cybersecurity/commits/{}".format(
version[2][1:]
)
return {
'app_version': version
'app_version': app_version,
'version_url': version_url
}
4 changes: 2 additions & 2 deletions templates/survey/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ <h4>Your web browser (Internet Explorer) is not compatible.</h4>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/CASES-LU/Fit4Cybersecurity/releases/tag/v{{ app_version }}" title="{{ _('Version of Fit4Cybersecurity') }}" alt="{{ _('Version of Fit4Cybersecurity') }}" target="_blank">
v{{ app_version }}
<a class="nav-link" href="{{ version_url }}" title="{{ _('Version of Fit4Cybersecurity') }}" alt="{{ _('Version of Fit4Cybersecurity') }}" target="_blank">
{{ app_version }}
</a>
</li>
</ul>
Expand Down

0 comments on commit cef18e7

Please sign in to comment.