summaryrefslogtreecommitdiff
path: root/buildscripts/burn_in_tags_bypass_compile_and_fetch_binaries.py
blob: 8a7e06789415daaf1bc7f480c2b9041eef0c23a3 (plain)
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
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""Bypass compile and fetch binaries for burn_in_tags."""

import logging
import sys

import click
import structlog
from structlog.stdlib import LoggerFactory

from evergreen.api import RetryingEvergreenApi
from buildscripts.bypass_compile_and_fetch_binaries import TargetBuild, gather_artifacts_and_update_expansions

structlog.configure(logger_factory=LoggerFactory())
LOGGER = structlog.get_logger(__name__)

EVG_CONFIG_FILE = ".evergreen.yml"


@click.command()
@click.option("--project", required=True, help="The evergreen project.")
@click.option("--build-variant", required=True, help="Build variant where compile is running.")
@click.option("--revision", required=True, help="Base revision of the build.")
@click.option("--out-file", required=True, help="File to write macros expansions to.")
@click.option("--version-id", required=True, help="Evergreen version id of the current build.")
@click.option("--json-artifact", required=True,
              help="The JSON file to write out the metadata of files to attach to task.")
def main(  # pylint: disable=too-many-arguments,too-many-locals
        project, build_variant, revision, out_file, version_id, json_artifact):
    """
    Create a file with expansions that can be used to bypass compile.

    This is used for dynamically generated build variants that can use a base build variants
    compile artifacts to run against.
    \f

    :param project: The evergreen project.
    :param build_variant: The build variant whose artifacts we want to use.
    :param revision: The base revision being run against.
    :param out_file: File to write expansions to.
    :param version_id: Evergreen version id being run against.
    """
    logging.basicConfig(
        format="[%(asctime)s - %(name)s - %(levelname)s] %(message)s",
        level=logging.DEBUG,
        stream=sys.stdout,
    )

    evg_api = RetryingEvergreenApi.get_api(config_file=EVG_CONFIG_FILE)

    version = evg_api.version_by_id(version_id)
    build = version.build_by_variant(build_variant)

    target = TargetBuild(project=project, revision=revision, build_variant=build_variant)
    gather_artifacts_and_update_expansions(build, target, json_artifact, out_file)


if __name__ == "__main__":
    main()  # pylint: disable=no-value-for-parameter