Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/features_parse/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ outputs:
runs:
using: composite
steps:
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.10
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.11
- id: result
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/flavors_parse/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ outputs:
runs:
using: composite
steps:
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.10
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.10.11
- id: matrix
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Installs the given GardenLinux Python library
inputs:
version:
description: GardenLinux Python library version
default: "0.10.10"
default: "0.10.11"
python_version:
description: Python version to setup
default: "3.13"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: ["3.13"]
python_version: ["3.13", "3.14"]
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[tool.poetry]
name = "gardenlinux"
version = "0.10.10"
version = "0.10.11"
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
authors = ["Garden Linux Maintainers <contact@gardenlinux.io>"]
license = "Apache-2.0"
readme = "README.md"
packages = [{ include = "gardenlinux", from = "src" }]

[tool.poetry.dependencies]
python = ">=3.13, <3.14"
python = ">=3.13, !=3.14.1"
apt-repo = "^0.5"
boto3 = "^1.42.10"
click = "^8.3.1"
Expand Down
80 changes: 60 additions & 20 deletions src/gardenlinux/features/cname.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,46 @@ def __init__(

commit_id_or_hash = None

re_match = re.match(
"([a-zA-Z0-9]+([\\_\\-][a-zA-Z0-9]+)*?)(-([a-z0-9]+)(-([a-z0-9.]+)-([a-z0-9]+))*)?$",
cname,
if version is not None:
# Support version values formatted as <version>-<commit_hash>
if commit_hash is None:
re_match = re.match("([a-z0-9.]+)(-([a-z0-9]+))?$", version)
assert re_match, f"Not a valid version {version}"

commit_id_or_hash = re_match[3]
version = re_match[1]
else:
commit_id_or_hash = commit_hash

re_object = re.compile(
"([a-zA-Z0-9]+([\\_\\-][a-zA-Z0-9]+)*?)(-([a-z0-9]+)(-([a-z0-9.]+)-([a-z0-9]+))*)?$"
)

re_match = re_object.match(cname)

# Workaround Garden Linux canonical names without mandatory final commit hash
if (
not re_match
and commit_id_or_hash
and re.match(
"([a-zA-Z0-9]+([\\_\\-][a-zA-Z0-9]+)*?)(-([a-z0-9]+)(-([a-z0-9.]+))*)?$",
cname,
)
):
re_match = re_object.match(f"{cname}-{commit_id_or_hash}")

assert re_match, f"Not a valid Garden Linux canonical name {cname}"

if re_match.lastindex == 1:
self._flavor = re_match[1]
else:
commit_id_or_hash = re_match[7]
if commit_id_or_hash is None:
commit_id_or_hash = re_match[7]
elif re_match.group(7) is not None:
assert commit_id_or_hash.startswith(re_match[7]), (
f"Mismatch between Garden Linux canonical name '{cname}' and given commit ID '{commit_id_or_hash}' detected"
)

self._flavor = re_match[1]
self._version = re_match[6]

Expand All @@ -91,17 +120,13 @@ def __init__(
if self._arch is None and arch is not None:
self._arch = arch

if self._version is None and version is not None:
# Support version values formatted as <version>-<commit_hash>
if commit_hash is None:
re_match = re.match("([a-z0-9.]+)(-([a-z0-9]+))?$", version)
assert re_match, f"Not a valid version {version}"

commit_id_or_hash = re_match[3]
self._version = re_match[1]
else:
commit_id_or_hash = commit_hash
if version is not None:
if self._version is None:
self._version = version
else:
assert version == self._version, (
f"Mismatch between Garden Linux canonical name '{cname}' and given version '{version}' detected"
)

if commit_id_or_hash is not None:
self._commit_id = commit_id_or_hash[:8]
Expand Down Expand Up @@ -312,21 +337,36 @@ def release_metadata_string(self) -> str:
assert len(features["platform"]) < 2
"Only one platform is supported"

commit_hash = self.commit_hash
commit_id = self.commit_id
elements = ",".join(features["element"])
flags = ",".join(features["flag"])
platform = features["platform"][0]
platforms = ",".join(features["platform"])
platform_variant = self.platform_variant
version = self.version

if commit_id is None:
commit_id = ""

if commit_hash is None:
commit_hash = commit_id

if platform_variant is None:
platform_variant = ""

if version is None:
pretty_name = f"{GL_DISTRIBUTION_NAME} unsupported version"
version = ""
else:
pretty_name = f"{GL_DISTRIBUTION_NAME} {version}"

metadata = f"""
ID={GL_RELEASE_ID}
ID_LIKE=debian
NAME="{GL_DISTRIBUTION_NAME}"
PRETTY_NAME="{GL_DISTRIBUTION_NAME} {self.version}"
IMAGE_VERSION={self.version}
PRETTY_NAME="{pretty_name}"
IMAGE_VERSION={version}
VARIANT_ID="{self.flavor}-{self.arch}"
HOME_URL="{GL_HOME_URL}"
SUPPORT_URL="{GL_SUPPORT_URL}"
Expand All @@ -338,9 +378,9 @@ def release_metadata_string(self) -> str:
GARDENLINUX_FEATURES_FLAGS="{flags}"
GARDENLINUX_PLATFORM="{platform}"
GARDENLINUX_PLATFORM_VARIANT="{platform_variant}"
GARDENLINUX_VERSION="{self.version}"
GARDENLINUX_COMMIT_ID="{self.commit_id}"
GARDENLINUX_COMMIT_ID_LONG="{self.commit_hash}"
GARDENLINUX_VERSION="{version}"
GARDENLINUX_COMMIT_ID="{commit_id}"
GARDENLINUX_COMMIT_ID_LONG="{commit_hash}"
""".strip()

return metadata
Expand All @@ -365,7 +405,7 @@ def version_and_commit_id(self) -> Optional[str]:
:since: 0.7.0
"""

if self._commit_id is None:
if self._version is None or self._commit_id is None:
return None

return f"{self._version}-{self._commit_id}"
Expand Down
16 changes: 8 additions & 8 deletions src/gardenlinux/s3/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

from .s3_artifacts import S3Artifacts

_ARGS_ACTION_ALLOWED = [
"download-artifacts-from-bucket",
"upload-artifacts-to-bucket",
]


def main() -> None:
"""
Expand All @@ -25,17 +20,22 @@ def main() -> None:
parser = argparse.ArgumentParser()

parser.add_argument("--bucket", dest="bucket")
parser.add_argument("--cname", required=False, dest="cname")
parser.add_argument("--path", required=False, dest="path")
parser.add_argument("--dry-run", action="store_true")

parser.add_argument("action", nargs="?", choices=_ARGS_ACTION_ALLOWED)
subparsers = parser.add_subparsers(dest="action")

download_parser = subparsers.add_parser("download-artifacts-from-bucket")
download_parser.add_argument("--cname", required=False, dest="cname")

upload_parser = subparsers.add_parser("upload-artifacts-to-bucket")
upload_parser.add_argument("--artifact-name", required=False, dest="artifact_name")

args = parser.parse_args()

if args.action == "download-artifacts-from-bucket":
S3Artifacts(args.bucket).download_to_directory(args.cname, args.path)
elif args.action == "upload-artifacts-to-bucket":
S3Artifacts(args.bucket).upload_from_directory(
args.cname, args.path, dry_run=args.dry_run
args.artifact_name, args.path, dry_run=args.dry_run
)
Loading