Skip to content

Commit

Permalink
First changes for using semver everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenton Holmes committed Apr 28, 2022
1 parent 9325eff commit 4ac6503
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,14 @@ jobs:
with:
images: ghcr.io/${{ github.repository }}
tags: |
# Tag branches with branch name
type=ref,event=branch
# Tag tags with tag name
type=ref,event=tag
# Process semver tags
# For a tag x.y.z or vX.Y.Z, output an x.y.z and x.y image tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
-
name: Checkout
uses: actions/checkout@v3
Expand Down
17 changes: 17 additions & 0 deletions docs/administration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ Then you can start paperless-ngx with ``-d`` to have it run in the background.
image: ghcr.io/paperless-ngx/paperless-ngx:latest
.. note::
In version 1.7.1 and onwards, the Docker image can now pinned to a release series.
This is often combined with automatic updaters such as Watchtower to allow safer
unattended upgrading to new bugfix releases only. It is still recommended to always
review release notes before upgrading. To ping your install to a release series, edit
the ``docker-compose.yml`` find the line that says

.. code::
image: ghcr.io/paperless-ngx/paperless-ngx:latest
and replace the version with the series you want to track, for example:

.. code::
image: ghcr.io/paperless-ngx/paperless-ngx:1.7
Bare Metal Route
================

Expand Down
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


__version__ = None
__full_version_str__ = None
__major_minor_version_str__ = None
exec(open("../src/paperless/version.py").read())


Expand Down Expand Up @@ -41,9 +43,9 @@
#

# The short X.Y version.
version = ".".join([str(_) for _ in __version__[:2]])
version = __major_minor_version_str__
# The full version, including alpha/beta/rc tags.
release = ".".join([str(_) for _ in __version__[:3]])
release = __full_version_str__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
29 changes: 17 additions & 12 deletions src/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,28 +676,33 @@ class RemoteVersionView(GenericAPIView):
def get(self, request, format=None):
remote_version = "0.0.0"
is_greater_than_current = False
current_version = packaging_version.parse(version.__full_version_str__)
# TODO: this can likely be removed when frontend settings are saved to DB
feature_is_set = settings.ENABLE_UPDATE_CHECK != "default"
if feature_is_set and settings.ENABLE_UPDATE_CHECK:
try:
with urllib.request.urlopen(
"https://api.github.com/repos/"
+ "paperless-ngx/paperless-ngx/releases/latest",
) as response:
req = urllib.request.Request(
"https://api.github.com/repos/paperless-ngx/"
"paperless-ngx/releases/latest",
)
# Ensure a JSON response
req.add_header("Accept", "application/json")

with urllib.request.urlopen(req) as response:
remote = response.read().decode("utf-8")
try:
remote_json = json.loads(remote)
remote_version = remote_json["tag_name"].replace("ngx-", "")
remote_version = remote_json["tag_name"].removeprefix("ngx-")
except ValueError:
logger.debug("An error occured parsing remote version json")
logger.debug("An error occurred parsing remote version json")
except urllib.error.URLError:
logger.debug("An error occured checking for available updates")
logger.debug("An error occurred checking for available updates")

current_version = ".".join([str(_) for _ in version.__version__[:3]])
is_greater_than_current = packaging_version.parse(
remote_version,
) > packaging_version.parse(
current_version,
is_greater_than_current = (
packaging_version.parse(
remote_version,
)
> current_version
)

return Response(
Expand Down
2 changes: 1 addition & 1 deletion src/paperless/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def __call__(self, request):
if request.user.is_authenticated:
versions = settings.REST_FRAMEWORK["ALLOWED_VERSIONS"]
response["X-Api-Version"] = versions[len(versions) - 1]
response["X-Version"] = ".".join([str(_) for _ in version.__version__])
response["X-Version"] = version.__full_version_str__

return response
9 changes: 8 additions & 1 deletion src/paperless/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
__version__ = (1, 7, 0)
from typing import Final
from typing import Tuple

__version__: Final[Tuple[int, int, int]] = (1, 7, 0)
# Version string like X.Y.Z
__full_version_str__: Final[str] = ".".join(map(str, __version__))
# Version string like X.Y
__major_minor_version_str__: Final[str] = ".".join(map(str, __version__[:-1]))

0 comments on commit 4ac6503

Please sign in to comment.