Skip to content

Commit

Permalink
Update checker kan niet overweg met release candidate tags #1566
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Jan 31, 2022
1 parent 5a3e07c commit bd26cee
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 19 deletions.
6 changes: 6 additions & 0 deletions docs/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Current version
:doc:`How to update</how-to/upgrading/upgrade>` *(minor updates only)*


v4.19.1 - 2022-02-01
--------------------

- ``Fixed`` Update checker kan niet overweg met release candidate tags [`#1566 <https://github.com/dsmrreader/dsmr-reader/issues/1566>`_]


v4.19.0 - 2021-10-23
--------------------

Expand Down
28 changes: 23 additions & 5 deletions dsmr_backend/services/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,31 @@ def get_capability(capability: Capability) -> bool:

def is_latest_version() -> bool:
""" Checks whether the current version is the latest tagged available on GitHub. """
response = requests.get(settings.DSMRREADER_LATEST_TAGS_LIST)
latest_tag = response.json()[0]
response = requests.get(settings.DSMRREADER_LATEST_RELEASES_LIST)

local_version = '{}.{}.{}'.format(* settings.DSMRREADER_RAW_VERSION[:3])
remote_version = latest_tag['name'].replace('v', '')
for current_release in response.json():
# Ignore release candidates or drafts.
if current_release['prerelease'] or current_release['draft']:
continue

# Ignore other branches.
if not current_release['tag_name'].startswith(settings.DSMRREADER_MAIN_BRANCH):
continue

release_tag = current_release['tag_name'].replace('v', '')
local_version = '{}.{}.{}'.format(* settings.DSMRREADER_RAW_VERSION[:3])

# StrictVersion does not support dashes nor rc's
# @see https://www.python.org/dev/peps/pep-0386/
comparable_release_tag = release_tag.replace('-', '').replace('rc', 'b')

# Ignore same or lower releases.
if StrictVersion(comparable_release_tag) <= StrictVersion(local_version):
continue

return False

return StrictVersion(local_version) >= StrictVersion(remote_version)
return True


def is_timestamp_passed(timestamp: Optional[timezone.datetime]) -> bool:
Expand Down
58 changes: 46 additions & 12 deletions dsmr_backend/tests/services/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import importlib
from unittest import mock

from django.conf import settings
from django.test import TestCase
from django.utils import timezone

Expand Down Expand Up @@ -324,38 +325,71 @@ def test_request_monitoring_status_coverage(self, signal_mock):

@mock.patch('requests.get')
class TestIslatestVersion(TestCase):
response_older = [
response_same_branch_unchanged = [
{
"name": "v1.2.0"
# Lowest in branch
"tag_name": "v{}.0.0".format(settings.DSMRREADER_MAIN_BRANCH),
"prerelease": False,
"draft": False,
},
{
"name": "v1.1.0"
# Current in branch
"tag_name": '{}.{}.{}'.format(* settings.DSMRREADER_RAW_VERSION[:3]),
"prerelease": False,
"draft": False,
},
{
# Latest but draft (should be ignored)
"tag_name": "v10.99.1",
"prerelease": False,
"draft": True,
},
{
# Latest but prerelease (should be ignored)
"tag_name": "v10.99.2",
"prerelease": True,
"draft": False,
}
]

response_newer = [
response_same_branch_newer_release = [
{
"name": "v10.99.0"
},
# Latest in branch
"tag_name": "{}.99.0".format(settings.DSMRREADER_MAIN_BRANCH),
"prerelease": False,
"draft": False,
}
]
response_newer_branch = [
{
"name": "v1.1.0"
# Newer/other branch (should be ignored)
"tag_name": "v10.99.0",
"prerelease": False,
"draft": False,
}
]

def test_true(self, get_mock):
def test_same_releases_in_branch_available(self, get_mock):
request_mock = mock.MagicMock()
request_mock.json.return_value = self.response_older
request_mock.json.return_value = self.response_same_branch_unchanged
get_mock.return_value = request_mock

self.assertTrue(dsmr_backend.services.backend.is_latest_version())

def test_false(self, get_mock):
def test_new_release_in_branch_available(self, get_mock):
request_mock = mock.MagicMock()
request_mock.json.return_value = self.response_newer
request_mock.json.return_value = self.response_same_branch_newer_release
get_mock.return_value = request_mock

self.assertFalse(dsmr_backend.services.backend.is_latest_version())

def test_newer_branch_new_release_available(self, get_mock):
request_mock = mock.MagicMock()
request_mock.json.return_value = self.response_newer_branch
get_mock.return_value = request_mock

# Should ignore other branches
self.assertTrue(dsmr_backend.services.backend.is_latest_version())


class TestIsLocalTimestampPassed(TestCase):
@mock.patch('django.utils.timezone.now')
Expand Down
2 changes: 1 addition & 1 deletion dsmrreader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.version import get_version

VERSION = (4, 19, 0, 'final', 0)
VERSION = (4, 19, 1, 'final', 0)

__version__ = get_version(VERSION)
2 changes: 1 addition & 1 deletion dsmrreader/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
DSMRREADER_VERSION = dsmrreader.__version__
DSMRREADER_RAW_VERSION = dsmrreader.VERSION
DSMRREADER_USER_AGENT = 'DSMR-reader v{}'.format(DSMRREADER_VERSION)
DSMRREADER_LATEST_TAGS_LIST = 'https://api.github.com/repos/dsmrreader/dsmr-reader/tags'
DSMRREADER_LATEST_RELEASES_LIST = 'https://api.github.com/repos/dsmrreader/dsmr-reader/releases'

# Scheduled Process modules.
DSMRREADER_MODULE_EMAIL_BACKUP = 'dsmr_backup.services.email.run'
Expand Down
17 changes: 17 additions & 0 deletions dsmrreader/provisioning/downgrade/v4.19.1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

# Dump for DSMR-reader v4.19.1
./manage.py migrate dsmr_api 0003_create_api_user
./manage.py migrate dsmr_backend 0015_backend_restart_required
./manage.py migrate dsmr_backup 0013_dropbox_setting_refactoring
./manage.py migrate dsmr_consumption 0019_energy_supplier_price_decimals
./manage.py migrate dsmr_datalogger 0030_override_telegram_timestamp
./manage.py migrate dsmr_dropbox 0001_schedule_dropbox
./manage.py migrate dsmr_frontend 0043_default_color_update_tariff_2
./manage.py migrate dsmr_influxdb 0004_client_settings_update
./manage.py migrate dsmr_mindergas 0005_schedule_mindergas_export
./manage.py migrate dsmr_mqtt 0020_drop_mqtt_qos_setting
./manage.py migrate dsmr_notification 0008_dummy_notification_provider
./manage.py migrate dsmr_pvoutput 0004_pvoutput_setting_refactoring
./manage.py migrate dsmr_stats 0017_day_statistics_reading_history_retroactive
./manage.py migrate dsmr_weather 0006_schedule_weather_update

0 comments on commit bd26cee

Please sign in to comment.