diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index c1b40b7..41c5630 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -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 @@ -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 }} diff --git a/Dockerfile b/Dockerfile index 1d31310..46ad9df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM ubuntu:jammy MAINTAINER thomasbechtold@jpberlin.de +ARG VERSION=unknown ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 @@ -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"] diff --git a/django-kitamanager/kitamanager/templates/kitamanager/base.html b/django-kitamanager/kitamanager/templates/kitamanager/base.html index 850a890..13bfdf8 100644 --- a/django-kitamanager/kitamanager/templates/kitamanager/base.html +++ b/django-kitamanager/kitamanager/templates/kitamanager/base.html @@ -1,4 +1,5 @@ {% load static %} +{% load kitamanagertags %} {% load i18n %} @@ -94,5 +95,11 @@ {% block content %}{% endblock content %} + diff --git a/django-kitamanager/kitamanager/templatetags/kitamanagertags.py b/django-kitamanager/kitamanager/templatetags/kitamanagertags.py index f79d8b7..fbce3c2 100644 --- a/django-kitamanager/kitamanager/templatetags/kitamanagertags.py +++ b/django-kitamanager/kitamanager/templatetags/kitamanagertags.py @@ -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): @@ -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 diff --git a/django-kitamanager/pyproject.toml b/django-kitamanager/pyproject.toml index 3f3c6b1..0b2d334 100644 --- a/django-kitamanager/pyproject.toml +++ b/django-kitamanager/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "setuptools-scm"] +requires = ["setuptools>=64", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" [project] @@ -31,4 +31,7 @@ dynamic = ["version"] [project.optional-dependencies] tests = ["flake8", "pytest-django",] -docs = ["Sphinx", "sphinx-rtd-theme"] \ No newline at end of file +docs = ["Sphinx", "sphinx-rtd-theme"] + +[tool.setuptools_scm] +root = ".." \ No newline at end of file