Remove dead code.
Some checks failed
CI / Prepare Workflow Run (push) Has been cancelled
CI / Pre-Commit (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / NSIS Tests (push) Has been cancelled
CI / Prepare Release: (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / Build Source Tarball (push) Has been cancelled
CI / Build Salt Onedir (push) Has been cancelled
CI / Build Packages (push) Has been cancelled
CI / CI Deps (push) Has been cancelled
CI / Test Package (push) Has been cancelled
CI / Test Salt (push) Has been cancelled
CI / Combine Code Coverage (push) Has been cancelled
CI / Set the Pipeline Exit Status (push) Has been cancelled

Define jobs is handled by the workflow_config method.
This commit is contained in:
Daniel A. Wozniak 2025-03-07 17:07:04 -07:00 committed by Daniel Wozniak
parent 32b55b9e9b
commit 3194208a7f

View file

@ -142,205 +142,6 @@ def process_changed_files(ctx: Context, event_name: str, changed_files: pathlib.
ctx.exit(0)
@ci.command(
name="define-jobs",
arguments={
"event_name": {
"help": "The name of the GitHub event being processed.",
},
"skip_tests": {
"help": "Skip running the Salt tests",
},
"skip_pkg_tests": {
"help": "Skip running the Salt Package tests",
},
"skip_pkg_download_tests": {
"help": "Skip running the Salt Package download tests",
},
"changed_files": {
"help": (
"Path to '.json' file containing the payload of changed files "
"from the 'dorny/paths-filter' GitHub action."
),
},
},
)
def define_jobs(
ctx: Context,
event_name: str,
changed_files: pathlib.Path,
skip_tests: bool = False,
skip_pkg_tests: bool = False,
skip_pkg_download_tests: bool = False,
):
"""
Set GH Actions 'jobs' output to know which jobs should run.
"""
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output is None:
ctx.warn("The 'GITHUB_OUTPUT' variable is not set.")
ctx.exit(1)
if TYPE_CHECKING:
assert github_output is not None
github_step_summary = os.environ.get("GITHUB_STEP_SUMMARY")
if github_step_summary is None:
ctx.warn("The 'GITHUB_STEP_SUMMARY' variable is not set.")
ctx.exit(1)
if TYPE_CHECKING:
assert github_step_summary is not None
jobs = {
"lint": True,
"test": True,
"test-pkg": True,
"test-pkg-download": True,
"prepare-release": True,
"build-docs": True,
"build-source-tarball": True,
"build-deps-onedir": True,
"build-salt-onedir": True,
"build-pkgs": True,
"build-deps-ci": True,
}
if skip_tests:
jobs["test"] = False
if skip_pkg_tests:
jobs["test-pkg"] = False
if skip_pkg_download_tests:
jobs["test-pkg-download"] = False
if event_name != "pull_request":
# In this case, all defined jobs should run
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("Selected Jobs:\n")
for name, value in sorted(jobs.items()):
wfh.write(f" - `{name}`: {value}\n")
ctx.info("Writing 'jobs' to the github outputs file")
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write(f"jobs={json.dumps(jobs)}\n")
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write(
f"All defined jobs will run due to event type of `{event_name}`.\n"
)
return
# This is a pull-request
labels: list[str] = []
gh_event_path = os.environ.get("GITHUB_EVENT_PATH") or None
if 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)
labels.extend(
label[0] for label in _get_pr_test_labels_from_event_payload(gh_event)
)
if not changed_files.exists():
ctx.error(f"The '{changed_files}' file does not exist.")
ctx.error(
"FYI, the command 'tools process-changed-files <changed-files-path>' "
"needs to run prior to this one."
)
ctx.exit(1)
try:
changed_files_contents = json.loads(changed_files.read_text())
except Exception as exc:
ctx.error(f"Could not load the changed files from '{changed_files}': {exc}")
ctx.exit(1)
# So, it's a pull request...
# Based on which files changed, we can decide what jobs to run.
required_lint_changes: set[str] = {
changed_files_contents["salt"],
changed_files_contents["tests"],
changed_files_contents["lint"],
}
if required_lint_changes == {"false"}:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("De-selecting the 'lint' job.\n")
jobs["lint"] = False
required_docs_changes: set[str] = {
changed_files_contents["salt"],
changed_files_contents["docs"],
}
if required_docs_changes == {"false"}:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("De-selecting the 'build-docs' job.\n")
jobs["build-docs"] = False
required_test_changes: set[str] = {
changed_files_contents["testrun"],
changed_files_contents["workflows"],
changed_files_contents["golden_images"],
}
if jobs["test"] and required_test_changes == {"false"}:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("De-selecting the 'test' job.\n")
jobs["test"] = False
required_pkg_test_changes: set[str] = {
changed_files_contents["pkg_tests"],
changed_files_contents["workflows"],
changed_files_contents["golden_images"],
}
if "test:os:all" in labels or any([_.startswith("test:os:macos") for _ in labels]):
jobs["build-deps-onedir-macos"] = True
jobs["build-salt-onedir-macos"] = True
if jobs["test-pkg"] and required_pkg_test_changes == {"false"}:
if "test:pkg" in labels:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write(
"The 'test-pkg' job is forcefully selected by the use of the 'test:pkg' label.\n"
)
jobs["test-pkg"] = True
else:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("De-selecting the 'test-pkg' job.\n")
jobs["test-pkg"] = False
if jobs["test-pkg-download"] and required_pkg_test_changes == {"false"}:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("De-selecting the 'test-pkg-download' job.\n")
jobs["test-pkg-download"] = False
if not jobs["test"] and not jobs["test-pkg"] and not jobs["test-pkg-download"]:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
for job in (
"build-deps-ci",
"build-deps-onedir",
"build-salt-onedir",
"build-pkgs",
):
wfh.write(f"De-selecting the '{job}' job.\n")
jobs[job] = False
if not jobs["build-docs"]:
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("De-selecting the 'build-source-tarball' job.\n")
jobs["build-source-tarball"] = False
with open(github_step_summary, "a", encoding="utf-8") as wfh:
wfh.write("Selected Jobs:\n")
for name, value in sorted(jobs.items()):
wfh.write(f" - `{name}`: {value}\n")
ctx.info("Writing 'jobs' to the github outputs file")
with open(github_output, "a", encoding="utf-8") as wfh:
wfh.write(f"jobs={json.dumps(jobs)}\n")
class TestRun(TypedDict):
type: str
skip_code_coverage: bool
@ -434,6 +235,10 @@ def _get_pr_test_labels_from_event_payload(
def _filter_test_labels(labels: list[dict[str, Any]]) -> list[tuple[str, str]]:
"""
Filter labels that can affect the workflow configuration. Return a tuple of
their name and description.
"""
return [
(label["name"], label["description"])
for label in labels