mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Remove unused code
This commit is contained in:
parent
4081406715
commit
0820ee84b0
1 changed files with 0 additions and 134 deletions
134
tools/ci.py
134
tools/ci.py
|
@ -392,140 +392,6 @@ def get_releases(ctx: Context, repository: str = "saltstack/salt"):
|
|||
ctx.exit(0)
|
||||
|
||||
|
||||
@ci.command(
|
||||
name="get-pr-test-labels",
|
||||
arguments={
|
||||
"pr": {
|
||||
"help": "Pull request number",
|
||||
},
|
||||
"repository": {
|
||||
"help": "Github repository.",
|
||||
},
|
||||
},
|
||||
)
|
||||
def get_pr_test_labels(
|
||||
ctx: Context, repository: str = "saltstack/salt", pr: int = None
|
||||
):
|
||||
"""
|
||||
Set the pull-request labels.
|
||||
"""
|
||||
github_step_summary = os.environ.get("GITHUB_STEP_SUMMARY")
|
||||
gh_event_path = os.environ.get("GITHUB_EVENT_PATH") or None
|
||||
if gh_event_path is None:
|
||||
labels = _get_pr_test_labels_from_api(ctx, repository, pr=pr)
|
||||
else:
|
||||
if TYPE_CHECKING:
|
||||
assert gh_event_path is not None
|
||||
|
||||
try:
|
||||
gh_event = json.loads(open(gh_event_path, encoding="utf-8").read())
|
||||
except Exception as exc:
|
||||
ctx.error(
|
||||
f"Could not load the GH Event payload from {gh_event_path!r}:\n", exc
|
||||
)
|
||||
ctx.exit(1)
|
||||
|
||||
if "pull_request" not in gh_event:
|
||||
ctx.warn("The 'pull_request' key was not found on the event payload.")
|
||||
ctx.exit(1)
|
||||
|
||||
pr = gh_event["pull_request"]["number"]
|
||||
labels = _get_pr_test_labels_from_event_payload(gh_event)
|
||||
|
||||
shared_context = tools.utils.get_cicd_shared_context()
|
||||
mandatory_os_slugs = set(shared_context["mandatory_os_slugs"])
|
||||
available = set(tools.utils.get_golden_images())
|
||||
# Add MacOS provided by GitHub
|
||||
available.update({"macos-12", "macos-13", "macos-13-arm64"})
|
||||
# Remove mandatory OS'ss
|
||||
available.difference_update(mandatory_os_slugs)
|
||||
select_all = set(available)
|
||||
selected = set()
|
||||
test_labels = []
|
||||
if labels:
|
||||
ctx.info(f"Test labels for pull-request #{pr} on {repository}:")
|
||||
for name, description in sorted(labels):
|
||||
ctx.info(
|
||||
f" * [yellow]{name}[/yellow]: {description or '[red][No description][/red]'}"
|
||||
)
|
||||
if name.startswith("test:os:"):
|
||||
slug = name.split("test:os:", 1)[-1]
|
||||
if slug not in available and name != "test:os:all":
|
||||
ctx.warn(
|
||||
f"The '{slug}' slug exists as a label but not as an available OS."
|
||||
)
|
||||
selected.add(slug)
|
||||
if slug != "all" and slug in available:
|
||||
available.remove(slug)
|
||||
continue
|
||||
test_labels.append(name)
|
||||
|
||||
else:
|
||||
ctx.info(f"No test labels for pull-request #{pr} on {repository}")
|
||||
|
||||
if "test:coverage" in test_labels:
|
||||
ctx.info(
|
||||
"Selecting ALL available OS'es because the label 'test:coverage' is set."
|
||||
)
|
||||
selected.add("all")
|
||||
if github_step_summary is not None:
|
||||
with open(github_step_summary, "a", encoding="utf-8") as wfh:
|
||||
wfh.write(
|
||||
"Selecting ALL available OS'es because the label `test:coverage` is set.\n"
|
||||
)
|
||||
|
||||
if "all" in selected:
|
||||
selected = select_all
|
||||
available.clear()
|
||||
|
||||
github_output = os.environ.get("GITHUB_OUTPUT")
|
||||
if github_output is None:
|
||||
ctx.exit(0)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
assert github_output is not None
|
||||
|
||||
ctx.info("Writing 'labels' to the github outputs file...")
|
||||
ctx.info("Test Labels:")
|
||||
if not test_labels:
|
||||
ctx.info(" * None")
|
||||
else:
|
||||
for label in sorted(test_labels):
|
||||
ctx.info(f" * [yellow]{label}[/yellow]")
|
||||
ctx.info("* OS Labels:")
|
||||
if not selected:
|
||||
ctx.info(" * None")
|
||||
else:
|
||||
for slug in sorted(selected):
|
||||
ctx.info(f" * [yellow]{slug}[/yellow]")
|
||||
with open(github_output, "a", encoding="utf-8") as wfh:
|
||||
wfh.write(f"os-labels={json.dumps([label for label in selected])}\n")
|
||||
wfh.write(f"test-labels={json.dumps([label for label in test_labels])}\n")
|
||||
|
||||
github_step_summary = os.environ.get("GITHUB_STEP_SUMMARY")
|
||||
if github_step_summary is not None:
|
||||
with open(github_step_summary, "a", encoding="utf-8") as wfh:
|
||||
wfh.write("Mandatory OS Test Runs:\n")
|
||||
for slug in sorted(mandatory_os_slugs):
|
||||
wfh.write(f"* `{slug}`\n")
|
||||
|
||||
wfh.write("\nOptional OS Test Runs(selected by label):\n")
|
||||
if not selected:
|
||||
wfh.write("* None\n")
|
||||
else:
|
||||
for slug in sorted(selected):
|
||||
wfh.write(f"* `{slug}`\n")
|
||||
|
||||
wfh.write("\nSkipped OS Tests Runs(NOT selected by label):\n")
|
||||
if not available:
|
||||
wfh.write("* None\n")
|
||||
else:
|
||||
for slug in sorted(available):
|
||||
wfh.write(f"* `{slug}`\n")
|
||||
|
||||
ctx.exit(0)
|
||||
|
||||
|
||||
def _get_pr_test_labels_from_api(
|
||||
ctx: Context, repository: str = "saltstack/salt", pr: int = None
|
||||
) -> list[tuple[str, str]]:
|
||||
|
|
Loading…
Add table
Reference in a new issue