Skip to content

Commit bc2aa3a

Browse files
committed
🐛 Fix tag rendering (#57)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description Tags were rendered wrongly for plugins in which format is changed for versions such as Golang ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent b5b9b48 commit bc2aa3a

File tree

7 files changed

+92
-32
lines changed

7 files changed

+92
-32
lines changed

continuous_delivery_scripts/plugins/ci.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""Plugin for CI projects."""
66
import logging
77
from pathlib import Path
8-
from typing import Optional, List
8+
from typing import Optional, Dict
99

1010
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1111
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
@@ -63,6 +63,6 @@ def should_clean_before_packaging(self) -> bool:
6363
"""States whether the repository must be cleaned before packaging happens."""
6464
return True
6565

66-
def tag_release(self, git: GitWrapper, version: str, shortcuts: List[str]) -> None:
66+
def tag_release(self, git: GitWrapper, version: str, shortcuts: Dict[str, bool]) -> None:
6767
"""Tags release commit."""
6868
super().tag_release(git, version, shortcuts)

continuous_delivery_scripts/plugins/golang.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77
import os
88
from pathlib import Path
9-
from typing import Optional, List
9+
from typing import Optional, List, Dict
1010
from subprocess import check_call
1111
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
1212
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
@@ -161,7 +161,7 @@ def should_clean_before_packaging(self) -> bool:
161161
"""States whether the repository must be cleaned before packaging happens."""
162162
return True
163163

164-
def tag_release(self, git: GitWrapper, version: str, shortcuts: List[str]) -> None:
164+
def tag_release(self, git: GitWrapper, version: str, shortcuts: Dict[str, bool]) -> None:
165165
"""Tags release commit."""
166166
super().tag_release(git, version, shortcuts)
167167
go_tag = _determine_go_module_tag(self.get_version_tag(version))

continuous_delivery_scripts/tag_and_release.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,16 @@ def _update_repository(
9999
if mode == CommitType.RELEASE:
100100
_commit_release_changes(git, version, commit_message)
101101
if is_new_version:
102-
get_language_specifics().tag_release(git, version, determine_version_shortcuts(mode, version_elements))
102+
get_language_specifics().tag_release(
103+
git,
104+
version,
105+
determine_version_shortcuts(
106+
mode,
107+
configuration.get_value(ConfigurationVariable.TAG_LATEST),
108+
configuration.get_value(ConfigurationVariable.TAG_VERSION_SHORTCUTS),
109+
version_elements,
110+
),
111+
)
103112
git.force_push_tag()
104113

105114

continuous_delivery_scripts/utils/language_specifics_base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88
from abc import ABC, abstractmethod
99
from pathlib import Path
10-
from typing import Optional, List
10+
from typing import Optional, Dict
1111

1212
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1313
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
@@ -74,15 +74,15 @@ def should_clean_before_packaging(self) -> bool:
7474
"""States whether the repository must be cleaned before packaging happens."""
7575
return False
7676

77-
def tag_release(self, git: GitWrapper, version: str, shortcuts: List[str]) -> None:
77+
def tag_release(self, git: GitWrapper, version: str, shortcuts: Dict[str, bool]) -> None:
7878
"""Tags release commit."""
7979
logger.info(f"Tagging commit as release {version}")
8080
git.create_tag(self.get_version_tag(version), message=f"release {version}")
81-
if configuration.get_value(ConfigurationVariable.TAG_LATEST):
82-
git.create_tag("latest", message="latest release")
83-
if configuration.get_value(ConfigurationVariable.TAG_VERSION_SHORTCUTS):
84-
for shortcut in shortcuts:
81+
for shortcut, version in shortcuts.items():
82+
if version:
8583
git.create_tag(self.get_version_tag(shortcut), message=f"{shortcut} release")
84+
else:
85+
git.create_tag(shortcut, message=shortcut)
8686

8787
@abstractmethod
8888
def generate_code_documentation(self, output_directory: Path, module_to_document: str) -> None:

continuous_delivery_scripts/utils/versioning.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88
import os
99
from auto_version import auto_version_tool
10-
from typing import Optional, Tuple, Dict, List
10+
from typing import Optional, Tuple, Dict
1111

1212
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
1313
from continuous_delivery_scripts.utils.definitions import CommitType
@@ -87,23 +87,36 @@ def determine_version_string(
8787
return new_version
8888

8989

90-
def determine_version_shortcuts(commit_type: CommitType, version_elements: Dict[str, str]) -> List[str]:
90+
def determine_version_shortcuts(
91+
commit_type: CommitType, tag_latest: bool, tag_shortcut: bool, version_elements: Dict[str, str]
92+
) -> Dict[str, bool]:
9193
"""Determine the different version shortcuts i.e. major, major.minor, pre depending on the release type.
9294
9395
Args:
9496
commit_type: commit type
97+
tag_latest: whether to tag release with `Latest`
98+
tag_shortcut: whether to set additional shortcuts
9599
version_elements: version elements
100+
101+
Returns:
102+
dict: A dictionary of shortcuts and a flag specifying
103+
whether it is a version string or bespoke shortcut such as latest
96104
"""
97-
shortcuts = []
105+
shortcuts = {}
106+
if commit_type == CommitType.RELEASE and tag_latest:
107+
shortcuts["latest"] = False
108+
if not tag_shortcut:
109+
return shortcuts
98110
major_version = version_elements.get(auto_version_tool.definitions.SemVerSigFig.major, None)
99111
if major_version:
100-
shortcuts.append(major_version)
112+
shortcuts[major_version] = True
101113
minor_version = version_elements.get(auto_version_tool.definitions.SemVerSigFig.minor, None)
102114
if minor_version and major_version:
103-
shortcuts.append(f"{major_version}.{minor_version}")
115+
shortcuts[f"{major_version}.{minor_version}"] = True
104116
if commit_type == CommitType.BETA:
105-
shortcuts.append(auto_version_tool.config.PRERELEASE_TOKEN)
117+
shortcuts[auto_version_tool.config.PRERELEASE_TOKEN] = False
106118
if commit_type == CommitType.DEVELOPMENT:
119+
shortcuts[auto_version_tool.config.BUILD_TOKEN] = False
107120
commit_count = version_elements.get(auto_version_tool.Constants.COMMIT_COUNT_FIELD, None)
108121
if not commit_count:
109122
with LocalProjectRepository() as git:
@@ -112,7 +125,7 @@ def determine_version_shortcuts(commit_type: CommitType, version_elements: Dict[
112125
if not commit_hash:
113126
with LocalProjectRepository() as git:
114127
commit_hash = git.get_commit_hash()
115-
shortcuts.append(f"{auto_version_tool.config.BUILD_TOKEN}.{commit_count}+{commit_hash}")
128+
shortcuts[f"{auto_version_tool.config.BUILD_TOKEN}.{commit_count}+{commit_hash}"] = False
116129

117130
return shortcuts
118131

news/20221221110243.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed shortcut tag rendering

tests/versioning/test_versioning.py

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,75 @@ def test_determine_version_string(self):
3333
self.assertGreaterEqual(len(determine_version_string(CommitType.DEVELOPMENT, "1.1.1", {})), len("1.1.1"))
3434

3535
def test_determine_version_shortcuts(self):
36-
self.assertListEqual(
37-
["1", "1.1"],
36+
self.assertDictEqual(
37+
{"1": True, "1.1": True},
3838
determine_version_shortcuts(
39-
CommitType.RELEASE, {definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"}
39+
CommitType.RELEASE,
40+
False,
41+
True,
42+
{definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"},
4043
),
4144
)
42-
self.assertListEqual(
43-
["1"], determine_version_shortcuts(CommitType.RELEASE, {definitions.SemVerSigFig.major: "1"})
45+
self.assertDictEqual(
46+
{"latest": False},
47+
determine_version_shortcuts(
48+
CommitType.RELEASE,
49+
True,
50+
False,
51+
{definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"},
52+
),
53+
)
54+
self.assertDictEqual(
55+
{},
56+
determine_version_shortcuts(
57+
CommitType.RELEASE,
58+
False,
59+
False,
60+
{definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"},
61+
),
62+
)
63+
self.assertDictEqual(
64+
{"1": True},
65+
determine_version_shortcuts(CommitType.RELEASE, False, True, {definitions.SemVerSigFig.major: "1"}),
66+
)
67+
self.assertDictEqual(
68+
{"1": True, "latest": False},
69+
determine_version_shortcuts(CommitType.RELEASE, True, True, {definitions.SemVerSigFig.major: "1"}),
70+
)
71+
self.assertDictEqual(
72+
{}, determine_version_shortcuts(CommitType.RELEASE, False, True, {definitions.SemVerSigFig.minor: "1"})
4473
)
45-
self.assertListEqual([], determine_version_shortcuts(CommitType.RELEASE, {definitions.SemVerSigFig.minor: "1"}))
46-
self.assertListEqual(
47-
["1", "1.1", config.PRERELEASE_TOKEN],
74+
self.assertDictEqual(
75+
{"1": True, "1.1": True, config.PRERELEASE_TOKEN: False},
4876
determine_version_shortcuts(
49-
CommitType.BETA, {definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"}
77+
CommitType.BETA, True, True, {definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"}
5078
),
5179
)
5280
self.assertTrue(
5381
"1.1"
5482
in determine_version_shortcuts(
55-
CommitType.DEVELOPMENT, {definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"}
56-
)
83+
CommitType.DEVELOPMENT,
84+
True,
85+
True,
86+
{definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"},
87+
).keys()
5788
)
5889
self.assertTrue(
5990
"1"
6091
in determine_version_shortcuts(
61-
CommitType.DEVELOPMENT, {definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"}
62-
)
92+
CommitType.DEVELOPMENT,
93+
True,
94+
True,
95+
{definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"},
96+
).keys()
6397
)
6498
self.assertGreaterEqual(
6599
len(
66100
determine_version_shortcuts(
67-
CommitType.DEVELOPMENT, {definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"}
101+
CommitType.DEVELOPMENT,
102+
True,
103+
True,
104+
{definitions.SemVerSigFig.major: "1", definitions.SemVerSigFig.minor: "1"},
68105
)
69106
),
70107
2,

0 commit comments

Comments
 (0)