Skip to content

Commit 2e61e56

Browse files
committed
Add workaround to accept GL canonical names without a commit ID
Fixes: #302 Signed-off-by: Tobias Wolf <wolf@b1-systems.de> On-behalf-of: SAP <tobias.wolf@sap.com>
1 parent 7535722 commit 2e61e56

File tree

8 files changed

+60
-28
lines changed

8 files changed

+60
-28
lines changed

.github/actions/features_parse/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ outputs:
1111
runs:
1212
using: composite
1313
steps:
14-
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.10
14+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.11
1515
- id: result
1616
shell: bash
1717
run: |

.github/actions/flavors_parse/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ outputs:
1313
runs:
1414
using: composite
1515
steps:
16-
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.10
16+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.11
1717
- id: matrix
1818
shell: bash
1919
run: |

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Installs the given GardenLinux Python library
44
inputs:
55
version:
66
description: GardenLinux Python library version
7-
default: "0.10.10"
7+
default: "0.10.11"
88
python_version:
99
description: Python version to setup
1010
default: "3.13"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "gardenlinux"
3-
version = "0.10.10"
3+
version = "0.10.11"
44
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
55
authors = ["Garden Linux Maintainers <contact@gardenlinux.io>"]
66
license = "Apache-2.0"

src/gardenlinux/features/cname.py

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,46 @@ def __init__(
6969

7070
commit_id_or_hash = None
7171

72-
re_match = re.match(
73-
"([a-zA-Z0-9]+([\\_\\-][a-zA-Z0-9]+)*?)(-([a-z0-9]+)(-([a-z0-9.]+)-([a-z0-9]+))*)?$",
74-
cname,
72+
if version is not None:
73+
# Support version values formatted as <version>-<commit_hash>
74+
if commit_hash is None:
75+
re_match = re.match("([a-z0-9.]+)(-([a-z0-9]+))?$", version)
76+
assert re_match, f"Not a valid version {version}"
77+
78+
commit_id_or_hash = re_match[3]
79+
version = re_match[1]
80+
else:
81+
commit_id_or_hash = commit_hash
82+
83+
re_object = re.compile(
84+
"([a-zA-Z0-9]+([\\_\\-][a-zA-Z0-9]+)*?)(-([a-z0-9]+)(-([a-z0-9.]+)-([a-z0-9]+))*)?$"
7585
)
7686

87+
re_match = re_object.match(cname)
88+
89+
# Workaround Garden Linux canonical names without mandatory final commit hash
90+
if (
91+
not re_match
92+
and commit_id_or_hash
93+
and re.match(
94+
"([a-zA-Z0-9]+([\\_\\-][a-zA-Z0-9]+)*?)(-([a-z0-9]+)(-([a-z0-9.]+))*)?$",
95+
cname,
96+
)
97+
):
98+
re_match = re_object.match(f"{cname}-{commit_id_or_hash}")
99+
77100
assert re_match, f"Not a valid Garden Linux canonical name {cname}"
78101

79102
if re_match.lastindex == 1:
80103
self._flavor = re_match[1]
81104
else:
82-
commit_id_or_hash = re_match[7]
105+
if commit_id_or_hash is None:
106+
commit_id_or_hash = re_match[7]
107+
elif re_match.group(7) is not None:
108+
assert commit_id_or_hash.startswith(re_match[7]), (
109+
f"Mismatch between Garden Linux canonical name {cname} and given commit ID {commit_id_or_hash} detected"
110+
)
111+
83112
self._flavor = re_match[1]
84113
self._version = re_match[6]
85114

@@ -92,16 +121,7 @@ def __init__(
92121
self._arch = arch
93122

94123
if self._version is None and version is not None:
95-
# Support version values formatted as <version>-<commit_hash>
96-
if commit_hash is None:
97-
re_match = re.match("([a-z0-9.]+)(-([a-z0-9]+))?$", version)
98-
assert re_match, f"Not a valid version {version}"
99-
100-
commit_id_or_hash = re_match[3]
101-
self._version = re_match[1]
102-
else:
103-
commit_id_or_hash = commit_hash
104-
self._version = version
124+
self._version = version
105125

106126
if commit_id_or_hash is not None:
107127
self._commit_id = commit_id_or_hash[:8]
@@ -312,15 +332,27 @@ def release_metadata_string(self) -> str:
312332
assert len(features["platform"]) < 2
313333
"Only one platform is supported"
314334

335+
commit_hash = self.commit_hash
336+
commit_id = self.commit_id
315337
elements = ",".join(features["element"])
316338
flags = ",".join(features["flag"])
317339
platform = features["platform"][0]
318340
platforms = ",".join(features["platform"])
319341
platform_variant = self.platform_variant
342+
version = self.version
343+
344+
if commit_id is None:
345+
commit_id = ""
346+
347+
if commit_hash is None:
348+
commit_hash = commit_id
320349

321350
if platform_variant is None:
322351
platform_variant = ""
323352

353+
if version is None:
354+
version = ""
355+
324356
metadata = f"""
325357
ID={GL_RELEASE_ID}
326358
ID_LIKE=debian
@@ -338,9 +370,9 @@ def release_metadata_string(self) -> str:
338370
GARDENLINUX_FEATURES_FLAGS="{flags}"
339371
GARDENLINUX_PLATFORM="{platform}"
340372
GARDENLINUX_PLATFORM_VARIANT="{platform_variant}"
341-
GARDENLINUX_VERSION="{self.version}"
342-
GARDENLINUX_COMMIT_ID="{self.commit_id}"
343-
GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}"
373+
GARDENLINUX_VERSION="{version}"
374+
GARDENLINUX_COMMIT_ID="{commit_id}"
375+
GARDENLINUX_COMMIT_ID_LONG="{commit_hash}"
344376
""".strip()
345377

346378
return metadata

src/gardenlinux/s3/s3_artifacts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ def upload_from_directory(
158158
if secureboot is None:
159159
secureboot = "_trustedboot" in feature_list
160160

161-
commit_hash = cname_object.commit_hash
161+
commit_id_or_hash = cname_object.commit_hash
162162

163-
if commit_hash is None:
164-
commit_hash = ""
163+
if commit_id_or_hash is None:
164+
commit_id_or_hash = cname_object.commit_id
165165

166166
version_epoch = str(cname_object.version_epoch)
167167

@@ -172,7 +172,7 @@ def upload_from_directory(
172172
"platform": cname_object.feature_set_platform,
173173
"architecture": cname_object.arch,
174174
"base_image": None,
175-
"build_committish": commit_hash,
175+
"build_committish": commit_id_or_hash,
176176
"build_timestamp": datetime.fromtimestamp(release_timestamp).isoformat(),
177177
"gardenlinux_epoch": {version_epoch},
178178
"logs": None,
@@ -224,7 +224,7 @@ def upload_from_directory(
224224
"architecture": re_object.sub("+", cname_object.arch),
225225
"platform": re_object.sub("+", cname_object.platform),
226226
"version": re_object.sub("+", cname_object.version), # type: ignore[arg-type]
227-
"committish": commit_hash,
227+
"committish": commit_id_or_hash,
228228
"md5sum": md5sum,
229229
"sha256sum": sha256sum,
230230
}

tests/s3/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def make_cname(
2727
flavor: str = "container",
2828
arch: str = "amd64",
2929
version: str = "1234.1",
30-
commit: str = "abc123",
30+
commit: str = "abc123long",
3131
) -> str:
3232
"""
3333
Helper function to build cname. Can be used to customized the cname.

tests/s3/test_s3_artifacts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .conftest import S3Env
1212

1313
RELEASE_DATA = """
14-
GARDENLINUX_CNAME="container-amd64-1234.1-abc123"
14+
GARDENLINUX_CNAME="container-amd64-1234.1"
1515
GARDENLINUX_VERSION=1234.1
1616
GARDENLINUX_COMMIT_ID="abc123"
1717
GARDENLINUX_COMMIT_ID_LONG="abc123long"

0 commit comments

Comments
 (0)