forked from mongodb/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivate_task.py
executable file
·51 lines (40 loc) · 1.84 KB
/
activate_task.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
40
41
42
43
44
45
46
47
48
49
50
51
"""Script that activates the input task on the same variant as the running task"""
from typing import Optional
import typer
from typing_extensions import Annotated
from buildscripts.resmokelib.utils import evergreen_conn
from buildscripts.util.read_config import read_config_file
def main(task_name: str, skip_for_patch_author: Annotated[Optional[str], typer.Argument()] = None):
expansions_file = "../expansions.yml"
expansions = read_config_file(expansions_file)
evg_api = evergreen_conn.get_evergreen_api()
# Skip activation if the patch author is the excluded user
if expansions.get("author") == skip_for_patch_author:
return
variant_id = expansions.get("build_id")
variant = evg_api.build_by_id(variant_id)
found_task = None
for task in variant.get_tasks():
if task.display_name == task_name:
found_task = task
break
is_patch = expansions.get("is_patch", False)
if found_task:
# In non-patch evergreen versions the task will live as not activated
# We can just find the task and activate it if it is not activated yet
if found_task.activated:
return
evg_api.configure_task(found_task.task_id, activated=True)
elif is_patch:
# Evergreen patches work differently than other evergreen versions
# When a task is not scheduled initially it does not exist as an unscheduled task
# So we need to use a different path in the api to schedule the task
patch_id = expansions.get("version_id")
build_variant = expansions.get("build_variant")
evg_api.configure_patch(patch_id, [{"id": build_variant, "tasks": [task_name]}])
else:
raise RuntimeError(
f"The {task_name} task could not be found in the {build_variant} variant"
)
if __name__ == "__main__":
typer.run(main)