-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathbuild_matrix.py
39 lines (29 loc) · 1.23 KB
/
build_matrix.py
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
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}")
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 = json.dumps({"include": [dataclasses.asdict(ver) for ver in new_or_updated]}) if new_or_updated else ""
_github_action_set_output("MATRIX", 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))