From 217c18096414f9a10e2cb65c6c8dfe755b5065ee Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Mon, 4 Nov 2024 14:06:16 +0100 Subject: [PATCH 1/3] Add custom parsing version handlding the PrestaShop development branches like 1.7.8.x and 8.0.x, get_aliases is now able to handle such branches and the VersionManager tests have been improved --- prestashop_docker/version_manager.py | 89 ++- .../prestashop_docker/test_version_manager.py | 597 ++++++++++++------ 2 files changed, 504 insertions(+), 182 deletions(-) diff --git a/prestashop_docker/version_manager.py b/prestashop_docker/version_manager.py index 37673d00..b05d0f44 100644 --- a/prestashop_docker/version_manager.py +++ b/prestashop_docker/version_manager.py @@ -83,12 +83,12 @@ def parse_version(self, version): def get_version_from_string(self, version): ''' - Split version to find PrestaShop version, PHP version and container type + Split version to find PrestaShop version, branch version, PHP version and container type @param version: The version you want @type version: str - @return: A tuple containing ('PS_VERSION', (PHP_VERSIONS), 'CONTAINER_TYPE') - or ('PS_VERSION', 'PHP_VERSION', 'CONTAINER_TYPE') + @return: A tuple containing ('PS_VERSION', 'BRANCH_VERSION', (PHP_VERSIONS), 'CONTAINER_TYPE') + or ('PS_VERSION', 'BRANCH_VERSION', 'PHP_VERSION', 'CONTAINER_TYPE') @rtype: tuple ''' matches = self.parse_version_from_string(version) @@ -108,12 +108,83 @@ def get_version_from_string(self, version): if matches.group('container'): container_version = matches.group('container') + split_version = self.split_prestashop_version(ps_version) + if split_version is None: + branch_version = 'develop' + elif split_version['patch'] == 'x': + # ps_version actually already contains the branch + branch_version = ps_version + # We need to transform the branch into the next patch version + patch_index = ps_version.rindex('.') + last_patch = self.get_last_patch_from_version(ps_version) + if last_patch is None: + last_patch = '0' + else: + last_patch = str(int(last_patch) + 1) + ps_version = ps_version[:patch_index + 1] + last_patch + else: + # Transform the last patch version into an x to get the branch, we ignore any -rc that may be present + real_version = split_version['version'] + patch_index = real_version.rindex('.') + branch_version = real_version[:patch_index + 1] + 'x' + return { 'ps_version': ps_version, + 'branch_version': branch_version, 'php_versions': php_versions, 'container_version': container_version } + def get_last_patch_from_version(self, version): + ''' + Get last patch version for the specified version based on the VERSIONS list + @param version: The version you need the match from + @type version: str + @return: Return None if no patch is found otherwise an int with the patch. + @rtpe: None|int + ''' + split_version = self.split_prestashop_version(version) + if (split_version is None): + return None + + lastPatch = None + for ps_version, php_versions in VERSIONS.items(): + split_ps_version = self.split_prestashop_version(ps_version) + if split_ps_version is None: + continue + if (split_ps_version['major'] != split_version['major'] or split_ps_version['minor'] != split_version['minor']): + continue + if split_ps_version['patch'] == 'x': + continue + if (lastPatch is None or int(split_ps_version['patch']) > int(lastPatch)): + lastPatch = split_ps_version['patch'] + return lastPatch + + def split_prestashop_version(self, version): + ''' + Split the version into major minor patch object, it is a custom-tailed alternative to semver.VersionInfo.parse + that can handle our development branches like 1.7.8.x, 8.0.x, ... + @param version: The version you need to split + @type version: str + @return: Return None if no patch is found otherwise an int with the patch. + @rtpe: None|tuple + ''' + regex = r"^(?P(1.)?[0-9]+)\.(?P[0-9]+)\.(?P[0-9x]+)(?P-(alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?" + matches = re.search(regex, version) + + if (matches and matches.group() and matches.group('major') and matches.group('major') and matches.group('major')): + # Remove the initial matched - + prerelease = matches.group('prerelease')[1:] if matches.group('prerelease') else None + + return { + 'version': matches.group('major') + '.' + matches.group('minor') + '.' + matches.group('patch'), + 'major': matches.group('major'), + 'minor': matches.group('minor'), + 'patch': matches.group('patch'), + 'prerelease': prerelease, + } + return None + def parse_version_from_string(self, version): ''' Parse version from string based on a regex @@ -122,7 +193,7 @@ def parse_version_from_string(self, version): @return: Return None if no position in the string matches the pattern otherwise a Match object. @rtpe: None|Match ''' - regex = r"^(?P(?:[0-9]+\.){0,3}(?:[0-9]+|nightly)(?:-(?:alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?)(?:-(?P\d+\.\d+))?(?:-(?Pfpm|apache))?$" + regex = r"^(?P(?:[0-9]+\.){0,3}(?:[0-9]+|nightly|x)(?:-(?:alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?)(?:-(?P\d+\.\d+))?(?:-(?Pfpm|apache))?$" return re.search(regex, version) def get_aliases(self): @@ -150,7 +221,7 @@ def get_aliases(self): if alias_version != 'latest': self.append_to_aliases(aliases, ps_version, php_version, PREFERED_CONTAINER, alias_version + '-' + php_version) - # Check prefered container + # Check preferred container self.append_to_aliases(aliases, ps_version, alias_php_version, PREFERED_CONTAINER, alias_version) # Check containers @@ -184,6 +255,14 @@ def get_ps_versions_aliases(self): } continue + # Ignore branch versions + split_version = self.split_prestashop_version(ps_version) + if split_version['patch'] == 'x': + aliases[ps_version] = { + 'value': ps_version + } + continue + # PrestaShop versions before 8 are in format 1.MAJOR.MINOR.PATCH # Starting version 8, format is MAJOR.MINOR.PATCH splitted_version = ps_version.split('.', 1) diff --git a/tests/prestashop_docker/test_version_manager.py b/tests/prestashop_docker/test_version_manager.py index 2d90da23..361123a0 100644 --- a/tests/prestashop_docker/test_version_manager.py +++ b/tests/prestashop_docker/test_version_manager.py @@ -1,6 +1,9 @@ from pyfakefs.fake_filesystem_unittest import TestCase from prestashop_docker.version_manager import VersionManager from unittest.mock import patch +import semver +# Used for debug +# import pprint class VersionManagerTestCase(TestCase): @@ -20,6 +23,10 @@ def setUp(self, docker_api): self.fs.create_dir('/tmp/images/8.1.0/7.2-fpm') self.fs.create_dir('/tmp/images/8.1.3/7.2-apache') self.fs.create_dir('/tmp/images/8.1.3/7.2-fpm') + self.fs.create_dir('/tmp/images/9.0.x/8.1-fpm') + self.fs.create_dir('/tmp/images/9.0.x/8.1-apache') + self.fs.create_dir('/tmp/images/9.0.x/8.2-fpm') + self.fs.create_dir('/tmp/images/9.0.x/8.2-apache') self.fs.create_dir('/tmp/images/nightly/7.1-fpm') self.fs.create_dir('/tmp/images/nightly/7.1-apache') self.version_manager = self.create_instance() @@ -35,24 +42,128 @@ def create_instance(self): '1.7.6.4': ('5.6', '7.1'), '1.7.6.5': ('5.6', '7.1'), '1.7.6.8': ('5.6', '7.1', '7.2'), + '1.7.6.24': ('5.6', '7.1', '7.2'), + '1.7.6.x': ('5.6', '7.1', '7.2'), '1.7.7.0-rc.1': ('7.1', '7.2', '7.3'), '8.0.0': ('7.2', '7.3', '7.4', '8.0', '8.1'), '8.0.0-rc.1': ('7.2', '7.3', '7.4', '8.0', '8.1'), '8.1.0': ('7.2', '7.3', '7.4', '8.0', '8.1'), '8.1.3': ('7.2', '7.3', '7.4', '8.0', '8.1'), + '8.1.x': ('7.2', '7.3', '7.4', '8.0', '8.1'), + '9.0.x': ('8.1', '8.2', '8.3'), 'nightly': ('7.1',) } + @patch('prestashop_docker.version_manager.VERSIONS', all_versions) + def test_split_prestashop_version(self): + result = self.version_manager.split_prestashop_version('8.0.0') + self.assertEqual( + {'version': '8.0.0', 'major': '8', 'minor': '0', 'patch': '0', 'prerelease': None}, + result + ) + result = self.version_manager.split_prestashop_version('10.2.24') + self.assertEqual( + {'version': '10.2.24', 'major': '10', 'minor': '2', 'patch': '24', 'prerelease': None}, + result + ) + result = self.version_manager.split_prestashop_version('9.0.x') + self.assertEqual( + {'version': '9.0.x', 'major': '9', 'minor': '0', 'patch': 'x', 'prerelease': None}, + result + ) + result = self.version_manager.split_prestashop_version('1.7.4.3') + self.assertEqual( + {'version': '1.7.4.3', 'major': '1.7', 'minor': '4', 'patch': '3', 'prerelease': None}, + result + ) + result = self.version_manager.split_prestashop_version('1.7.8.x') + self.assertEqual( + {'version': '1.7.8.x', 'major': '1.7', 'minor': '8', 'patch': 'x', 'prerelease': None}, + result + ) + result = self.version_manager.split_prestashop_version('1.7.7.0-rc.1') + self.assertEqual( + {'version': '1.7.7.0', 'major': '1.7', 'minor': '7', 'patch': '0', 'prerelease': 'rc.1'}, + result + ) + result = self.version_manager.split_prestashop_version('nightly') + self.assertEqual( + None, + result + ) + + @patch('prestashop_docker.version_manager.VERSIONS', all_versions) + def test_get_last_patch_from_version(self): + result = self.version_manager.get_last_patch_from_version('1.7.6.4') + self.assertEqual( + '24', + result + ) + result = self.version_manager.get_last_patch_from_version('8.0.0') + self.assertEqual( + '0', + result + ) + result = self.version_manager.get_last_patch_from_version('8.1.0') + self.assertEqual( + '3', + result + ) + result = self.version_manager.get_last_patch_from_version('8.1.3') + self.assertEqual( + '3', + result + ) + result = self.version_manager.get_last_patch_from_version('8.1.x') + self.assertEqual( + '3', + result + ) + result = self.version_manager.get_last_patch_from_version('9.0.x') + self.assertEqual( + None, + result + ) + result = self.version_manager.get_last_patch_from_version('nightly') + self.assertEqual( + None, + result + ) + @patch('prestashop_docker.version_manager.VERSIONS', all_versions) def test_get_version_from_string_with_ps_version(self): + # Existing patch versions deduce the branch version with a finishing x result = self.version_manager.get_version_from_string('1.7.6.8') self.assertEqual( - {'ps_version': '1.7.6.8', 'php_versions': ('5.6', '7.1', '7.2'), 'container_version': None}, + {'ps_version': '1.7.6.8', 'branch_version': '1.7.6.x', 'php_versions': ('5.6', '7.1', '7.2'), 'container_version': None}, result ) result = self.version_manager.get_version_from_string('8.0.0') self.assertEqual( - {'ps_version': '8.0.0', 'php_versions': ('7.2', '7.3', '7.4', '8.0', '8.1'), 'container_version': None}, + {'ps_version': '8.0.0', 'branch_version': '8.0.x', 'php_versions': ('7.2', '7.3', '7.4', '8.0', '8.1'), 'container_version': None}, + result + ) + # Branch input return target version patch + 1 + result = self.version_manager.get_version_from_string('8.1.x') + self.assertEqual( + {'ps_version': '8.1.4', 'branch_version': '8.1.x', 'php_versions': ('7.2', '7.3', '7.4', '8.0', '8.1'), 'container_version': None}, + result + ) + result = self.version_manager.get_version_from_string('1.7.6.x') + self.assertEqual( + {'ps_version': '1.7.6.25', 'branch_version': '1.7.6.x', 'php_versions': ('5.6', '7.1', '7.2'), 'container_version': None}, + result + ) + # Branch input with no other patch versions returns patch 0 + result = self.version_manager.get_version_from_string('9.0.x') + self.assertEqual( + {'ps_version': '9.0.0', 'branch_version': '9.0.x', 'php_versions': ('8.1', '8.2', '8.3'), 'container_version': None}, + result + ) + # Nightly version uses develop as the branch + result = self.version_manager.get_version_from_string('nightly') + self.assertEqual( + {'ps_version': 'nightly', 'branch_version': 'develop', 'php_versions': ('7.1',), 'container_version': None}, result ) @@ -67,12 +178,12 @@ def test_get_version_from_string_with_invalid_version(self): def test_get_version_from_string_with_container_version(self): result = self.version_manager.get_version_from_string('1.7.6.8-5.6') self.assertEqual( - {'ps_version': '1.7.6.8', 'php_versions': ('5.6',), 'container_version': None}, + {'ps_version': '1.7.6.8', 'branch_version': '1.7.6.x', 'php_versions': ('5.6',), 'container_version': None}, result ) result = self.version_manager.get_version_from_string('8.0.0-7.2') self.assertEqual( - {'ps_version': '8.0.0', 'php_versions': ('7.2',), 'container_version': None}, + {'ps_version': '8.0.0', 'branch_version': '8.0.x', 'php_versions': ('7.2',), 'container_version': None}, result ) @@ -80,12 +191,12 @@ def test_get_version_from_string_with_container_version(self): def test_get_version_from_string_with_container_version_and_type(self): result = self.version_manager.get_version_from_string('1.7.6.8-5.6-fpm') self.assertEqual( - {'ps_version': '1.7.6.8', 'php_versions': ('5.6',), 'container_version': 'fpm'}, + {'ps_version': '1.7.6.8', 'branch_version': '1.7.6.x', 'php_versions': ('5.6',), 'container_version': 'fpm'}, result ) result = self.version_manager.get_version_from_string('8.0.0-7.2-fpm') self.assertEqual( - {'ps_version': '8.0.0', 'php_versions': ('7.2',), 'container_version': 'fpm'}, + {'ps_version': '8.0.0', 'branch_version': '8.0.x', 'php_versions': ('7.2',), 'container_version': 'fpm'}, result ) @@ -93,12 +204,12 @@ def test_get_version_from_string_with_container_version_and_type(self): def test_get_version_from_string_with_pre_release_and_without_container_version_and_type(self): result = self.version_manager.get_version_from_string('1.7.7.0-rc.1') self.assertEqual( - {'ps_version': '1.7.7.0-rc.1', 'php_versions': ('7.1', '7.2', '7.3'), 'container_version': None}, + {'ps_version': '1.7.7.0-rc.1', 'branch_version': '1.7.7.x', 'php_versions': ('7.1', '7.2', '7.3'), 'container_version': None}, result ) result = self.version_manager.get_version_from_string('8.0.0-rc.1') self.assertEqual( - {'ps_version': '8.0.0-rc.1', 'php_versions': ('7.2', '7.3', '7.4', '8.0', '8.1'), 'container_version': None}, + {'ps_version': '8.0.0-rc.1', 'branch_version': '8.0.x', 'php_versions': ('7.2', '7.3', '7.4', '8.0', '8.1'), 'container_version': None}, result ) @@ -106,12 +217,12 @@ def test_get_version_from_string_with_pre_release_and_without_container_version_ def test_get_version_from_string_with_pre_release_and_php_version_and_without_container_version(self): result = self.version_manager.get_version_from_string('1.7.7.0-rc.1-7.3') self.assertEqual( - {'ps_version': '1.7.7.0-rc.1', 'php_versions': ('7.3',), 'container_version': None}, + {'ps_version': '1.7.7.0-rc.1', 'branch_version': '1.7.7.x', 'php_versions': ('7.3',), 'container_version': None}, result ) result = self.version_manager.get_version_from_string('8.0.0-rc.1-7.3') self.assertEqual( - {'ps_version': '8.0.0-rc.1', 'php_versions': ('7.3',), 'container_version': None}, + {'ps_version': '8.0.0-rc.1', 'branch_version': '8.0.x', 'php_versions': ('7.3',), 'container_version': None}, result ) @@ -119,12 +230,12 @@ def test_get_version_from_string_with_pre_release_and_php_version_and_without_co def test_get_version_from_string_with_pre_release_and_php_version_and_with_container_version(self): result = self.version_manager.get_version_from_string('1.7.7.0-rc.1-7.3-apache') self.assertEqual( - {'ps_version': '1.7.7.0-rc.1', 'php_versions': ('7.3',), 'container_version': 'apache'}, + {'ps_version': '1.7.7.0-rc.1', 'branch_version': '1.7.7.x', 'php_versions': ('7.3',), 'container_version': 'apache'}, result ) result = self.version_manager.get_version_from_string('8.0.0-rc.1-7.3-apache') self.assertEqual( - {'ps_version': '8.0.0-rc.1', 'php_versions': ('7.3',), 'container_version': 'apache'}, + {'ps_version': '8.0.0-rc.1', 'branch_version': '8.0.x', 'php_versions': ('7.3',), 'container_version': 'apache'}, result ) @@ -188,176 +299,308 @@ def test_parse_version_with_valid_version_php_version_and_container(self): @patch('prestashop_docker.version_manager.VERSIONS', all_versions) def test_get_versions(self): - print(self.version_manager.get_versions()) - self.assertEqual( - { - '1.7.5.0-5.6-fpm': '/tmp/images/1.7.5.0/5.6-fpm', - '1.7.5.0-5.6-apache': '/tmp/images/1.7.5.0/5.6-apache', - '1.7.5.0-5.4-fpm': '/tmp/images/1.7.5.0/5.4-fpm', - '1.7.5.0-5.4-apache': '/tmp/images/1.7.5.0/5.4-apache', - '1.7.5.1-5.6-fpm': '/tmp/images/1.7.5.1/5.6-fpm', - '1.7.5.1-5.6-apache': '/tmp/images/1.7.5.1/5.6-apache', - '1.7.5.1-5.4-fpm': '/tmp/images/1.7.5.1/5.4-fpm', - '1.7.5.1-5.4-apache': '/tmp/images/1.7.5.1/5.4-apache', - '1.7.6.4-5.6-fpm': '/tmp/images/1.7.6.4/5.6-fpm', - '1.7.6.4-5.6-apache': '/tmp/images/1.7.6.4/5.6-apache', - '1.7.6.4-7.1-fpm': '/tmp/images/1.7.6.4/7.1-fpm', - '1.7.6.4-7.1-apache': '/tmp/images/1.7.6.4/7.1-apache', - '1.7.6.5-5.6-fpm': '/tmp/images/1.7.6.5/5.6-fpm', - '1.7.6.5-5.6-apache': '/tmp/images/1.7.6.5/5.6-apache', - '1.7.6.5-7.1-fpm': '/tmp/images/1.7.6.5/7.1-fpm', - '1.7.6.5-7.1-apache': '/tmp/images/1.7.6.5/7.1-apache', - '1.7.6.8-5.6-fpm': '/tmp/images/1.7.6.8/5.6-fpm', - '1.7.6.8-5.6-apache': '/tmp/images/1.7.6.8/5.6-apache', - '1.7.6.8-7.1-fpm': '/tmp/images/1.7.6.8/7.1-fpm', - '1.7.6.8-7.1-apache': '/tmp/images/1.7.6.8/7.1-apache', - '1.7.6.8-7.2-fpm': '/tmp/images/1.7.6.8/7.2-fpm', - '1.7.6.8-7.2-apache': '/tmp/images/1.7.6.8/7.2-apache', - '1.7.7.0-rc.1-7.1-fpm': '/tmp/images/1.7.7.0-rc.1/7.1-fpm', - '1.7.7.0-rc.1-7.1-apache': '/tmp/images/1.7.7.0-rc.1/7.1-apache', - '1.7.7.0-rc.1-7.2-fpm': '/tmp/images/1.7.7.0-rc.1/7.2-fpm', - '1.7.7.0-rc.1-7.2-apache': '/tmp/images/1.7.7.0-rc.1/7.2-apache', - '1.7.7.0-rc.1-7.3-fpm': '/tmp/images/1.7.7.0-rc.1/7.3-fpm', - '1.7.7.0-rc.1-7.3-apache': '/tmp/images/1.7.7.0-rc.1/7.3-apache', - '8.0.0-7.2-fpm': '/tmp/images/8.0.0/7.2-fpm', - '8.0.0-7.2-apache': '/tmp/images/8.0.0/7.2-apache', - '8.0.0-7.3-fpm': '/tmp/images/8.0.0/7.3-fpm', - '8.0.0-7.3-apache': '/tmp/images/8.0.0/7.3-apache', - '8.0.0-7.4-fpm': '/tmp/images/8.0.0/7.4-fpm', - '8.0.0-7.4-apache': '/tmp/images/8.0.0/7.4-apache', - '8.0.0-8.0-fpm': '/tmp/images/8.0.0/8.0-fpm', - '8.0.0-8.0-apache': '/tmp/images/8.0.0/8.0-apache', - '8.0.0-8.1-fpm': '/tmp/images/8.0.0/8.1-fpm', - '8.0.0-8.1-apache': '/tmp/images/8.0.0/8.1-apache', - '8.0.0-rc.1-7.2-fpm': '/tmp/images/8.0.0-rc.1/7.2-fpm', - '8.0.0-rc.1-7.2-apache': '/tmp/images/8.0.0-rc.1/7.2-apache', - '8.0.0-rc.1-7.3-fpm': '/tmp/images/8.0.0-rc.1/7.3-fpm', - '8.0.0-rc.1-7.3-apache': '/tmp/images/8.0.0-rc.1/7.3-apache', - '8.0.0-rc.1-7.4-fpm': '/tmp/images/8.0.0-rc.1/7.4-fpm', - '8.0.0-rc.1-7.4-apache': '/tmp/images/8.0.0-rc.1/7.4-apache', - '8.0.0-rc.1-8.0-fpm': '/tmp/images/8.0.0-rc.1/8.0-fpm', - '8.0.0-rc.1-8.0-apache': '/tmp/images/8.0.0-rc.1/8.0-apache', - '8.0.0-rc.1-8.1-fpm': '/tmp/images/8.0.0-rc.1/8.1-fpm', - '8.0.0-rc.1-8.1-apache': '/tmp/images/8.0.0-rc.1/8.1-apache', - '8.1.0-7.2-fpm': '/tmp/images/8.1.0/7.2-fpm', - '8.1.0-7.2-apache': '/tmp/images/8.1.0/7.2-apache', - '8.1.0-7.3-fpm': '/tmp/images/8.1.0/7.3-fpm', - '8.1.0-7.3-apache': '/tmp/images/8.1.0/7.3-apache', - '8.1.0-7.4-fpm': '/tmp/images/8.1.0/7.4-fpm', - '8.1.0-7.4-apache': '/tmp/images/8.1.0/7.4-apache', - '8.1.0-8.0-fpm': '/tmp/images/8.1.0/8.0-fpm', - '8.1.0-8.0-apache': '/tmp/images/8.1.0/8.0-apache', - '8.1.0-8.1-fpm': '/tmp/images/8.1.0/8.1-fpm', - '8.1.0-8.1-apache': '/tmp/images/8.1.0/8.1-apache', - '8.1.0-7.2-fpm': '/tmp/images/8.1.0/7.2-fpm', - '8.1.3-7.2-fpm': '/tmp/images/8.1.3/7.2-fpm', - '8.1.3-7.2-apache': '/tmp/images/8.1.3/7.2-apache', - '8.1.3-7.3-fpm': '/tmp/images/8.1.3/7.3-fpm', - '8.1.3-7.3-apache': '/tmp/images/8.1.3/7.3-apache', - '8.1.3-7.4-fpm': '/tmp/images/8.1.3/7.4-fpm', - '8.1.3-7.4-apache': '/tmp/images/8.1.3/7.4-apache', - '8.1.3-8.0-fpm': '/tmp/images/8.1.3/8.0-fpm', - '8.1.3-8.0-apache': '/tmp/images/8.1.3/8.0-apache', - '8.1.3-8.1-fpm': '/tmp/images/8.1.3/8.1-fpm', - '8.1.3-8.1-apache': '/tmp/images/8.1.3/8.1-apache', - 'nightly-7.1-fpm': '/tmp/images/nightly/7.1-fpm', - 'nightly-7.1-apache': '/tmp/images/nightly/7.1-apache' + manager_versions = self.version_manager.get_versions() + expected_versions = { + '1.7.5.0-5.6-fpm': '/tmp/images/1.7.5.0/5.6-fpm', + '1.7.5.0-5.6-apache': '/tmp/images/1.7.5.0/5.6-apache', + '1.7.5.0-5.4-fpm': '/tmp/images/1.7.5.0/5.4-fpm', + '1.7.5.0-5.4-apache': '/tmp/images/1.7.5.0/5.4-apache', + '1.7.5.1-5.6-fpm': '/tmp/images/1.7.5.1/5.6-fpm', + '1.7.5.1-5.6-apache': '/tmp/images/1.7.5.1/5.6-apache', + '1.7.5.1-5.4-fpm': '/tmp/images/1.7.5.1/5.4-fpm', + '1.7.5.1-5.4-apache': '/tmp/images/1.7.5.1/5.4-apache', + '1.7.6.4-5.6-fpm': '/tmp/images/1.7.6.4/5.6-fpm', + '1.7.6.4-5.6-apache': '/tmp/images/1.7.6.4/5.6-apache', + '1.7.6.4-7.1-fpm': '/tmp/images/1.7.6.4/7.1-fpm', + '1.7.6.4-7.1-apache': '/tmp/images/1.7.6.4/7.1-apache', + '1.7.6.5-5.6-fpm': '/tmp/images/1.7.6.5/5.6-fpm', + '1.7.6.5-5.6-apache': '/tmp/images/1.7.6.5/5.6-apache', + '1.7.6.5-7.1-fpm': '/tmp/images/1.7.6.5/7.1-fpm', + '1.7.6.5-7.1-apache': '/tmp/images/1.7.6.5/7.1-apache', + '1.7.6.8-5.6-fpm': '/tmp/images/1.7.6.8/5.6-fpm', + '1.7.6.8-5.6-apache': '/tmp/images/1.7.6.8/5.6-apache', + '1.7.6.8-7.1-fpm': '/tmp/images/1.7.6.8/7.1-fpm', + '1.7.6.8-7.1-apache': '/tmp/images/1.7.6.8/7.1-apache', + '1.7.6.8-7.2-fpm': '/tmp/images/1.7.6.8/7.2-fpm', + '1.7.6.8-7.2-apache': '/tmp/images/1.7.6.8/7.2-apache', + '1.7.6.24-5.6-fpm': '/tmp/images/1.7.6.24/5.6-fpm', + '1.7.6.24-5.6-apache': '/tmp/images/1.7.6.24/5.6-apache', + '1.7.6.24-7.1-fpm': '/tmp/images/1.7.6.24/7.1-fpm', + '1.7.6.24-7.1-apache': '/tmp/images/1.7.6.24/7.1-apache', + '1.7.6.24-7.2-fpm': '/tmp/images/1.7.6.24/7.2-fpm', + '1.7.6.24-7.2-apache': '/tmp/images/1.7.6.24/7.2-apache', + '1.7.6.x-5.6-fpm': '/tmp/images/1.7.6.x/5.6-fpm', + '1.7.6.x-5.6-apache': '/tmp/images/1.7.6.x/5.6-apache', + '1.7.6.x-7.1-fpm': '/tmp/images/1.7.6.x/7.1-fpm', + '1.7.6.x-7.1-apache': '/tmp/images/1.7.6.x/7.1-apache', + '1.7.6.x-7.2-fpm': '/tmp/images/1.7.6.x/7.2-fpm', + '1.7.6.x-7.2-apache': '/tmp/images/1.7.6.x/7.2-apache', + '1.7.7.0-rc.1-7.1-fpm': '/tmp/images/1.7.7.0-rc.1/7.1-fpm', + '1.7.7.0-rc.1-7.1-apache': '/tmp/images/1.7.7.0-rc.1/7.1-apache', + '1.7.7.0-rc.1-7.2-fpm': '/tmp/images/1.7.7.0-rc.1/7.2-fpm', + '1.7.7.0-rc.1-7.2-apache': '/tmp/images/1.7.7.0-rc.1/7.2-apache', + '1.7.7.0-rc.1-7.3-fpm': '/tmp/images/1.7.7.0-rc.1/7.3-fpm', + '1.7.7.0-rc.1-7.3-apache': '/tmp/images/1.7.7.0-rc.1/7.3-apache', + '8.0.0-7.2-fpm': '/tmp/images/8.0.0/7.2-fpm', + '8.0.0-7.2-apache': '/tmp/images/8.0.0/7.2-apache', + '8.0.0-7.3-fpm': '/tmp/images/8.0.0/7.3-fpm', + '8.0.0-7.3-apache': '/tmp/images/8.0.0/7.3-apache', + '8.0.0-7.4-fpm': '/tmp/images/8.0.0/7.4-fpm', + '8.0.0-7.4-apache': '/tmp/images/8.0.0/7.4-apache', + '8.0.0-8.0-fpm': '/tmp/images/8.0.0/8.0-fpm', + '8.0.0-8.0-apache': '/tmp/images/8.0.0/8.0-apache', + '8.0.0-8.1-fpm': '/tmp/images/8.0.0/8.1-fpm', + '8.0.0-8.1-apache': '/tmp/images/8.0.0/8.1-apache', + '8.0.0-rc.1-7.2-fpm': '/tmp/images/8.0.0-rc.1/7.2-fpm', + '8.0.0-rc.1-7.2-apache': '/tmp/images/8.0.0-rc.1/7.2-apache', + '8.0.0-rc.1-7.3-fpm': '/tmp/images/8.0.0-rc.1/7.3-fpm', + '8.0.0-rc.1-7.3-apache': '/tmp/images/8.0.0-rc.1/7.3-apache', + '8.0.0-rc.1-7.4-fpm': '/tmp/images/8.0.0-rc.1/7.4-fpm', + '8.0.0-rc.1-7.4-apache': '/tmp/images/8.0.0-rc.1/7.4-apache', + '8.0.0-rc.1-8.0-fpm': '/tmp/images/8.0.0-rc.1/8.0-fpm', + '8.0.0-rc.1-8.0-apache': '/tmp/images/8.0.0-rc.1/8.0-apache', + '8.0.0-rc.1-8.1-fpm': '/tmp/images/8.0.0-rc.1/8.1-fpm', + '8.0.0-rc.1-8.1-apache': '/tmp/images/8.0.0-rc.1/8.1-apache', + '8.1.0-7.2-fpm': '/tmp/images/8.1.0/7.2-fpm', + '8.1.0-7.2-apache': '/tmp/images/8.1.0/7.2-apache', + '8.1.0-7.3-fpm': '/tmp/images/8.1.0/7.3-fpm', + '8.1.0-7.3-apache': '/tmp/images/8.1.0/7.3-apache', + '8.1.0-7.4-fpm': '/tmp/images/8.1.0/7.4-fpm', + '8.1.0-7.4-apache': '/tmp/images/8.1.0/7.4-apache', + '8.1.0-8.0-fpm': '/tmp/images/8.1.0/8.0-fpm', + '8.1.0-8.0-apache': '/tmp/images/8.1.0/8.0-apache', + '8.1.0-8.1-fpm': '/tmp/images/8.1.0/8.1-fpm', + '8.1.0-8.1-apache': '/tmp/images/8.1.0/8.1-apache', + '8.1.0-7.2-fpm': '/tmp/images/8.1.0/7.2-fpm', + '8.1.3-7.2-fpm': '/tmp/images/8.1.3/7.2-fpm', + '8.1.3-7.2-apache': '/tmp/images/8.1.3/7.2-apache', + '8.1.3-7.3-fpm': '/tmp/images/8.1.3/7.3-fpm', + '8.1.3-7.3-apache': '/tmp/images/8.1.3/7.3-apache', + '8.1.3-7.4-fpm': '/tmp/images/8.1.3/7.4-fpm', + '8.1.3-7.4-apache': '/tmp/images/8.1.3/7.4-apache', + '8.1.3-8.0-fpm': '/tmp/images/8.1.3/8.0-fpm', + '8.1.3-8.0-apache': '/tmp/images/8.1.3/8.0-apache', + '8.1.3-8.1-fpm': '/tmp/images/8.1.3/8.1-fpm', + '8.1.3-8.1-apache': '/tmp/images/8.1.3/8.1-apache', + '8.1.x-7.2-fpm': '/tmp/images/8.1.x/7.2-fpm', + '8.1.x-7.2-apache': '/tmp/images/8.1.x/7.2-apache', + '8.1.x-7.3-fpm': '/tmp/images/8.1.x/7.3-fpm', + '8.1.x-7.3-apache': '/tmp/images/8.1.x/7.3-apache', + '8.1.x-7.4-fpm': '/tmp/images/8.1.x/7.4-fpm', + '8.1.x-7.4-apache': '/tmp/images/8.1.x/7.4-apache', + '8.1.x-8.0-fpm': '/tmp/images/8.1.x/8.0-fpm', + '8.1.x-8.0-apache': '/tmp/images/8.1.x/8.0-apache', + '8.1.x-8.1-fpm': '/tmp/images/8.1.x/8.1-fpm', + '8.1.x-8.1-apache': '/tmp/images/8.1.x/8.1-apache', + '9.0.x-8.1-fpm': '/tmp/images/9.0.x/8.1-fpm', + '9.0.x-8.1-apache': '/tmp/images/9.0.x/8.1-apache', + '9.0.x-8.2-fpm': '/tmp/images/9.0.x/8.2-fpm', + '9.0.x-8.2-apache': '/tmp/images/9.0.x/8.2-apache', + '9.0.x-8.3-fpm': '/tmp/images/9.0.x/8.3-fpm', + '9.0.x-8.3-apache': '/tmp/images/9.0.x/8.3-apache', + 'nightly-7.1-fpm': '/tmp/images/nightly/7.1-fpm', + 'nightly-7.1-apache': '/tmp/images/nightly/7.1-apache', + } + # Useful for debug + # pprint.pp(manager_versions) + # pprint.pp(expected_versions) + # diff = list(set(manager_versions) - set(expected_versions)) + # print(diff) + + self.assertEqual(expected_versions, manager_versions) + @patch('prestashop_docker.version_manager.VERSIONS', all_versions) + def test_get_ps_versions_aliases(self): + expected_versions_aliases = { + '1.7': { + 'version': semver.VersionInfo(7, 6, 24), 'value': '1.7.6.24' }, + '1.7.5': { + 'version': semver.VersionInfo(7, 5, 1), 'value': '1.7.5.1' + }, + '1.7.5.1': { + 'version': semver.VersionInfo(7, 5, 1), 'value': '1.7.5.1' + }, + 'latest': { + 'version': semver.VersionInfo(8, 1, 3), 'value': '8.1.3' + }, + '1.7.6': { + 'version': semver.VersionInfo(7, 6, 24), 'value': '1.7.6.24' + }, + '1.7.6.4': { + 'version': semver.VersionInfo(7, 6, 4), 'value': '1.7.6.4' + }, + '1.7.6.5': { + 'version': semver.VersionInfo(7, 6, 5), 'value': '1.7.6.5' + }, + '1.7.6.8': { + 'version': semver.VersionInfo(7, 6, 8), 'value': '1.7.6.8' + }, + '1.7.6.24': { + 'version': semver.VersionInfo(7, 6, 24), 'value': '1.7.6.24' + }, + '1.7.6.x': { + 'value': '1.7.6.x' + }, + '1.7.7.0-rc.1': { + 'value': '1.7.7.0-rc.1' + }, + '8': { + 'version': semver.VersionInfo(8, 1, 3), 'value': '8.1.3' + }, + '8.0': { + 'version': semver.VersionInfo(8, 0, 0), 'value': '8.0.0' + }, + '8.0.0': { + 'version': semver.VersionInfo(8, 0, 0), 'value': '8.0.0' + }, + '8.0.0-rc.1': { + 'value': '8.0.0-rc.1' + }, + '8.1': { + 'version': semver.VersionInfo(8, 1, 3), 'value': '8.1.3' + }, + '8.1.0': { + 'version': semver.VersionInfo(8, 1, 0), 'value': '8.1.0' + }, + '8.1.3': { + 'version': semver.VersionInfo(8, 1, 3), 'value': '8.1.3' + }, + '8.1.x': { + 'value': '8.1.x' + }, + '9.0.x': { + 'value': '9.0.x' + }, + 'nightly': { + 'value': 'nightly' + }, + } + manager_versions_aliases = self.version_manager.get_ps_versions_aliases() + # Useful for debug + # pprint.pp(manager_versions_aliases) + # pprint.pp(expected_versions_aliases) - self.version_manager.get_versions(), - ) + self.assertEqual(expected_versions_aliases, manager_versions_aliases) @patch('prestashop_docker.version_manager.VERSIONS', all_versions) def test_get_aliases(self): + expected_aliases = { + '1.7.6.24-5.6-apache': ['1.7-5.6', '1.7.6-5.6', '1.7.6.24-5.6'], + '1.7.6.24-7.1-apache': ['1.7-7.1', '1.7.6-7.1', '1.7.6.24-7.1'], + '1.7.6.24-7.2-apache': [ + '1.7-7.2', + '1.7', + '1.7-apache', + '1.7.6-7.2', + '1.7.6', + '1.7.6-apache', + '1.7.6.24-7.2', + '1.7.6.24', + '1.7.6.24-apache', + ], + '1.7.6.24-7.2-fpm': ['1.7-fpm', '1.7.6-fpm', '1.7.6.24-fpm'], + '1.7.6.8-5.6-apache': ['1.7.6.8-5.6'], + '1.7.6.8-7.1-apache': ['1.7.6.8-7.1'], + '1.7.6.8-7.2-apache': ['1.7.6.8-7.2', '1.7.6.8', '1.7.6.8-apache'], + '1.7.6.8-7.2-fpm': ['1.7.6.8-fpm'], + '1.7.6.x-5.6-apache': ['1.7.6.x-5.6'], + '1.7.6.x-7.1-apache': ['1.7.6.x-7.1'], + '1.7.6.x-7.2-apache': ['1.7.6.x-7.2', '1.7.6.x', '1.7.6.x-apache'], + '1.7.6.x-7.2-fpm': ['1.7.6.x-fpm'], + '1.7.5.1-5.6-apache': [ + '1.7.5-5.6', + '1.7.5', + '1.7.5-apache', + '1.7.5.1-5.6', + '1.7.5.1', + '1.7.5.1-apache', + ], + '1.7.5.1-5.4-apache': ['1.7.5-5.4', '1.7.5.1-5.4'], + '1.7.5.1-5.6-fpm': ['1.7.5-fpm', '1.7.5.1-fpm'], + '1.7.6.4-5.6-apache': ['1.7.6.4-5.6'], + '1.7.6.4-7.1-apache': ['1.7.6.4-7.1', '1.7.6.4', '1.7.6.4-apache'], + '1.7.6.4-7.1-fpm': ['1.7.6.4-fpm'], + '1.7.6.5-5.6-apache': ['1.7.6.5-5.6'], + '1.7.6.5-7.1-apache': ['1.7.6.5-7.1', '1.7.6.5', '1.7.6.5-apache'], + '1.7.6.5-7.1-fpm': ['1.7.6.5-fpm'], + '1.7.7.0-rc.1-7.1-apache': ['1.7.7.0-rc.1-7.1'], + '1.7.7.0-rc.1-7.2-apache': ['1.7.7.0-rc.1-7.2'], + '1.7.7.0-rc.1-7.3-apache': [ + '1.7.7.0-rc.1-7.3', + '1.7.7.0-rc.1', + '1.7.7.0-rc.1-apache', + ], + '1.7.7.0-rc.1-7.3-fpm': ['1.7.7.0-rc.1-fpm'], + '8.0.0-7.2-apache': ['8.0-7.2', '8.0.0-7.2'], + '8.0.0-7.3-apache': ['8.0-7.3', '8.0.0-7.3'], + '8.0.0-7.4-apache': ['8.0-7.4', '8.0.0-7.4'], + '8.0.0-8.0-apache': ['8.0-8.0', '8.0.0-8.0'], + '8.0.0-8.1-apache': [ + '8.0-8.1', + '8.0', + '8.0-apache', + '8.0.0-8.1', + '8.0.0', + '8.0.0-apache' + ], + '8.0.0-8.1-fpm': ['8.0-fpm', '8.0.0-fpm'], + '8.0.0-rc.1-7.2-apache': ['8.0.0-rc.1-7.2'], + '8.0.0-rc.1-7.3-apache': ['8.0.0-rc.1-7.3'], + '8.0.0-rc.1-7.4-apache': ['8.0.0-rc.1-7.4'], + '8.0.0-rc.1-8.0-apache': ['8.0.0-rc.1-8.0'], + '8.0.0-rc.1-8.1-apache': [ + '8.0.0-rc.1-8.1', + '8.0.0-rc.1', + '8.0.0-rc.1-apache' + ], + '8.0.0-rc.1-8.1-fpm': ['8.0.0-rc.1-fpm'], + '8.1.0-7.2-apache': ['8.1.0-7.2'], + '8.1.0-7.3-apache': ['8.1.0-7.3'], + '8.1.0-7.4-apache': ['8.1.0-7.4'], + '8.1.0-8.0-apache': ['8.1.0-8.0'], + '8.1.0-8.1-apache': ['8.1.0-8.1', '8.1.0', '8.1.0-apache'], + '8.1.0-8.1-fpm': ['8.1.0-fpm'], + '8.1.3-7.2-apache': ['8-7.2', '8.1-7.2', '8.1.3-7.2'], + '8.1.3-7.3-apache': ['8-7.3', '8.1-7.3', '8.1.3-7.3'], + '8.1.3-7.4-apache': ['8-7.4', '8.1-7.4', '8.1.3-7.4'], + '8.1.3-8.0-apache': ['8-8.0', '8.1-8.0', '8.1.3-8.0'], + '8.1.3-8.1-apache': [ + 'latest', + '8-8.1', + '8', + '8-apache', + '8.1-8.1', + '8.1', + '8.1-apache', + '8.1.3-8.1', + '8.1.3', + '8.1.3-apache', + ], + '8.1.3-8.1-fpm': ['8-fpm', '8.1-fpm', '8.1.3-fpm'], + '8.1.x-7.2-apache': ['8.1.x-7.2'], + '8.1.x-7.3-apache': ['8.1.x-7.3'], + '8.1.x-7.4-apache': ['8.1.x-7.4'], + '8.1.x-8.0-apache': ['8.1.x-8.0'], + '8.1.x-8.1-apache': ['8.1.x-8.1', '8.1.x', '8.1.x-apache'], + '8.1.x-8.1-fpm': ['8.1.x-fpm'], + '9.0.x-8.1-apache': ['9.0.x-8.1'], + '9.0.x-8.2-apache': ['9.0.x-8.2'], + '9.0.x-8.3-apache': ['9.0.x-8.3', '9.0.x', '9.0.x-apache'], + '9.0.x-8.3-fpm': ['9.0.x-fpm'], + 'nightly-7.1-apache': ['nightly-7.1', 'nightly', 'nightly-apache'], + 'nightly-7.1-fpm': ['nightly-fpm'], + } + manager_aliases = self.version_manager.get_aliases() + # Useful for debug + # print('### manager') + # pprint.pp(manager_aliases) + # print('### expected') + # pprint.pp(expected_aliases) + # diff = list(set(manager_aliases) - set(expected_aliases)) + # print(diff) + self.assertEqual( - { - '1.7.6.8-5.6-apache': ['1.7-5.6', '1.7.6-5.6', '1.7.6.8-5.6'], - '1.7.6.8-7.1-apache': ['1.7-7.1', '1.7.6-7.1', '1.7.6.8-7.1'], - '1.7.6.8-7.2-apache': [ - '1.7-7.2', - '1.7', - '1.7-apache', - '1.7.6-7.2', - '1.7.6', - '1.7.6-apache', - '1.7.6.8-7.2', - '1.7.6.8', - '1.7.6.8-apache', - ], - '1.7.6.8-7.2-fpm': ['1.7-fpm', '1.7.6-fpm', '1.7.6.8-fpm'], - '1.7.5.1-5.6-apache': [ - '1.7.5-5.6', - '1.7.5', - '1.7.5-apache', - '1.7.5.1-5.6', - '1.7.5.1', - '1.7.5.1-apache', - ], - '1.7.5.1-5.4-apache': ['1.7.5-5.4', '1.7.5.1-5.4'], - '1.7.5.1-5.6-fpm': ['1.7.5-fpm', '1.7.5.1-fpm'], - '1.7.6.4-5.6-apache': ['1.7.6.4-5.6'], - '1.7.6.4-7.1-apache': ['1.7.6.4-7.1', '1.7.6.4', '1.7.6.4-apache'], - '1.7.6.4-7.1-fpm': ['1.7.6.4-fpm'], - '1.7.6.5-5.6-apache': ['1.7.6.5-5.6'], - '1.7.6.5-7.1-apache': ['1.7.6.5-7.1', '1.7.6.5', '1.7.6.5-apache'], - '1.7.6.5-7.1-fpm': ['1.7.6.5-fpm'], - '1.7.7.0-rc.1-7.1-apache': ['1.7.7.0-rc.1-7.1'], - '1.7.7.0-rc.1-7.2-apache': ['1.7.7.0-rc.1-7.2'], - '1.7.7.0-rc.1-7.3-apache': [ - '1.7.7.0-rc.1-7.3', - '1.7.7.0-rc.1', - '1.7.7.0-rc.1-apache', - ], - '1.7.7.0-rc.1-7.3-fpm': ['1.7.7.0-rc.1-fpm'], - '8.0.0-7.2-apache': ['8.0-7.2', '8.0.0-7.2'], - '8.0.0-7.3-apache': ['8.0-7.3', '8.0.0-7.3'], - '8.0.0-7.4-apache': ['8.0-7.4', '8.0.0-7.4'], - '8.0.0-8.0-apache': ['8.0-8.0', '8.0.0-8.0'], - '8.0.0-8.1-apache': [ - '8.0-8.1', - '8.0', - '8.0-apache', - '8.0.0-8.1', - '8.0.0', - '8.0.0-apache' - ], - '8.0.0-8.1-fpm': ['8.0-fpm', '8.0.0-fpm'], - '8.0.0-rc.1-7.2-apache': ['8.0.0-rc.1-7.2'], - '8.0.0-rc.1-7.3-apache': ['8.0.0-rc.1-7.3'], - '8.0.0-rc.1-7.4-apache': ['8.0.0-rc.1-7.4'], - '8.0.0-rc.1-8.0-apache': ['8.0.0-rc.1-8.0'], - '8.0.0-rc.1-8.1-apache': [ - '8.0.0-rc.1-8.1', - '8.0.0-rc.1', - '8.0.0-rc.1-apache' - ], - '8.0.0-rc.1-8.1-fpm': ['8.0.0-rc.1-fpm'], - '8.1.0-7.2-apache': ['8.1.0-7.2'], - '8.1.0-7.3-apache': ['8.1.0-7.3'], - '8.1.0-7.4-apache': ['8.1.0-7.4'], - '8.1.0-8.0-apache': ['8.1.0-8.0'], - '8.1.0-8.1-apache': ['8.1.0-8.1', '8.1.0', '8.1.0-apache'], - '8.1.0-8.1-fpm': ['8.1.0-fpm'], - '8.1.3-7.2-apache': ['8-7.2', '8.1-7.2', '8.1.3-7.2'], - '8.1.3-7.3-apache': ['8-7.3', '8.1-7.3', '8.1.3-7.3'], - '8.1.3-7.4-apache': ['8-7.4', '8.1-7.4', '8.1.3-7.4'], - '8.1.3-8.0-apache': ['8-8.0', '8.1-8.0', '8.1.3-8.0'], - '8.1.3-8.1-apache': [ - 'latest', - '8-8.1', - '8', - '8-apache', - '8.1-8.1', - '8.1', - '8.1-apache', - '8.1.3-8.1', - '8.1.3', - '8.1.3-apache', - ], - '8.1.3-8.1-fpm': ['8-fpm', '8.1-fpm', '8.1.3-fpm'], - 'nightly-7.1-apache': ['nightly-7.1', 'nightly', 'nightly-apache'], - 'nightly-7.1-fpm': ['nightly-fpm'], - }, - self.version_manager.get_aliases(), + expected_aliases, + manager_aliases, ) From 568b28d116aabe2cfc722d43bc40e4dc1728138c Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Mon, 4 Nov 2024 17:22:43 +0100 Subject: [PATCH 2/3] Improve generator to use VersionManager and improve its tests --- Dockerfile-branch.model | 2 +- prestashop_docker/generator.py | 22 +++++- tests/prestashop_docker/test_generator.py | 93 ++++++++++++++++++----- 3 files changed, 91 insertions(+), 26 deletions(-) diff --git a/Dockerfile-branch.model b/Dockerfile-branch.model index 5cd6ff87..4c812ea7 100644 --- a/Dockerfile-branch.model +++ b/Dockerfile-branch.model @@ -4,6 +4,6 @@ LABEL maintainer="PrestaShop Core Team " RUN apt update RUN apt -y install git -RUN git clone -b $ps_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps +RUN git clone -b $branch_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps CMD ["/tmp/docker_run.sh"] diff --git a/prestashop_docker/generator.py b/prestashop_docker/generator.py index b272e19a..38abfc32 100644 --- a/prestashop_docker/generator.py +++ b/prestashop_docker/generator.py @@ -3,6 +3,7 @@ from string import Template from packaging import version from . import CONTAINERS +from prestashop_docker.version_manager import VersionManager class Generator: @@ -27,6 +28,7 @@ def __init__(self, directory_path, template, nightly_template, branch_template): self.template = Template(template) self.nightly_template = Template(nightly_template) self.branch_template = Template(branch_template) + self.version_manager = VersionManager(directory_path) def create_directory(self, directory_path): """Try to create a directory if it's possible @@ -58,16 +60,27 @@ def generate_image(self, ps_version, container_version): self.create_directory(directory_path) file_path = path.join(directory_path, 'Dockerfile') + parsed_version = self.version_manager.get_version_from_string(ps_version) + split_version = self.version_manager.split_prestashop_version(ps_version) + template = self.nightly_template if ( ps_version == self.NIGHTLY ) else self.branch_template if ( - ps_version.endswith('.x') + split_version is not None and split_version['patch'] == 'x' ) else self.template + # Get valid PS version (for branch versions it returns to future next patch) + ps_version = parsed_version['ps_version'] + branch_version = parsed_version['branch_version'] + with open(file_path, 'w+') as f: - # We use 1.7.8.8 as the comparison base because the 1.7.8.9 is not hosted on the .com anymore but until 1.7.8.8 it still works, - # however we can't use 8.0 as the base because 8.0.0-beta is lower than 8.0 and we need beta versions of 8 to use the new url - if version.parse(ps_version) > version.parse('1.7.8.8'): + use_github_url = True + # We use 1.7.8.8 as the comparison base because the 1.7.8.9 is not hosted on the .com anymore but until 1.7.8.8, + # it still works so the .com url is used + if split_version is not None and split_version['major'] == '1.7' and version.parse(ps_version) <= version.parse('1.7.8.8'): + use_github_url = False + + if use_github_url: ps_url = self.download_url_github.format(ps_version, ps_version) else: ps_url = self.download_url.format(ps_version) @@ -75,6 +88,7 @@ def generate_image(self, ps_version, container_version): template.substitute( { 'ps_version': ps_version, + 'branch_version': branch_version, 'container_version': container_version, 'ps_url': ps_url } diff --git a/tests/prestashop_docker/test_generator.py b/tests/prestashop_docker/test_generator.py index 61a22955..40202b4c 100644 --- a/tests/prestashop_docker/test_generator.py +++ b/tests/prestashop_docker/test_generator.py @@ -29,7 +29,7 @@ def setUp(self): contents=''' CONTAINER_VERSION: $container_version RUN apt -y install git - RUN git clone -b $ps_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps + RUN git clone -b $branch_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps ''' ) @@ -46,10 +46,10 @@ def test_create_directory(self): self.assertTrue(path.exists('/tmp/images/test')) def test_generate_image(self): - dockerfile = '/tmp/images/1.7.8/7.4-alpine/Dockerfile' + dockerfile = '/tmp/images/1.7.8.0/7.4-alpine/Dockerfile' self.assertFalse(path.exists(dockerfile)) self.generator.generate_image( - '1.7.8', + '1.7.8.0', '7.4-alpine' ) self.assertTrue(path.exists(dockerfile)) @@ -58,17 +58,55 @@ def test_generate_image(self): content = f.read() self.assertIn( 'PS_URL: https://www.prestashop.com/download/old/' - 'prestashop_1.7.8.zip', + 'prestashop_1.7.8.0.zip', content ) - self.assertIn('PS_VERSION: 1.7.8', content) + self.assertIn('PS_VERSION: 1.7.8.0', content) + self.assertIn('CONTAINER_VERSION: 7.4-alpine', content) + + def test_generate_image_1788(self): + dockerfile = '/tmp/images/1.7.8.8/7.4-alpine/Dockerfile' + self.assertFalse(path.exists(dockerfile)) + self.generator.generate_image( + '1.7.8.8', + '7.4-alpine' + ) + self.assertTrue(path.exists(dockerfile)) + + with open(dockerfile) as f: + content = f.read() + self.assertIn( + 'PS_URL: https://www.prestashop.com/download/old/' + 'prestashop_1.7.8.8.zip', + content + ) + self.assertIn('PS_VERSION: 1.7.8.8', content) + self.assertIn('CONTAINER_VERSION: 7.4-alpine', content) + + def test_generate_image_1789(self): + dockerfile = '/tmp/images/1.7.8.9/7.4-alpine/Dockerfile' + self.assertFalse(path.exists(dockerfile)) + self.generator.generate_image( + '1.7.8.9', + '7.4-alpine' + ) + self.assertTrue(path.exists(dockerfile)) + + with open(dockerfile) as f: + content = f.read() + self.assertIn( + 'PS_URL: https://github.com/PrestaShop/PrestaShop/releases/download/1.7.8.9/' + 'prestashop_1.7.8.9.zip', + content + ) + self.assertIn('PS_VERSION: 1.7.8.9', content) self.assertIn('CONTAINER_VERSION: 7.4-alpine', content) def test_generate_image_80(self): - dockerfile = '/tmp/images/8.0/7.4-alpine/Dockerfile' + dockerfile = '/tmp/images/8.0.0/7.4-alpine/Dockerfile' self.assertFalse(path.exists(dockerfile)) self.generator.generate_image( - '8.0', + '8.0.0', '7.4-alpine' ) self.assertTrue(path.exists(dockerfile)) @@ -76,11 +114,11 @@ def test_generate_image_80(self): with open(dockerfile) as f: content = f.read() self.assertIn( - 'PS_URL: https://github.com/PrestaShop/PrestaShop/releases/download/8.0/' - 'prestashop_8.0.zip', + 'PS_URL: https://github.com/PrestaShop/PrestaShop/releases/download/8.0.0/' + 'prestashop_8.0.0.zip', content ) - self.assertIn('PS_VERSION: 8.0', content) + self.assertIn('PS_VERSION: 8.0.0', content) self.assertIn('CONTAINER_VERSION: 7.4-alpine', content) def test_generate_nightly_image(self): @@ -116,29 +154,42 @@ def test_generate_branch_image(self): 'PS_URL', content ) - self.assertNotIn('PS_VERSION', content) self.assertIn('CONTAINER_VERSION: 8.1-alpine', content) self.assertIn('RUN apt -y install git', content) self.assertIn('RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps', content) def test_generate_all(self): files = ( - '/tmp/images/7.0/7.3-apache/Dockerfile', - '/tmp/images/7.0/7.3-fpm/Dockerfile', - '/tmp/images/7.0/7.2-apache/Dockerfile', - '/tmp/images/7.0/7.2-fpm/Dockerfile', - '/tmp/images/8.0/7.1-apache/Dockerfile', - '/tmp/images/8.0/7.1-fpm/Dockerfile', - '/tmp/images/8.0/5.6-apache/Dockerfile', - '/tmp/images/8.0/5.6-fpm/Dockerfile', + '/tmp/images/1.7.8.8/7.3-apache/Dockerfile', + '/tmp/images/1.7.8.8/7.3-fpm/Dockerfile', + '/tmp/images/1.7.8.8/7.2-apache/Dockerfile', + '/tmp/images/1.7.8.8/7.2-fpm/Dockerfile', + '/tmp/images/8.0.0/7.2-apache/Dockerfile', + '/tmp/images/8.0.0/7.2-fpm/Dockerfile', + '/tmp/images/8.0.0/8.1-apache/Dockerfile', + '/tmp/images/8.0.0/8.1-fpm/Dockerfile', + '/tmp/images/9.0.x/8.1-apache/Dockerfile', + '/tmp/images/9.0.x/8.1-fpm/Dockerfile', + '/tmp/images/9.0.x/8.2-apache/Dockerfile', + '/tmp/images/9.0.x/8.2-fpm/Dockerfile', + '/tmp/images/9.0.x/8.3-apache/Dockerfile', + '/tmp/images/9.0.x/8.3-fpm/Dockerfile', + '/tmp/images/nightly/8.1-apache/Dockerfile', + '/tmp/images/nightly/8.1-fpm/Dockerfile', + '/tmp/images/nightly/8.2-apache/Dockerfile', + '/tmp/images/nightly/8.2-fpm/Dockerfile', + '/tmp/images/nightly/8.3-apache/Dockerfile', + '/tmp/images/nightly/8.3-fpm/Dockerfile', ) for f in files: self.assertFalse(path.exists(f)) self.generator.generate_all( { - '7.0': ('7.2', '7.3'), - '8.0': ('7.1', '5.6'), + '1.7.8.8': ('7.2', '7.3'), + '8.0.0': ('7.2', '8.1'), + '9.0.x': ('8.1', '8.2', '8.3'), + 'nightly': ('8.1', '8.2', '8.3'), } ) From 634b39db28ccb88c281b7a5f7454375eb550fedd Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Mon, 4 Nov 2024 17:23:06 +0100 Subject: [PATCH 3/3] Improve How to use to help running tests locally --- HOW-TO-USE.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/HOW-TO-USE.md b/HOW-TO-USE.md index 541d8b37..11a50499 100644 --- a/HOW-TO-USE.md +++ b/HOW-TO-USE.md @@ -70,3 +70,44 @@ docker compose up generate ``` This will create new folders for the new version you just added. + +## Running tests locally + +To run the python tests you need to install requirements + +```bash +$ pip install -r requirements.txt +``` + +Then you can run the tests: + +```bash +$ nosetests +``` + +Locally you may have an error like ``, running these commands may help running tests locally: + +```bash +$ pip uninstall -y nose +$ pip install -U nose --no-binary :all: +``` + +or alternatively: + +```bash +$ pip install nose-py3 +``` + +If you need to debug one specific test you first need to run + +``` +$ nosetests --with-id +``` + +This will execute tests and each test method will be assigned an ID that you can then use to filter it specifically: + +``` +$ nosetests --with-id 7 +``` + +This will also generate a `.nodeids` binary file, when you add new test methods you need to remove this file to re-generate the list of IDs.