Skip to content

Commit ea7e3b0

Browse files
committed
Add support to generate container tags based on given version input
Signed-off-by: Tobias Wolf <wolf@b1-systems.de> On-behalf-of: SAP <tobias.wolf@sap.com>
1 parent 4b0ed4f commit ea7e3b0

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/gardenlinux/features/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"cname",
2121
"cname_base",
2222
"container_name",
23+
"container_tag",
2324
"commit_id",
2425
"features",
2526
"platforms",
@@ -117,7 +118,7 @@ def main() -> None:
117118
if (
118119
version is None
119120
or version == ""
120-
and (args.type in ("cname", "commit_id", "version", "version_and_commit_id"))
121+
and (args.type in ("cname", "container_tag", "commit_id", "version", "version_and_commit_id"))
121122
):
122123
raise RuntimeError("Version not specified and no default version set")
123124

@@ -146,6 +147,8 @@ def main() -> None:
146147
print_output_from_cname(args.type, cname)
147148
elif args.type == "commit_id":
148149
print(commit_id_or_hash[:8])
150+
elif args.type == "container_tag":
151+
print(re.sub("\\W+", "-", f"{version}-{commit_id_or_hash[:8]}"))
149152
elif args.type == "version":
150153
print(version)
151154
elif args.type == "version_and_commit_id":

tests/features/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ def test_main_prints_container_name(monkeypatch, capsys):
160160
assert "container-python-dev" in out
161161

162162

163+
def test_main_prints_container_tag(monkeypatch, capsys):
164+
# Arrange
165+
argv = ["prog", "--arch", "amd64", "--cname", "flav", "--version", "1.0", "--commit", "~post1", "container_tag"]
166+
monkeypatch.setattr(sys, "argv", argv)
167+
monkeypatch.setattr(fema, "Parser", lambda *a, **kw: None)
168+
169+
# Act
170+
fema.main()
171+
172+
# Assert
173+
out = capsys.readouterr().out.strip()
174+
assert "1-0-post1" == out
175+
176+
163177
def test_main_prints_commit_id(monkeypatch, capsys):
164178
# Arrange
165179
argv = ["prog", "--arch", "amd64", "--cname", "flav", "commit_id"]

0 commit comments

Comments
 (0)