Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e257359

Browse files
committed
Skip jobs based on the active channel in Python
1 parent 2a7fe14 commit e257359

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ci/github-actions/calculate-job-matrix.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import yaml
1919

20+
CI_DIR = Path(__file__).absolute().parent.parent
2021
JOBS_YAML_PATH = Path(__file__).absolute().parent / "jobs.yml"
2122

2223
Job = Dict[str, Any]
@@ -90,6 +91,13 @@ def calculate_jobs(job_type: JobType, job_data: Dict[str, Any]) -> List[Job]:
9091
return []
9192

9293

94+
def skip_jobs(jobs: List[Dict[str, Any]], channel: str) -> List[Job]:
95+
"""
96+
Skip CI jobs that are not supposed to be executed on the given `channel`.
97+
"""
98+
return [j for j in jobs if j.get("CI_ONLY_WHEN_CHANNEL", channel) == channel]
99+
100+
93101
def get_github_ctx() -> GitHubCtx:
94102
return GitHubCtx(
95103
event_name=os.environ["GITHUB_EVENT_NAME"],
@@ -109,9 +117,13 @@ def get_github_ctx() -> GitHubCtx:
109117
job_type = find_job_type(github_ctx)
110118
logging.info(f"Job type: {job_type}")
111119

120+
with open(CI_DIR / "channel") as f:
121+
channel = f.read().strip()
122+
112123
jobs = []
113124
if job_type is not None:
114125
jobs = calculate_jobs(job_type, data)
126+
jobs = skip_jobs(jobs, channel)
115127

116128
logging.info(f"Output:\n{yaml.dump(jobs, indent=4)}")
117129
print(f"jobs={json.dumps(jobs)}")

0 commit comments

Comments
 (0)