Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Report the same version string on the API and the docker tag

Roland Geider8e3750569fe1
diff --git a/.github/workflows/docker-base.yml b/.github/workflows/docker-base.yml
index a4717d3dc..a15a08271 100644
--- a/.github/workflows/docker-base.yml
+++ b/.github/workflows/docker-base.yml
@@ -35,6 +35,11 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
+ - name: Set build date
+ run: echo "BUILD_DATE=$(date -u +'%Y-%m-%d')" >> $GITHUB_ENV
+
+ # The base image holds no wger code, only Ubuntu and apt packages, so it
+ # is tagged by build date.
- name: Build base image
uses: docker/build-push-action@v7
with:
@@ -42,4 +47,6 @@ jobs:
push: true
file: extras/docker/base/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
- tags: ${{ vars.REGISTRY_REPO }}/base:latest,${{ vars.REGISTRY_REPO }}/base:2.6-dev
+ tags: |
+ ${{ vars.REGISTRY_REPO }}/base:latest
+ ${{ vars.REGISTRY_REPO }}/base:${{ env.BUILD_DATE }}
diff --git a/.github/workflows/docker-demo.yml b/.github/workflows/docker-demo.yml
index bfa78216b..eb7f9dbf1 100644
--- a/.github/workflows/docker-demo.yml
+++ b/.github/workflows/docker-demo.yml
@@ -44,4 +44,4 @@ jobs:
push: true
file: extras/docker/demo/Dockerfile
platforms: linux/amd64,linux/arm64
- tags: ${{ vars.REGISTRY_REPO }}/demo:latest,${{ vars.REGISTRY_REPO }}/demo:2.4-dev
+ tags: ${{ vars.REGISTRY_REPO }}/demo:latest
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 1b97229c9..9f24a38f0 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -48,7 +48,11 @@ jobs:
- name: Read version from wger/version.py
id: version
run: |
- VERSION=$(sed -n "s/^VERSION = Version('\(.*\)')/\1/p" wger/version.py)
+ VERSION=$(sed -n "s/^VERSION_STRING = '\(.*\)'/\1/p" wger/version.py)
+ if [ -z "$VERSION" ]; then
+ echo "::error::could not read VERSION_STRING from wger/version.py"
+ exit 1
+ fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Docker meta
@@ -59,7 +63,8 @@ jobs:
# https://github.com/docker/metadata-action
tags: |
type=raw,value=latest
- type=raw,value=${{ steps.version.outputs.version }}
+ type=semver,pattern={{version}},value=${{ steps.version.outputs.version }}
+ type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.version }}
images: |
${{ env.REGISTRY_IMAGE }}
@@ -148,7 +153,8 @@ jobs:
with:
tags: |
type=raw,value=latest
- type=raw,value=${{ needs.build-prod.outputs.version }}
+ type=semver,pattern={{version}},value=${{ needs.build-prod.outputs.version }}
+ type=semver,pattern={{major}}.{{minor}},value=${{ needs.build-prod.outputs.version }}
images: |
${{ env.REGISTRY_IMAGE }}
diff --git a/wger/core/tests/test_version.py b/wger/core/tests/test_version.py
new file mode 100644
index 000000000..4cafd8b59
--- /dev/null
+++ b/wger/core/tests/test_version.py
@@ -0,0 +1,57 @@
+# This file is part of wger Workout Manager.
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+
+# Standard Library
+import os
+import re
+from unittest import mock
+
+# Django
+from django.urls import reverse
+
+# wger
+from wger.core.tests.base_testcase import WgerTestCase
+from wger.version import (
+ VERSION_STRING,
+ get_version_with_git,
+)
+
+
+SEMVER = re.compile(r'^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$')
+
+
+class VersionTestCase(WgerTestCase):
+ """
+ Tests the version constants and the version endpoint
+ """
+
+ def test_version_string_is_semver(self):
+ """
+ The literal is used as-is as a docker tag, which only accepts semver
+ """
+ self.assertRegex(VERSION_STRING, SEMVER)
+
+ def test_endpoint_reports_the_literal(self):
+ """
+ The API answers with the literal, not with the PEP 440 normalisation
+ """
+ response = self.client.get(reverse('app_version'))
+ self.assertEqual(response.json(), VERSION_STRING)
+
+ def test_git_sha_is_appended_as_build_metadata(self):
+ """
+ The build commit is appended in the semver build metadata syntax
+ """
+ with mock.patch.dict(os.environ, {'APP_BUILD_COMMIT': 'abcdef1234567890'}):
+ self.assertEqual(get_version_with_git(), f'{VERSION_STRING}+gitabcdef1')
diff --git a/wger/version.py b/wger/version.py
index 6bd9f36c6..b502fe4f4 100644
--- a/wger/version.py
+++ b/wger/version.py
@@ -35,24 +35,25 @@ Always use versions in the x.y.z format, without any suffixes like "beta1" or su
MIN_SERVER_VERSION = Version('2.5.0')
"""Minimum version of the server required to run sync commands on this server"""
-VERSION = Version('2.7.0')
+VERSION_STRING = '2.7.0'
"""
-Current version of the app
+Current version of the app.
-Note that this string is also extracted by .github/workflows/docker.yml and used
-as-is to set the docker version, only use [A-Za-z0-9_.-]
+This literal is what the API reports and what .github/workflows/docker.yml
+extracts to tag the images, so both agree. It must be valid semver: write
+pre-releases as "2.8.0-dev", not "2.8.0.dev0".
"""
+VERSION = Version(VERSION_STRING)
+"""Parsed form of VERSION_STRING, for version comparisons"""
-def get_version(version: Version = None) -> str:
- if version is None:
- version = VERSION
- return str(version)
+def get_version() -> str:
+ return VERSION_STRING
-def get_version_with_git(version: Version = None) -> str:
- version = get_version(version)
+def get_version_with_git() -> str:
+ version = VERSION_STRING
git_sha1 = os.environ.get('APP_BUILD_COMMIT', '')[:7]
if git_sha1:
version += f'+git{git_sha1}'