Skip to content

Commit

Permalink
feat: add version string to templates
Browse files Browse the repository at this point in the history
That way, it's clear which version of the software is actually
running.
  • Loading branch information
toabctl committed Jan 20, 2024
1 parent e8fedaf commit 75e6fdb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set django-kitamanager version env
run: |
pip install setuptools_scm
echo "DJANGO_KITAMANAGER_VERSION=$(cd django-kitamanager && python -m setuptools_scm)" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -64,6 +68,8 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v3
with:
build-args: |
"VERSION=${{ env.DJANGO_KITAMANAGER_VERSION }}"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ubuntu:jammy

MAINTAINER thomasbechtold@jpberlin.de
ARG VERSION=unknown

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
Expand All @@ -15,7 +16,7 @@ WORKDIR $APPDIR
COPY . .
RUN cd django-kitamanager && \
pip install --upgrade pip setuptools \
&& pip install --no-cache-dir "." gunicorn tzdata
&& SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} pip install --no-cache-dir "." gunicorn tzdata

COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load static %}
{% load kitamanagertags %}
{% load i18n %}

<!doctype html>
Expand Down Expand Up @@ -94,5 +95,11 @@
{% block content %}{% endblock content %}
</section>
</div>
<footer class="footer">
<div class="content has-text-centered">
{% version as version %}
version: {{ version }}
</div>
</footer>
</body>
</html>
12 changes: 12 additions & 0 deletions django-kitamanager/kitamanager/templatetags/kitamanagertags.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from importlib.metadata import version, PackageNotFoundError
from django import template
from kitamanager.models import Employee, ChildContract, Person

register = template.Library()


try:
_version = version("django-kitamanager")
except PackageNotFoundError:
_version = "unknown"


@register.filter("pay_level_next")
def pay_level_next(obj, date):
if not isinstance(obj, Employee):
Expand Down Expand Up @@ -37,3 +44,8 @@ def age(obj, date):
if not isinstance(obj, Person):
raise Exception(f'"age" template filter expects a "Person" object but got {obj.__class__}')
return obj.age(date)


@register.simple_tag
def version():
return _version
7 changes: 5 additions & 2 deletions django-kitamanager/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -31,4 +31,7 @@ dynamic = ["version"]

[project.optional-dependencies]
tests = ["flake8", "pytest-django",]
docs = ["Sphinx", "sphinx-rtd-theme"]
docs = ["Sphinx", "sphinx-rtd-theme"]

[tool.setuptools_scm]
root = ".."

0 comments on commit 75e6fdb

Please sign in to comment.