tasks/libs/github_actions_tools.py
def trigger_macos_workflow(
    workflow="macos.yaml",
    github_action_ref="master",
    datadog_agent_ref=DEFAULT_BRANCH,
    release_version=None,
    major_version=None,
    python_runtimes="3",
):
    """
    Trigger a workflow to build a MacOS Agent.
    """
    inputs = {}

    if datadog_agent_ref is not None:
        inputs["datadog_agent_ref"] = datadog_agent_ref

    if release_version is not None:
        inputs["release_version"] = release_version

    if major_version is not None:
        inputs["agent_major_version"] = major_version

    if python_runtimes is not None:
        inputs["python_runtimes"] = python_runtimes

    print(
        "Creating workflow on datadog-agent-macos-build on commit {} with args:\n{}".format(  # noqa: FS002
            github_action_ref, "\n".join([f"  - {k}: {inputs[k]}" for k in inputs])
        )
    )

    # Hack: get current time to only fetch workflows that started after now.
    now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")

    # The workflow trigger endpoint doesn't return anything. You need to fetch the workflow run id
    # by yourself.
    create_or_refresh_macos_build_github_workflows().trigger_workflow(workflow, github_action_ref, inputs)

    # Thus the following hack: query the latest run for ref, wait until we get a non-completed run
    # that started after we triggered the workflow.
    # In practice, this should almost never be a problem, even if the Agent 6 and 7 jobs run at the
    # same time, given that these two jobs will target different github_action_ref on RCs / releases.
    MAX_RETRIES = 10  # Retry up to 10 times
    for i in range(MAX_RETRIES):
        print(f"Fetching triggered workflow (try {i + 1}/{MAX_RETRIES})")
        run = get_macos_workflow_run_for_ref(workflow, github_action_ref)
        if run is not None and run.get("created_at", datetime.fromtimestamp(0).strftime("%Y-%m-%dT%H:%M:%SZ")) >= now:
            return run.get("id")

        sleep(5)

    # Something went wrong :(
    print("Couldn't fetch workflow run that was triggered.")
    raise Exit(code=1)

    Trigger a workflow to build a MacOS Agent.
    
Trigger a workflow to build a MacOS Agent.
Trigger a workflow to build a MacOS Agent .
def trigger_macos_workflow(
    workflow="macos.yaml",
    github_action_ref="master",
    datadog_agent_ref=DEFAULT_BRANCH,
    release_version=None,
    major_version=None,
    python_runtimes="3",
):
    inputs = {}
    if datadog_agent_ref is not None:
        inputs["datadog_agent_ref"] = datadog_agent_ref
    if release_version is not None:
        inputs["release_version"] = release_version
    if major_version is not None:
        inputs["agent_major_version"] = major_version
    if python_runtimes is not None:
        inputs["python_runtimes"] = python_runtimes
    print(
        "Creating workflow on datadog-agent-macos-build on commit {} with args:\n{}".format(  
            github_action_ref, "\n".join([f"  - {k}: {inputs[k]}" for k in inputs])
        )
    )
    now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
    create_or_refresh_macos_build_github_workflows().trigger_workflow(workflow, github_action_ref, inputs)
    MAX_RETRIES = 10  
    for i in range(MAX_RETRIES):
        print(f"Fetching triggered workflow (try {i + 1}/{MAX_RETRIES})")
        run = get_macos_workflow_run_for_ref(workflow, github_action_ref)
        if run is not None and run.get("created_at", datetime.fromtimestamp(0).strftime("%Y-%m-%dT%H:%M:%SZ")) >= now:
            return run.get("id")
        sleep(5)
    print("Couldn't fetch workflow run that was triggered.")
    raise Exit(code=1)
def trigger_macos_workflow ( workflow = "macos.yaml" , github_action_ref = "master" , datadog_agent_ref = DEFAULT_BRANCH , release_version = None , major_version = None , python_runtimes = "3" , ) : inputs = { } if datadog_agent_ref is not None : inputs [ "datadog_agent_ref" ] = datadog_agent_ref if release_version is not None : inputs [ "release_version" ] = release_version if major_version is not None : inputs [ "agent_major_version" ] = major_version if python_runtimes is not None : inputs [ "python_runtimes" ] = python_runtimes print ( "Creating workflow on datadog-agent-macos-build on commit {} with args:\n{}" . format ( github_action_ref , "\n" . join ( [ f"  - {k}: {inputs[k]}" for k in inputs ] ) ) ) now = datetime . utcnow ( ) . strftime ( "%Y-%m-%dT%H:%M:%SZ" ) create_or_refresh_macos_build_github_workflows ( ) . trigger_workflow ( workflow , github_action_ref , inputs ) MAX_RETRIES = 10 for i in range ( MAX_RETRIES ) : print ( f"Fetching triggered workflow (try {i + 1}/{MAX_RETRIES})" ) run = get_macos_workflow_run_for_ref ( workflow , github_action_ref ) if run is not None and run . get ( "created_at" , datetime . fromtimestamp ( 0 ) . strftime ( "%Y-%m-%dT%H:%M:%SZ" ) ) >= now : return run . get ( "id" ) sleep ( 5 ) print ( "Couldn't fetch workflow run that was triggered." ) raise Exit ( code = 1 )
Trigger a workflow to build a MacOS Agent.
Trigger a workflow to build a MacOS Agent .
"""
    Trigger a workflow to build a MacOS Agent.
    """ # noqa: FS002 # Hack: get current time to only fetch workflows that started after now. # The workflow trigger endpoint doesn't return anything. You need to fetch the workflow run id # by yourself. # Thus the following hack: query the latest run for ref, wait until we get a non-completed run # that started after we triggered the workflow. # In practice, this should almost never be a problem, even if the Agent 6 and 7 jobs run at the # same time, given that these two jobs will target different github_action_ref on RCs / releases. # Retry up to 10 times # Something went wrong :(
workflow
github_action_ref
datadog_agent_ref
release_version
major_version
python_runtimes