Skip to content

Commit

Permalink
fix: Only push new versions images to Docker Hub (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <msouzaol@redhat.com>
  • Loading branch information
mateusoliveira43 committed May 30, 2023
1 parent 4c331c5 commit 9a229ff
Show file tree
Hide file tree
Showing 9 changed files with 1,765 additions and 1,425 deletions.
1 change: 1 addition & 0 deletions .github/new_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Poetry": ["1.5.1"], "Python": []}
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
id: generate-jobs
run: |
matrix=$(./scripts/pipeline.py cd)
echo "::set-output name=matrix::$matrix"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
docker-hub:
needs: generate-jobs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
id: generate-jobs
run: |
matrix=$(./scripts/pipeline.py ci)
echo "::set-output name=matrix::$matrix"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
docker-check:
needs: [project-check, generate-docker-jobs]
Expand Down
1,933 changes: 1,067 additions & 866 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
[tool.poetry.dependencies]
python = "^3.7"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
bandit = "^1.7.4"
black = "^22.3.0"
editorconfig-checker = "^2.4.0"
Expand Down
1,165 changes: 643 additions & 522 deletions requirements/dev.txt

Large diffs are not rendered by default.

52 changes: 29 additions & 23 deletions scripts/pipeline_cli/commands/cd_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import json
from typing import Dict, List

from ..config import POETRY_VERSIONS, PYTHON_VARIATIONS, PYTHON_VERSIONS
from ..config import (
NEW_VERSIONS_FILE,
POETRY_VERSIONS,
PYTHON_VARIATIONS,
PYTHON_VERSIONS,
)
from . import get_dockerfile_version


Expand Down Expand Up @@ -82,28 +87,29 @@ def get_tags(
)


jobs = [
{
"version": (
f"{poetry_minor}.{poetry_patch}-python"
f"{python_minor}.{python_patch}-{variation}"
),
"tags": get_tags(
poetry_minor=poetry_minor,
poetry_patch=poetry_patch,
python_minor=python_minor,
python_patch=python_patch,
variation=variation,
),
}
for poetry_minor, poetry_patches in POETRY_VERSIONS.items()
for poetry_patch in poetry_patches
for python_minor, python_patches in PYTHON_VERSIONS.items()
for python_patch in python_patches
for variation in PYTHON_VARIATIONS
]


def generate_cd_jobs() -> None:
"""Generate jobs for the Continuos Delivery pipeline."""
new_versions_content = json.loads(NEW_VERSIONS_FILE.read_text())
jobs = [
{
"version": (
f"{poetry_minor}.{poetry_patch}-python"
f"{python_minor}.{python_patch}-{variation}"
),
"tags": get_tags(
poetry_minor=poetry_minor,
poetry_patch=poetry_patch,
python_minor=python_minor,
python_patch=python_patch,
variation=variation,
),
}
for poetry_minor, poetry_patches in POETRY_VERSIONS.items()
for poetry_patch in poetry_patches
for python_minor, python_patches in PYTHON_VERSIONS.items()
for python_patch in python_patches
for variation in PYTHON_VARIATIONS
if f"{poetry_minor}.{poetry_patch}" in new_versions_content["Poetry"]
or f"{python_minor}.{python_patch}" in new_versions_content["Python"]
]
print(json.dumps({"include": jobs}))
32 changes: 21 additions & 11 deletions scripts/pipeline_cli/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
import json
from functools import partial
from pathlib import Path
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Tuple
from urllib import request

from cly.colors import color_text
from cly.utils import run_command

from ..config import POETRY_VERSIONS, PROJECT_ROOT, PYTHON_VERSIONS, __file__
from ..config import (
NEW_VERSIONS_FILE,
POETRY_VERSIONS,
PROJECT_ROOT,
PYTHON_VERSIONS,
__file__,
)

TAB = " " * 4

Expand Down Expand Up @@ -54,7 +60,7 @@ def patch_is_highest(patch: int, patches: List[int]) -> bool:

def get_updates(
tags: List[str], versions: Dict[str, List[int]]
) -> List[Optional[Tuple[int, int, int]]]:
) -> List[Tuple[int, int, int]]:
"""
Get available updates from tags, looking to project versions.
Expand All @@ -67,7 +73,7 @@ def get_updates(
Returns
-------
List[Optional[Tuple[int, int, int]]]
List[Tuple[int, int, int]]
Empty list, if there are no updates to be made; else, a list with the
available versions for update.
Expand All @@ -87,7 +93,7 @@ def get_updates(
else:
tags_serialized[major_and_minor] = [int(patch)]

patch_errors = [
patch_updates = [
(*tag_str_to_tuple(version), patch)
for version, patches in versions.items()
for patch in filter(
Expand All @@ -97,20 +103,20 @@ def get_updates(
if patch not in patches
]

major_and_minor_errors = [
major_and_minor_updates = [
(*tag_str_to_tuple(tag), patch)
for tag, patches in tags_serialized.items()
for patch in patches
if tag_str_to_tuple(tag)
> max(tag_str_to_tuple(version) for version in versions)
]

return sorted(patch_errors + major_and_minor_errors) # type: ignore
return sorted(patch_updates + major_and_minor_updates)


def update_software_versions(
software: str,
updates: List[Optional[Tuple[int, int, int]]],
updates: List[Tuple[int, int, int]],
versions: Dict[str, List[int]],
) -> None:
"""
Expand All @@ -120,7 +126,7 @@ def update_software_versions(
----------
software : str
The software to update (Poetry or Python).
updates : List[Optional[Tuple[int, int, int]]]
updates : List[Tuple[int, int, int]]
List of available updates for the software.
versions : Dict[str, List[int]]
Project versions of the software.
Expand All @@ -139,8 +145,12 @@ def update_software_versions(
)
+ 1
)
for version in updates:
major, minor, patch = version # type: ignore
new_versions_content: Dict[str, List[str]] = {"Poetry": [], "Python": []}
new_versions_content[software] = [
f"{version[0]}.{version[1]}.{version[2]}" for version in updates
]
NEW_VERSIONS_FILE.write_text(json.dumps(new_versions_content) + "\n")
for major, minor, patch in updates:
major_and_minor = f"{major}.{minor}"
print(f"{TAB}Adding {software} version {major_and_minor}.{patch}")
if major_and_minor in versions:
Expand Down
1 change: 1 addition & 0 deletions scripts/pipeline_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@

PROJECT_ROOT: Path = Path(__file__).resolve().parent.parent.parent
TEMPLATE_FOLDER: Path = PROJECT_ROOT / "templates"
NEW_VERSIONS_FILE = PROJECT_ROOT / ".github/new_versions.json"

0 comments on commit 9a229ff

Please sign in to comment.