diff --git a/scipost_django/SciPost_v1/settings/base.py b/scipost_django/SciPost_v1/settings/base.py index 07fac12e1ff0ead0fbddb6e63477be79967f517e..0b23676eba5a71a4c1495f9456bafd7132437b5b 100644 --- a/scipost_django/SciPost_v1/settings/base.py +++ b/scipost_django/SciPost_v1/settings/base.py @@ -35,6 +35,17 @@ with open(os.path.join(BASE_DIR, "secrets.json")) as f: secrets = json.load(f) +def get_latest_commit_hash(): + try: + ps = os.popen("git log -n 1 --pretty=format:%h").read() + return ps.strip() + except Exception: + return None + + +COMMIT_HASH = get_latest_commit_hash() + + def get_secret(setting, secrets=secrets): """Get the secret variable or return explicit exception.""" try: @@ -338,6 +349,7 @@ TEMPLATES = [ "django.contrib.messages.context_processors.messages", "scipost.context_processors.roles_processor", "scipost.context_processors.domain_processor", + "scipost.context_processors.commit_hash_processor", "journals.context_processors.publishing_years_processor", "journals.context_processors.journals_processor", "ontology.context_processors.ontology_processor", diff --git a/scipost_django/scipost/context_processors.py b/scipost_django/scipost/context_processors.py index 1e51d5b63bc1174e3dbfa11349f79c6ebd88d21c..b3a74ec0b9da78c0eac2be84f2021f2357d0c7dc 100644 --- a/scipost_django/scipost/context_processors.py +++ b/scipost_django/scipost/context_processors.py @@ -2,6 +2,7 @@ __copyright__ = "Copyright 2016-2018, Stichting SciPost (SciPost Foundation)" __license__ = "AGPL v3" +from django.conf import settings from django.contrib.auth.models import Group from common.utils.models import get_current_domain @@ -56,3 +57,10 @@ def domain_processor(request): Add the domain name to the context. """ return {"DOMAIN_HOST": get_current_domain()} + + +def commit_hash_processor(request): + """ + Add the current commit hash to the context. + """ + return {"COMMIT_HASH": settings.COMMIT_HASH} diff --git a/scipost_django/scipost/templates/scipost/footer.html b/scipost_django/scipost/templates/scipost/footer.html index 2a5328491ccd327f254136759b3b86f78c490f91..b0cab1fff507b1619364d8076d37c964708994f9 100644 --- a/scipost_django/scipost/templates/scipost/footer.html +++ b/scipost_django/scipost/templates/scipost/footer.html @@ -47,7 +47,8 @@ <ul class="list-inline text-center"> <li class="list-inline-item"> <a href="https://git.{{ DOMAIN_HOST }}" target="_blank" rel="noopener"> - <span>{% include 'bi/git.html' %}</span> Git Repository</a> + <span>{% include 'bi/git.html' %}</span> Git Repository</a> + <span class="ms-1">(server version <a class="text-info" href="https://git.{{ DOMAIN_HOST }}/scipost/SciPost/-/commit/{{COMMIT_HASH}}">{{ COMMIT_HASH }}</a>)</span> </li> <li class="list-inline-item"> <a href="{% url 'scipost:feeds' %}" aria-label="RSS feeds">