Skip to content

Commit 28105d9

Browse files
committed
Make it possible to select PR vs auto jobs
1 parent 0021c22 commit 28105d9

File tree

1 file changed

+22
-9
lines changed
  • src/ci/github-actions

1 file changed

+22
-9
lines changed

src/ci/github-actions/ci.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
def add_job_properties(jobs: List[Dict], prefix: str) -> List[Job]:
3131
"""
3232
Modify the `name` attribute of each job, based on its base name and the given `prefix`.
33-
Add an `image` attribute to each job, base don its image.
33+
Add an `image` attribute to each job, based on its image.
3434
"""
3535
modified_jobs = []
3636
for job in jobs:
@@ -196,15 +196,14 @@ def get_job_image(job) -> str:
196196
return job.get("env", {}).get("IMAGE", job["name"])
197197

198198

199-
def run_workflow_locally(job_data: Dict[str, Any], job_name: str):
199+
def run_workflow_locally(job_data: Dict[str, Any], job_name: str, pr_jobs: bool):
200200
DOCKER_DIR = Path(__file__).absolute().parent.parent / "docker"
201201

202-
jobs = list(job_data["auto"])
203-
jobs.extend(job_data["pr"])
204-
202+
jobs = job_data["pr"] if pr_jobs else job_data["auto"]
205203
jobs = [job for job in jobs if job.get("name") == job_name]
206204
if len(jobs) == 0:
207-
raise Exception(f"Job `{job_name}` not found")
205+
raise Exception(f"Job `{job_name}` not found in {'pr' if pr_jobs else 'auto'} jobs")
206+
assert len(jobs) == 1
208207
job = jobs[0]
209208
if "ubuntu" not in job["os"]:
210209
raise Exception("Only Linux jobs can be executed locally")
@@ -222,7 +221,12 @@ def run_workflow_locally(job_data: Dict[str, Any], job_name: str):
222221

223222
env = os.environ.copy()
224223
env.update(custom_env)
225-
subprocess.run(args, env=env)
224+
225+
process = subprocess.Popen(args, env=env)
226+
try:
227+
process.wait()
228+
except KeyboardInterrupt:
229+
process.kill()
226230

227231

228232
if __name__ == "__main__":
@@ -239,7 +243,16 @@ def run_workflow_locally(job_data: Dict[str, Any], job_name: str):
239243
subparsers = parser.add_subparsers(help="Command to execute", dest="command", required=True)
240244
subparsers.add_parser("calculate-job-matrix")
241245
run_parser = subparsers.add_parser("run-local")
242-
run_parser.add_argument("job_name", help="CI job that should be executed")
246+
run_parser.add_argument(
247+
"job_name",
248+
help="CI job that should be executed. By default, a merge (auto) "
249+
"job with the given name will be executed"
250+
)
251+
run_parser.add_argument(
252+
"--pr",
253+
action="store_true",
254+
help="Run a PR job instead of an auto job"
255+
)
243256
args = parser.parse_args()
244257

245258
if args.command == "calculate-job-matrix":
@@ -265,6 +278,6 @@ def run_workflow_locally(job_data: Dict[str, Any], job_name: str):
265278
print(f"jobs={json.dumps(jobs)}")
266279
print(f"run_type={run_type}")
267280
elif args.command == "run-local":
268-
run_workflow_locally(data, args.job_name)
281+
run_workflow_locally(data, args.job_name, args.pr)
269282
else:
270283
raise Exception(f"Unknown command {args.command}")

0 commit comments

Comments
 (0)