From 27c4dcced7780e4f819f61f75e2484104e01d0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=C5=91d=20Ill=C3=A9s?= Date: Mon, 16 Jan 2023 19:12:51 +0100 Subject: [PATCH] Fix validator for std-with-versions For projects that has branch type 'std-with-versions' (like ironic, because they cut bugfix/. bugfix branches) the new stable branch name style (like stable/2023.1) does not pass validator. This patch extends the validator to accept these branch names, too. Change-Id: If597684b1a4ea741707ee786e8e01e9e8f3d2cb4 --- openstack_releases/cmds/validate.py | 19 +++++++++++---- openstack_releases/tests/test_validate.py | 28 +++++++++++++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index fd5aad28e6..1c1fc9fd96 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -1522,6 +1522,14 @@ def validate_branch_prefixes(deliv, context): branch.name, _VALID_BRANCH_PREFIXES)) +def _is_branch_with_release_id(branch_name): + "Check if stable branch name matches the new format, like stable/2023.1." + + prefix, branch_id = branch_name.split('/') + return (prefix == 'stable' and + re.search(r'^[0-9]{4}.[1-2]{1}$', branch_id, re.I) is not None) + + def validate_stable_branches(deliv, context): "Apply the rules for stable branches." @@ -1679,18 +1687,21 @@ def validate_stable_branches(deliv, context): if series != deliv.series: if branch_mode == 'std-with-versions': # Not a normal stable branch, so it must be a versioned - # bugfix branch (bugfix/3.1) + # bugfix branch (bugfix/3.1) or the new format of stable + # branches (for example: stable/2023.1) expected_version = '.'.join(location.split('.')[0:2]) - if series != expected_version: + if (series != expected_version and + not _is_branch_with_release_id(branch.name)): context.error( 'cycle-based projects must match series names ' 'for stable branches, or branch based on version ' 'for short term support. %s should be stable/%s ' - 'or bugfix/%s' % ( + 'or stable/. (for example: ' + 'stable/2023.1) or bugfix/%s' % ( branch.name, deliv.series, expected_version)) elif branch_mode == 'std': # Looking for SLURP naming (e.g: 2023.1) - if re.search(r'^[0-9]{4}.[1]{1}$', series, re.I) is None: + if not _is_branch_with_release_id(branch.name): context.error( 'cycle-based projects must match series names ' 'for stable branches. %s should be stable/%s ' diff --git a/openstack_releases/tests/test_validate.py b/openstack_releases/tests/test_validate.py index 5d53255cd5..fdf0579478 100644 --- a/openstack_releases/tests/test_validate.py +++ b/openstack_releases/tests/test_validate.py @@ -2024,7 +2024,7 @@ class TestValidateStableBranches(base.BaseTestCase): self.assertEqual(0, len(self.ctx.warnings)) self.assertEqual(1, len(self.ctx.errors)) - def test_stable_branch_slurp_formatted_name(self): + def test_std_branch_type_with_release_id(self): deliverable_data = textwrap.dedent(''' releases: - version: 99.0.3 @@ -2032,7 +2032,31 @@ class TestValidateStableBranches(base.BaseTestCase): - repo: openstack/release-test hash: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660 branches: - - name: stable/2023.1 + - name: stable/2022.2 + location: 99.0.3 + repository-settings: + openstack/release-test: {} + ''') + deliv = deliverable.Deliverable( + team='team', + series='antelope', + name='release-test', + data=yamlutils.loads(deliverable_data), + ) + validate.validate_stable_branches(deliv, self.ctx) + self.assertEqual(0, len(self.ctx.warnings)) + self.assertEqual(0, len(self.ctx.errors)) + + def test_std_with_versions_branch_type_with_release_id(self): + deliverable_data = textwrap.dedent(''' + stable-branch-type: std-with-versions + releases: + - version: 99.0.3 + projects: + - repo: openstack/release-test + hash: 0cd17d1ee3b9284d36b2a0d370b49a6f0bbb9660 + branches: + - name: stable/2022.2 location: 99.0.3 repository-settings: openstack/release-test: {}