forked from nikolaik/docker-python-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_matrix.py
More file actions
66 lines (50 loc) · 2.06 KB
/
build_matrix.py
File metadata and controls
66 lines (50 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import dataclasses
import json
import logging
import os
import sys
from pathlib import Path
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from .versions import BuildVersion
CI_EVENT_SCHEDULED = "scheduled"
logger = logging.getLogger("dpn")
GITHUB_OUTPUT = os.getenv("GITHUB_OUTPUT", "")
def _github_action_set_output(key: str, value: str) -> None:
"""Write
https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
"""
if not GITHUB_OUTPUT:
print("GITHUB_OUTPUT not set", file=sys.stderr)
sys.exit(1)
with Path(GITHUB_OUTPUT).open("a") as fp:
fp.write(f"{key}={value}\n")
def _build_matrix_json(new_or_updated: list[BuildVersion]) -> str:
return json.dumps({"include": [dataclasses.asdict(ver) for ver in new_or_updated]}) if new_or_updated else ""
def _build_arch_matrix_json(new_or_updated: list[BuildVersion]) -> str:
if not new_or_updated:
return ""
include: list[dict[str, object]] = []
for version in new_or_updated:
include.extend(
(
dataclasses.asdict(version)
| {
"platform": platform,
"arch": platform.split("/")[1],
"runner": "ubuntu-24.04-arm" if platform == "linux/arm64" else "ubuntu-latest",
}
)
for platform in version.platforms
)
return json.dumps({"include": include})
def build_matrix(new_or_updated: list[BuildVersion], ci_event: str) -> None:
if not new_or_updated and ci_event == CI_EVENT_SCHEDULED:
logger.info("\n# Scheduled run with no new or updated versions. Doing nothing.")
return
matrix = _build_matrix_json(new_or_updated)
arch_matrix = _build_arch_matrix_json(new_or_updated)
_github_action_set_output("matrix", matrix)
_github_action_set_output("arch_matrix", arch_matrix)
logger.info("\n# New or updated versions:")
logger.info("Nothing" if not new_or_updated else "\n".join(version.key for version in new_or_updated))