diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index fe7a7738a..1d3c1c19c 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -17,6 +17,12 @@ Current version :doc:`How to update` *(minor updates only)* +v4.19.1 - 2022-02-01 +-------------------- + +- ``Fixed`` Update checker kan niet overweg met release candidate tags [`#1566 `_] + + v4.19.0 - 2021-10-23 -------------------- diff --git a/dsmr_backend/services/backend.py b/dsmr_backend/services/backend.py index 9e6f7a27a..e6a2224a4 100644 --- a/dsmr_backend/services/backend.py +++ b/dsmr_backend/services/backend.py @@ -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: diff --git a/dsmr_backend/tests/services/test_backend.py b/dsmr_backend/tests/services/test_backend.py index 6566cd6c5..1199d0017 100644 --- a/dsmr_backend/tests/services/test_backend.py +++ b/dsmr_backend/tests/services/test_backend.py @@ -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 @@ -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') diff --git a/dsmrreader/__init__.py b/dsmrreader/__init__.py index 44b2f94b1..1502393ba 100644 --- a/dsmrreader/__init__.py +++ b/dsmrreader/__init__.py @@ -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) diff --git a/dsmrreader/config/defaults.py b/dsmrreader/config/defaults.py index 0cbc4d4fe..925e4b251 100644 --- a/dsmrreader/config/defaults.py +++ b/dsmrreader/config/defaults.py @@ -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' diff --git a/dsmrreader/provisioning/downgrade/v4.19.1.sh b/dsmrreader/provisioning/downgrade/v4.19.1.sh new file mode 100644 index 000000000..d05170bef --- /dev/null +++ b/dsmrreader/provisioning/downgrade/v4.19.1.sh @@ -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