summaryrefslogtreecommitdiffstats
path: root/chromium/infra/config/lib/ci.star
blob: 557b741b23425df69210d2892565e92d20138742 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Library for defining CI builders.

The `ci_builder` function defined in this module enables defining a CI builder.
It can also be accessed through `ci.builder`.

The `defaults` struct provides module-level defaults for the arguments to
`ci_builder`. The parameters that support module-level defaults have a
corresponding attribute on `defaults` that is a `lucicfg.var` that can be used
to set the default value. Can also be accessed through `ci.defaults`.
"""

load("./args.star", "args")
load("./branches.star", "branches")
load("./builders.star", "builders", "os", "os_category")
load("//project.star", "settings")

defaults = args.defaults(
    extends = builders.defaults,
    main_console_view = None,
    cq_mirrors_console_view = None,
    thin_tester_cores = args.DEFAULT,
    tree_closing = False,
    tree_closing_notifiers = None,
)

def ci_builder(
        *,
        name,
        branch_selector = branches.MAIN,
        console_view_entry = None,
        main_console_view = args.DEFAULT,
        cq_mirrors_console_view = args.DEFAULT,
        sheriff_rotations = None,
        tree_closing = args.DEFAULT,
        tree_closing_notifiers = None,
        notifies = None,
        resultdb_bigquery_exports = None,
        experiments = None,
        **kwargs):
    """Define a CI builder.

    Args:
      name: name of the builder, will show up in UIs and logs. Required.
      branch_selector: A branch selector value controlling whether the
        builder definition is executed. See branches.star for more
        information.
      console_view_entry: A `consoles.console_view_entry` struct or a list of
        them describing console view entries to create for the builder.
        See `consoles.console_view_entry` for details.
      main_console_view: A string identifying the ID of the main console
        view to add an entry to. Supports a module-level default that
        defaults to None. An entry will be added only if
        `console_view_entry` is provided and the first entry's branch
        selector causes the entry to be defined. On branches, the provided
        value is ignored; all CI builders will be added to the `main` console.
      cq_mirrors_console_view: A string identifying the ID of the CQ
        mirrors console view to add an entry to. Supports a module-level
        default that defaults to None. An entry will be added only if
        `console_view_entry` is provided and the first entry's branch
        selector causes the entry to be defined.
      sheriff_rotations: The name(s) of any sheriff rotations that the builder
        should be added to. On branches, all CI builders will be added to the
        `chrome_browser_release` sheriff rotation.
      tree_closing: If true, failed builds from this builder that meet certain
        criteria will close the tree and email the sheriff. See the
        'chromium-tree-closer' config in notifiers.star for the full criteria.
      tree_closing_notifiers: A list of notifiers that will be notified when
        tree closing criteria are met by a build of this builder. Supports a
        module-level default that will be merged with the provided value.
      notifies: Any extra notifiers to attach to this builder.
      resultdb_bigquery_exports: a list of resultdb.export_test_results(...)
        specifying additional parameters for exporting test results to BigQuery.
        Will always upload to the following tables in addition to any tables
        specified by the list's elements:
          chrome-luci-data.chromium.ci_test_results
          chrome-luci-data.chromium.gpu_ci_test_results
      experiments: a dict of experiment name to the percentage chance (0-100)
        that it will apply to builds generated from this builder.
      **kwargs: Additional keyword arguments that will be forwarded on to
        `builders.builder`.
    """
    if not branches.matches(branch_selector):
        return

    try_only_kwargs = [k for k in ("mirrors", "try_settings") if k in kwargs]
    if try_only_kwargs:
        fail("CI builders cannot specify the following try-only arguments: {}".format(try_only_kwargs))

    tree_closing = defaults.get_value("tree_closing", tree_closing)
    if tree_closing:
        tree_closing_notifiers = defaults.get_value("tree_closing_notifiers", tree_closing_notifiers, merge = args.MERGE_LIST)
        tree_closing_notifiers = args.listify("chromium-tree-closer", "chromium-tree-closer-email", tree_closing_notifiers)

        notifies = args.listify(notifies, tree_closing_notifiers)

    merged_resultdb_bigquery_exports = [
        resultdb.export_test_results(
            bq_table = "chrome-luci-data.chromium.ci_test_results",
        ),
        resultdb.export_test_results(
            bq_table = "chrome-luci-data.chromium.gpu_ci_test_results",
            predicate = resultdb.test_result_predicate(
                # Only match the telemetry_gpu_integration_test target and its
                # Fuchsia and Android variants that have a suffix added to the
                # end. Those are caught with [^/]*.
                test_id_regexp = "ninja://chrome/test:telemetry_gpu_integration_test[^/]*/.+",
            ),
        ),
        resultdb.export_test_results(
            bq_table = "chrome-luci-data.chromium.blink_web_tests_ci_test_results",
            predicate = resultdb.test_result_predicate(
                # Match the "blink_web_tests" target and all of its
                # flag-specific versions, e.g. "vulkan_swiftshader_blink_web_tests".
                test_id_regexp = "ninja://[^/]*blink_web_tests/.+",
            ),
        ),
    ]
    merged_resultdb_bigquery_exports.extend(resultdb_bigquery_exports or [])

    sheriff_rotations = args.listify(
        sheriff_rotations,
        # All CI builders on standard branches should be part of the
        # chrome_browser_release sheriff rotation
        branches.value({branches.STANDARD_BRANCHES: "chrome_browser_release"}),
    )

    # All builders that are selected for extended stable should be part of the
    # chrome_browser_release sheriff rotation (this is less straightforward than
    # above because desktop extended stable can coexist with CrOS LTS and we
    # don't want the CrOS LTS builders to appear in the chrome_browser_release
    # tree)
    if branches.matches(branch_selector, target = branches.DESKTOP_EXTENDED_STABLE_BRANCHES):
        sheriff_rotations = args.listify(sheriff_rotations, branches.value({
            branches.DESKTOP_EXTENDED_STABLE_BRANCHES: "chrome_browser_release",
        }))

    goma_enable_ats = defaults.get_value_from_kwargs("goma_enable_ats", kwargs)
    if goma_enable_ats == args.COMPUTE:
        os = defaults.get_value_from_kwargs("os", kwargs)

        # in CI, enable ATS on windows.
        if os and os.category == os_category.WINDOWS:
            kwargs["goma_enable_ats"] = True

    # Define the builder first so that any validation of luci.builder arguments
    # (e.g. bucket) occurs before we try to use it
    builders.builder(
        name = name,
        branch_selector = branch_selector,
        console_view_entry = console_view_entry,
        resultdb_bigquery_exports = merged_resultdb_bigquery_exports,
        sheriff_rotations = sheriff_rotations,
        notifies = notifies,
        experiments = experiments,
        resultdb_index_by_timestamp = True,
        **kwargs
    )

    if console_view_entry:
        # builder didn't fail, we're guaranteed that console_view_entry is
        # either a single console_view_entry or a list of them and that they are valid
        if type(console_view_entry) == type(struct()):
            entry = console_view_entry
        else:
            entry = console_view_entry[0]

        if branches.matches(entry.branch_selector):
            console_view = entry.console_view
            if console_view == None:
                console_view = defaults.get_value_from_kwargs("builder_group", kwargs)

            bucket = defaults.get_value_from_kwargs("bucket", kwargs)
            builder = "{}/{}".format(bucket, name)

            overview_console_category = console_view
            if entry.category:
                overview_console_category = "|".join([console_view, entry.category])
            if not settings.is_main:
                main_console_view = "main"
            else:
                main_console_view = defaults.get_value("main_console_view", main_console_view)
            if main_console_view:
                luci.console_view_entry(
                    builder = builder,
                    console_view = main_console_view,
                    category = overview_console_category,
                    short_name = entry.short_name,
                )

            cq_mirrors_console_view = defaults.get_value(
                "cq_mirrors_console_view",
                cq_mirrors_console_view,
            )
            if cq_mirrors_console_view:
                luci.console_view_entry(
                    builder = builder,
                    console_view = cq_mirrors_console_view,
                    category = overview_console_category,
                    short_name = entry.short_name,
                )

def _gpu_linux_builder(*, name, **kwargs):
    """Defines a GPU-related linux builder.

    This sets linux-specific defaults that are common to GPU-related builder
    groups.
    """
    kwargs.setdefault("cores", 8)
    kwargs.setdefault("os", os.LINUX_DEFAULT)
    return ci.builder(name = name, **kwargs)

def _gpu_mac_builder(*, name, **kwargs):
    """Defines a GPU-related mac builder.

    This sets mac-specific defaults that are common to GPU-related builder
    groups.
    """
    kwargs.setdefault("builderless", True)
    kwargs.setdefault("os", os.MAC_ANY)
    return ci.builder(name = name, **kwargs)

def _gpu_windows_builder(*, name, **kwargs):
    """Defines a GPU-related windows builder.

    This sets windows-specific defaults that are common to GPU-related builder
    groups.
    """
    kwargs.setdefault("builderless", True)
    kwargs.setdefault("cores", 8)
    kwargs.setdefault("os", os.WINDOWS_ANY)
    return ci.builder(name = name, **kwargs)

def thin_tester(
        *,
        name,
        triggered_by,
        cores = args.DEFAULT,
        **kwargs):
    """Define a thin tester.

    A thin tester is a builder that is triggered by another builder to
    trigger and wait for tests that were built by the triggering builder.
    Because these builders do not perform compilation and are performing
    platform-agnostic operations, they can generally run on small linux
    machines.

    Args:
      name: The name of the builder.
      triggered_by: The triggering builder. See
        https://chromium.googlesource.com/infra/luci/luci-go/+/refs/heads/main/lucicfg/doc/README.md#luci.builder
        for more information.
      cores: See `builders.builder` for more information. The `thin_tester_core`
        module-level default in `ci.defaults` will be used as the default if it
        is set.
      **kwargs: Additional keyword arguments to forward on to `ci.builder`.

    Returns:
      The `luci.builder` keyset.
    """
    cores = defaults.get_value("thin_tester_cores", cores)
    kwargs.setdefault("goma_backend", None)
    kwargs.setdefault("reclient_instance", None)
    kwargs.setdefault("os", builders.os.LINUX_DEFAULT)
    return ci.builder(
        name = name,
        triggered_by = triggered_by,
        cores = cores,
        **kwargs
    )

ci = struct(
    # Module-level defaults for ci functions
    defaults = defaults,

    # Functions for declaring CI builders
    builder = ci_builder,
    thin_tester = thin_tester,

    # CONSTANTS
    DEFAULT_EXECUTABLE = "recipe:chromium",
    DEFAULT_EXECUTION_TIMEOUT = 3 * time.hour,
    DEFAULT_POOL = "luci.chromium.ci",
    DEFAULT_SERVICE_ACCOUNT = "chromium-ci-builder@chops-service-accounts.iam.gserviceaccount.com",

    # Functions and constants for the GPU-related builder groups
    gpu = struct(
        linux_builder = _gpu_linux_builder,
        mac_builder = _gpu_mac_builder,
        windows_builder = _gpu_windows_builder,
        POOL = "luci.chromium.gpu.ci",
        SERVICE_ACCOUNT = "chromium-ci-gpu-builder@chops-service-accounts.iam.gserviceaccount.com",
        TREE_CLOSING_NOTIFIERS = ["gpu-tree-closer-email"],
    ),
)

rbe_instance = struct(
    DEFAULT = "rbe-chromium-trusted",
    GVISOR_SHADOW = "rbe-chromium-gvisor-shadow",
)

rbe_jobs = struct(
    DEFAULT = 250,
    LOW_JOBS_FOR_CI = 80,
    HIGH_JOBS_FOR_CI = 500,
)