2023-04-12 22:12:27 +02:00
|
|
|
from pathlib import Path
|
2020-06-15 20:12:30 +02:00
|
|
|
from subprocess import run
|
|
|
|
|
|
|
|
from django import template
|
|
|
|
from django.core.cache import cache
|
|
|
|
|
|
|
|
register = template.Library()
|
|
|
|
|
|
|
|
|
|
|
|
@register.simple_tag
|
|
|
|
def commit_id():
|
2023-04-12 22:12:27 +02:00
|
|
|
current_dir = Path(__file__).parent
|
2020-06-15 20:12:30 +02:00
|
|
|
commit = cache.get("commit")
|
|
|
|
if not commit:
|
2023-04-12 22:12:27 +02:00
|
|
|
sp = run(["git", "rev-parse", "--verify", "HEAD"], capture_output=True, cwd=current_dir)
|
2020-06-15 20:12:30 +02:00
|
|
|
commit = sp.stdout.decode().strip()
|
|
|
|
cache.set("commit", commit)
|
|
|
|
return commit
|