Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not build/release/test/scan tracks with expired end-of-life values #241

Merged
merged 10 commits into from
Sep 30, 2024
2 changes: 1 addition & 1 deletion oci/mock-rock/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ upload:
directory: mock_rock/1.0
release:
1.0-22.04:
end-of-life: "2025-05-01T00:00:00Z"
end-of-life: "2024-05-01T00:00:00Z"
risks:
- candidate
- edge
Expand Down
23 changes: 18 additions & 5 deletions src/image/prepare_single_image_build_matrix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
from datetime import datetime, timezone
import glob
import json
import os
Expand Down Expand Up @@ -59,8 +60,10 @@ def validate_image_trigger(data: dict) -> None:
builds = image_trigger.get("upload", [])

release_to = "true" if "release" in image_trigger else ""

img_number = 0
# inject some extra metadata into the matrix data
for img_number, _ in enumerate(builds):
while img_number < len(builds):
builds[img_number]["name"] = args.oci_path.rstrip("/").split("/")[-1]
builds[img_number]["path"] = args.oci_path
builds[img_number]["revision"] = img_number + int(args.next_revision)
Expand Down Expand Up @@ -103,13 +106,23 @@ def validate_image_trigger(data: dict) -> None:

# set an output as a marker for later knowing if we need to release
if "release" in builds[img_number]:
release_to = "true"
# the workflow GH matrix has a problem parsing nested JSON dicts
# so let's remove this field since we don't need it for the builds
builds[img_number]["release"] = "true"
min_eol = datetime.strptime(min(
v["end-of-life"] for v in builds[img_number]["release"].values()
), "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
if min_eol < datetime.now(timezone.utc):
print("Track skipped because it reached its end of life")
del builds[img_number]
continue
else:
release_to = "true"
# the workflow GH matrix has a problem parsing nested JSON dicts
# so let's remove this field since we don't need it for the builds
builds[img_number]["release"] = "true"
linostar marked this conversation as resolved.
Show resolved Hide resolved
else:
builds[img_number]["release"] = ""

img_number += 1

matrix = {"include": builds}
print(f"{args.oci_path} - build matrix:\n{json.dumps(matrix, indent=4)}")
with open(os.environ["GITHUB_OUTPUT"], "a") as gh_out:
Expand Down
18 changes: 2 additions & 16 deletions src/image/utils/schema/triggers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pydantic

from datetime import datetime, timezone
from datetime import datetime
from typing import Dict, List, Literal, Optional


Expand All @@ -25,13 +25,6 @@ class ImageUploadReleaseSchema(pydantic.BaseModel):
class Config:
extra = pydantic.Extra.forbid

@pydantic.validator("end_of_life")
def ensure_still_supported(cls, v: datetime) -> datetime:
"""ensure that the end of life isn't reached."""
if v < datetime.now(timezone.utc):
raise ImageReachedEol("This track has reached its end of life")
return v


class ImageUploadSchema(pydantic.BaseModel):
"""Schema of each upload within the image.yaml files."""
Expand All @@ -58,21 +51,14 @@ class Config:
extra = pydantic.Extra.forbid

@pydantic.validator("stable", "candidate", "beta", "edge", pre=True)
def _check_risks(cls, values: List) -> str:
def _check_risks(cls, values: List) -> List:
"""There must be at least one risk specified."""
error = "At least one risk must be specified per track."
if not any(values):
raise ImageTriggerValidationError(error)

return values

@pydantic.validator("end_of_life")
def ensure_still_supported(cls, v: datetime) -> datetime:
"""ensure that the end of life isn't reached."""
if v < datetime.now(timezone.utc):
raise ImageReachedEol("This track has reached its end of life")
return v


class ImageSchema(pydantic.BaseModel):
"""Validates the schema of the image.yaml files."""
Expand Down
Loading