Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3 | # Copyright 2018 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 17 | import argparse |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 18 | import base64 |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 19 | import codecs |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 20 | import copy |
Jakob Buchgraber | 1280705 | 2018-02-25 17:04:56 +0100 | [diff] [blame] | 21 | import datetime |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 22 | from glob import glob |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 23 | import hashlib |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 24 | import itertools |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 25 | import json |
Jakob Buchgraber | 6db0f26 | 2018-02-17 15:45:54 +0100 | [diff] [blame] | 26 | import multiprocessing |
Philipp Wollermann | 0a04cf3 | 2018-02-21 17:07:22 +0100 | [diff] [blame] | 27 | import os |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 28 | import os.path |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 29 | import platform as platform_module |
Jakob Buchgraber | 257693b | 2018-02-20 00:03:56 +0100 | [diff] [blame] | 30 | import random |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 31 | import re |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 32 | import requests |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 33 | import shutil |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 34 | import stat |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 35 | import subprocess |
| 36 | import sys |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 37 | import tarfile |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 38 | import tempfile |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 39 | import threading |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 40 | import time |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 41 | import urllib.error |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 42 | import urllib.request |
Jakob Buchgraber | 25bb50f | 2018-02-22 18:06:21 +0100 | [diff] [blame] | 43 | import yaml |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 44 | |
| 45 | # Initialize the random number generator. |
| 46 | random.seed() |
| 47 | |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 48 | BUILDKITE_ORG = os.environ["BUILDKITE_ORGANIZATION_SLUG"] |
Florian Weikert | c274551 | 2021-02-17 16:13:55 +0100 | [diff] [blame] | 49 | THIS_IS_PRODUCTION = BUILDKITE_ORG == "bazel" |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 50 | THIS_IS_TESTING = BUILDKITE_ORG == "bazel-testing" |
| 51 | THIS_IS_TRUSTED = BUILDKITE_ORG == "bazel-trusted" |
| 52 | THIS_IS_SPARTA = True |
| 53 | |
| 54 | CLOUD_PROJECT = "bazel-public" if THIS_IS_TRUSTED else "bazel-untrusted" |
| 55 | |
| 56 | GITHUB_BRANCH = {"bazel": "master", "bazel-trusted": "master", "bazel-testing": "testing"}[ |
| 57 | BUILDKITE_ORG |
| 58 | ] |
| 59 | |
| 60 | SCRIPT_URL = "https://raw.githubusercontent.com/bazelbuild/continuous-integration/{}/buildkite/bazelci.py?{}".format( |
| 61 | GITHUB_BRANCH, int(time.time()) |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 62 | ) |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 63 | |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 64 | AGGREGATE_INCOMPATIBLE_TEST_RESULT_URL = "https://raw.githubusercontent.com/bazelbuild/continuous-integration/{}/buildkite/aggregate_incompatible_flags_test_result.py?{}".format( |
| 65 | GITHUB_BRANCH, int(time.time()) |
| 66 | ) |
| 67 | |
| 68 | EMERGENCY_FILE_URL = "https://raw.githubusercontent.com/bazelbuild/continuous-integration/{}/buildkite/emergency.yml?{}".format( |
| 69 | GITHUB_BRANCH, int(time.time()) |
| 70 | ) |
| 71 | |
| 72 | FLAKY_TESTS_BUCKET = { |
| 73 | "bazel-testing": "gs://bazel-testing-buildkite-stats/flaky-tests-bep/", |
| 74 | "bazel-trusted": "gs://bazel-buildkite-stats/flaky-tests-bep/", |
| 75 | "bazel": "gs://bazel-buildkite-stats/flaky-tests-bep/", |
| 76 | }[BUILDKITE_ORG] |
| 77 | |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 78 | KZIPS_BUCKET = { |
| 79 | "bazel-testing": "gs://bazel-kzips-testing/", |
| 80 | "bazel-trusted": "gs://bazel-kzips/", |
| 81 | "bazel": "gs://bazel-kzips/", |
| 82 | }[BUILDKITE_ORG] |
| 83 | |
Florian Weikert | 797787b | 2019-12-19 15:33:07 +0100 | [diff] [blame] | 84 | # Projects can opt out of receiving GitHub issues from --notify by adding `"do_not_notify": True` to their respective downstream entry. |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 85 | DOWNSTREAM_PROJECTS_PRODUCTION = { |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 86 | "Android Studio Plugin": { |
| 87 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 88 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/master/.bazelci/android-studio.yml", |
| 89 | "pipeline_slug": "android-studio-plugin", |
| 90 | }, |
Mai Hussien | 0731b4d | 2022-06-28 11:16:07 -0700 | [diff] [blame] | 91 | "Android Studio Plugin Google": { |
| 92 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 93 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/google/.bazelci/android-studio.yml", |
| 94 | "pipeline_slug": "android-studio-plugin-google", |
| 95 | }, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 96 | "Android Testing": { |
| 97 | "git_repository": "https://github.com/googlesamples/android-testing.git", |
Jingwen | bde7260 | 2018-12-13 10:57:43 -0500 | [diff] [blame] | 98 | "http_config": "https://raw.githubusercontent.com/googlesamples/android-testing/master/bazelci/buildkite-pipeline.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 99 | "pipeline_slug": "android-testing", |
Yun Peng | 9b1d343 | 2021-12-07 10:40:45 +0100 | [diff] [blame] | 100 | "disabled_reason": "https://github.com/android/testing-samples/issues/417", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 101 | }, |
Yun Peng | 8910fa3 | 2019-01-03 08:58:16 +0100 | [diff] [blame] | 102 | "Bazel": { |
| 103 | "git_repository": "https://github.com/bazelbuild/bazel.git", |
| 104 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazel/master/.bazelci/postsubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 105 | "pipeline_slug": "bazel-bazel", |
Yun Peng | 8910fa3 | 2019-01-03 08:58:16 +0100 | [diff] [blame] | 106 | }, |
Tobias Werth | d848eca | 2019-05-14 15:08:35 +0200 | [diff] [blame] | 107 | "Bazel Bench": { |
| 108 | "git_repository": "https://github.com/bazelbuild/bazel-bench.git", |
joeleba | 92ffec8 | 2019-05-22 14:50:15 +0200 | [diff] [blame] | 109 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazel-bench/master/.bazelci/postsubmit.yml", |
Tobias Werth | d848eca | 2019-05-14 15:08:35 +0200 | [diff] [blame] | 110 | "pipeline_slug": "bazel-bench", |
| 111 | }, |
Philipp Wollermann | fefcbf4 | 2019-05-28 14:28:40 +0200 | [diff] [blame] | 112 | "Bazel Codelabs": { |
| 113 | "git_repository": "https://github.com/bazelbuild/codelabs.git", |
| 114 | "http_config": "https://raw.githubusercontent.com/bazelbuild/codelabs/master/.bazelci/presubmit.yml", |
| 115 | "pipeline_slug": "bazel-codelabs", |
Yun Peng | 88d80ae | 2020-11-19 16:23:49 +0100 | [diff] [blame] | 116 | "disabled_reason": "https://github.com/bazelbuild/codelabs/issues/38", |
Philipp Wollermann | fefcbf4 | 2019-05-28 14:28:40 +0200 | [diff] [blame] | 117 | }, |
Jin | fce9b30 | 2019-08-08 15:18:26 -0400 | [diff] [blame] | 118 | "Bazel Examples": { |
| 119 | "git_repository": "https://github.com/bazelbuild/examples.git", |
| 120 | "http_config": "https://raw.githubusercontent.com/bazelbuild/examples/master/.bazelci/presubmit.yml", |
| 121 | "pipeline_slug": "bazel-bazel-examples", |
| 122 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 123 | "Bazel Remote Cache": { |
| 124 | "git_repository": "https://github.com/buchgr/bazel-remote.git", |
| 125 | "http_config": "https://raw.githubusercontent.com/buchgr/bazel-remote/master/.bazelci/presubmit.yml", |
| 126 | "pipeline_slug": "bazel-remote-cache", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 127 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 128 | "Bazel skylib": { |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 129 | "git_repository": "https://github.com/bazelbuild/bazel-skylib.git", |
Alexandre Rostovtsev | d414d0d | 2021-04-16 13:44:35 -0400 | [diff] [blame] | 130 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazel-skylib/main/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 131 | "pipeline_slug": "bazel-skylib", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 132 | "owned_by_bazel": True, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 133 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 134 | "Bazel toolchains": { |
| 135 | "git_repository": "https://github.com/bazelbuild/bazel-toolchains.git", |
| 136 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazel-toolchains/master/.bazelci/presubmit.yml", |
| 137 | "pipeline_slug": "bazel-toolchains", |
| 138 | }, |
| 139 | "Bazel watcher": { |
| 140 | "git_repository": "https://github.com/bazelbuild/bazel-watcher.git", |
| 141 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazel-watcher/master/.bazelci/presubmit.yml", |
| 142 | "pipeline_slug": "bazel-watcher", |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 143 | "disabled_reason": "https://github.com/bazelbuild/bazel-watcher/issues/590", |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 144 | }, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 145 | "Bazelisk": { |
| 146 | "git_repository": "https://github.com/bazelbuild/bazelisk.git", |
| 147 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazelisk/master/.bazelci/config.yml", |
| 148 | "pipeline_slug": "bazelisk", |
| 149 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 150 | "Buildfarm": { |
| 151 | "git_repository": "https://github.com/bazelbuild/bazel-buildfarm.git", |
Philipp Wollermann | df1e19b | 2021-09-09 12:33:37 +0200 | [diff] [blame] | 152 | "http_config": "https://raw.githubusercontent.com/bazelbuild/bazel-buildfarm/main/.bazelci/presubmit.yml", |
Philipp Wollermann | 89e5d88 | 2021-09-09 12:44:29 +0200 | [diff] [blame] | 153 | "pipeline_slug": "buildfarm-farmer", |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 154 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 155 | "Buildtools": { |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 156 | "git_repository": "https://github.com/bazelbuild/buildtools.git", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 157 | "http_config": "https://raw.githubusercontent.com/bazelbuild/buildtools/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 158 | "pipeline_slug": "buildtools", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 159 | }, |
Yun Peng | 175bf3e | 2021-02-23 16:37:35 +0100 | [diff] [blame] | 160 | "Cargo-Raze": { |
| 161 | "git_repository": "https://github.com/google/cargo-raze.git", |
Yun Peng | 3ffde1c | 2021-12-07 10:50:28 +0100 | [diff] [blame] | 162 | "http_config": "https://raw.githubusercontent.com/google/cargo-raze/main/.bazelci/presubmit.yml", |
Yun Peng | 175bf3e | 2021-02-23 16:37:35 +0100 | [diff] [blame] | 163 | "pipeline_slug": "cargo-raze", |
Yun Peng | ab700d5 | 2023-05-08 13:16:44 +0200 | [diff] [blame] | 164 | "disabled_reason": "https://github.com/bazelbuild/continuous-integration/issues/1594 (broken by Xcode 14.2)", |
Yun Peng | 175bf3e | 2021-02-23 16:37:35 +0100 | [diff] [blame] | 165 | }, |
Yun Peng | 39a4258 | 2018-11-09 10:59:47 +0100 | [diff] [blame] | 166 | "CLion Plugin": { |
| 167 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 168 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/master/.bazelci/clion.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 169 | "pipeline_slug": "clion-plugin", |
Yun Peng | 39a4258 | 2018-11-09 10:59:47 +0100 | [diff] [blame] | 170 | }, |
Mai Hussien | 0731b4d | 2022-06-28 11:16:07 -0700 | [diff] [blame] | 171 | "CLion Plugin Google": { |
| 172 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 173 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/google/.bazelci/clion.yml", |
| 174 | "pipeline_slug": "clion-plugin-google", |
| 175 | }, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 176 | "Cartographer": { |
| 177 | "git_repository": "https://github.com/googlecartographer/cartographer.git", |
| 178 | "http_config": "https://raw.githubusercontent.com/googlecartographer/cartographer/master/.bazelci/presubmit.yml", |
| 179 | "pipeline_slug": "cartographer", |
| 180 | }, |
Philipp Wollermann | ee85078 | 2019-02-05 22:56:04 +0100 | [diff] [blame] | 181 | "Cloud Robotics Core": { |
Stefan Sauer | b4dd3f9 | 2019-02-05 22:44:28 +0100 | [diff] [blame] | 182 | "git_repository": "https://github.com/googlecloudrobotics/core.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 183 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/cloud-robotics.yml", |
Stefan Sauer | b4dd3f9 | 2019-02-05 22:44:28 +0100 | [diff] [blame] | 184 | "pipeline_slug": "cloud-robotics-core", |
| 185 | }, |
Keith Smiley | 3b0ba60 | 2019-05-15 04:42:19 -0700 | [diff] [blame] | 186 | "Envoy": { |
| 187 | "git_repository": "https://github.com/envoyproxy/envoy.git", |
Yun Peng | 7ea4bc8 | 2022-12-01 12:58:08 +0100 | [diff] [blame] | 188 | "http_config": "https://raw.githubusercontent.com/envoyproxy/envoy/main/.bazelci/presubmit.yml", |
Keith Smiley | 3b0ba60 | 2019-05-15 04:42:19 -0700 | [diff] [blame] | 189 | "pipeline_slug": "envoy", |
| 190 | }, |
Florian Weikert | 1fe28b7 | 2019-07-02 12:47:55 +0200 | [diff] [blame] | 191 | "FlatBuffers": { |
| 192 | "git_repository": "https://github.com/google/flatbuffers.git", |
| 193 | "http_config": "https://raw.githubusercontent.com/google/flatbuffers/master/.bazelci/presubmit.yml", |
| 194 | "pipeline_slug": "flatbuffers", |
| 195 | }, |
Philipp Wollermann | f3750fa | 2019-05-21 17:11:59 +0200 | [diff] [blame] | 196 | "Flogger": { |
| 197 | "git_repository": "https://github.com/google/flogger.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 198 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/flogger.yml", |
Philipp Wollermann | f3750fa | 2019-05-21 17:11:59 +0200 | [diff] [blame] | 199 | "pipeline_slug": "flogger", |
| 200 | }, |
Marcel Hlopko | c884077 | 2018-10-23 12:51:46 +0200 | [diff] [blame] | 201 | "Gerrit": { |
| 202 | "git_repository": "https://gerrit.googlesource.com/gerrit.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 203 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/gerrit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 204 | "pipeline_slug": "gerrit", |
Marcel Hlopko | c884077 | 2018-10-23 12:51:46 +0200 | [diff] [blame] | 205 | }, |
Yun Peng | d662202 | 2018-11-05 13:10:26 +0100 | [diff] [blame] | 206 | "Google Logging": { |
| 207 | "git_repository": "https://github.com/google/glog.git", |
Philipp Wollermann | 17e5fc6 | 2021-02-15 14:48:36 +0100 | [diff] [blame] | 208 | "http_config": "https://raw.githubusercontent.com/google/glog/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 209 | "pipeline_slug": "google-logging", |
Yun Peng | ab700d5 | 2023-05-08 13:16:44 +0200 | [diff] [blame] | 210 | "disabled_reason": "Waiting on https://github.com/google/glog/pull/916", |
Yun Peng | d662202 | 2018-11-05 13:10:26 +0100 | [diff] [blame] | 211 | }, |
Yun Peng | 9586db5 | 2018-11-02 10:48:40 +0100 | [diff] [blame] | 212 | "IntelliJ Plugin": { |
| 213 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 214 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/master/.bazelci/intellij.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 215 | "pipeline_slug": "intellij-plugin", |
Yun Peng | 9586db5 | 2018-11-02 10:48:40 +0100 | [diff] [blame] | 216 | }, |
Mai Hussien | 0731b4d | 2022-06-28 11:16:07 -0700 | [diff] [blame] | 217 | "IntelliJ Plugin Google": { |
| 218 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 219 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/google/.bazelci/intellij.yml", |
| 220 | "pipeline_slug": "intellij-plugin-google", |
| 221 | }, |
| 222 | "IntelliJ UE Plugin": { |
| 223 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 224 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/master/.bazelci/intellij-ue.yml", |
| 225 | "pipeline_slug": "intellij-ue-plugin", |
| 226 | }, |
| 227 | "IntelliJ UE Plugin Google": { |
| 228 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 229 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/google/.bazelci/intellij-ue.yml", |
| 230 | "pipeline_slug": "intellij-ue-plugin-google", |
| 231 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 232 | "IntelliJ Plugin Aspect": { |
| 233 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 234 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/master/.bazelci/aspect.yml", |
| 235 | "pipeline_slug": "intellij-plugin-aspect", |
| 236 | }, |
Mai Hussien | 0731b4d | 2022-06-28 11:16:07 -0700 | [diff] [blame] | 237 | "IntelliJ Plugin Aspect Google": { |
| 238 | "git_repository": "https://github.com/bazelbuild/intellij.git", |
| 239 | "http_config": "https://raw.githubusercontent.com/bazelbuild/intellij/google/.bazelci/aspect.yml", |
| 240 | "pipeline_slug": "intellij-plugin-aspect-google", |
| 241 | }, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 242 | "Kythe": { |
| 243 | "git_repository": "https://github.com/kythe/kythe.git", |
| 244 | "http_config": "https://raw.githubusercontent.com/kythe/kythe/master/.bazelci/presubmit.yml", |
| 245 | "pipeline_slug": "kythe", |
| 246 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 247 | "Protobuf": { |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 248 | "git_repository": "https://github.com/google/protobuf.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 249 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/protobuf.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 250 | "pipeline_slug": "protobuf", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 251 | "owned_by_bazel": True, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 252 | }, |
Laurent Le Brun | f6326d6 | 2020-07-28 18:24:10 +0200 | [diff] [blame] | 253 | "Stardoc": { |
| 254 | "git_repository": "https://github.com/bazelbuild/stardoc.git", |
| 255 | "http_config": "https://raw.githubusercontent.com/bazelbuild/stardoc/master/.bazelci/presubmit.yml", |
| 256 | "pipeline_slug": "stardoc", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 257 | "owned_by_bazel": True, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 258 | }, |
| 259 | "Subpar": { |
| 260 | "git_repository": "https://github.com/google/subpar.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 261 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/subpar.yml", |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 262 | "pipeline_slug": "subpar", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 263 | "owned_by_bazel": True, |
Xùdōng Yáng | 26e280f | 2021-07-20 23:33:07 +1000 | [diff] [blame] | 264 | "disabled_reason": "https://github.com/google/subpar/issues/133", |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 265 | }, |
| 266 | "TensorFlow": { |
| 267 | "git_repository": "https://github.com/tensorflow/tensorflow.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 268 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/tensorflow.yml", |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 269 | "pipeline_slug": "tensorflow", |
Yun Peng | ab700d5 | 2023-05-08 13:16:44 +0200 | [diff] [blame] | 270 | "disabled_reason": "https://github.com/tensorflow/tensorflow/issues/60508", |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 271 | }, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 272 | "re2": { |
| 273 | "git_repository": "https://github.com/google/re2.git", |
Philipp Wollermann | dd8cf92 | 2021-10-01 15:43:33 +0200 | [diff] [blame] | 274 | "http_config": "https://raw.githubusercontent.com/bazelbuild/continuous-integration/master/pipelines/re2.yml", |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 275 | "pipeline_slug": "re2", |
| 276 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 277 | "rules_android": { |
| 278 | "git_repository": "https://github.com/bazelbuild/rules_android.git", |
| 279 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_android/master/.bazelci/postsubmit.yml", |
| 280 | "pipeline_slug": "rules-android", |
Yun Peng | c0575c8 | 2020-06-03 11:27:45 +0200 | [diff] [blame] | 281 | "disabled_reason": "https://github.com/bazelbuild/rules_android/issues/15", |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 282 | }, |
Keith Smiley | 2e3d7c8 | 2022-09-09 00:47:51 -0700 | [diff] [blame] | 283 | "rules_android_ndk": { |
Yun Peng | 687ad6b | 2022-09-15 11:00:02 +0200 | [diff] [blame] | 284 | "git_repository": "https://github.com/bazelbuild/rules_android_ndk.git", |
Keith Smiley | 2e3d7c8 | 2022-09-09 00:47:51 -0700 | [diff] [blame] | 285 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_android_ndk/main/.bazelci/presubmit.yml", |
| 286 | "pipeline_slug": "rules-android-ndk", |
| 287 | }, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 288 | "rules_appengine": { |
| 289 | "git_repository": "https://github.com/bazelbuild/rules_appengine.git", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 290 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_appengine/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 291 | "pipeline_slug": "rules-appengine-appengine", |
Yun Peng | e4816d7 | 2022-05-04 15:33:40 -0700 | [diff] [blame] | 292 | "disabled_reason": "https://github.com/bazelbuild/rules_appengine/issues/127", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 293 | }, |
Yun Peng | 809f27b | 2018-11-13 10:15:39 +0100 | [diff] [blame] | 294 | "rules_apple": { |
| 295 | "git_repository": "https://github.com/bazelbuild/rules_apple.git", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 296 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_apple/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 297 | "pipeline_slug": "rules-apple-darwin", |
Yun Peng | 809f27b | 2018-11-13 10:15:39 +0100 | [diff] [blame] | 298 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 299 | "rules_cc": { |
| 300 | "git_repository": "https://github.com/bazelbuild/rules_cc.git", |
aiuto | 560809f | 2021-08-17 14:51:32 -0400 | [diff] [blame] | 301 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_cc/main/.bazelci/presubmit.yml", |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 302 | "pipeline_slug": "rules-cc", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 303 | "owned_by_bazel": True, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 304 | }, |
Marcel Hlopko | 340dfd2 | 2018-10-19 11:33:01 +0200 | [diff] [blame] | 305 | "rules_closure": { |
| 306 | "git_repository": "https://github.com/bazelbuild/rules_closure.git", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 307 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_closure/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 308 | "pipeline_slug": "rules-closure-closure-compiler", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 309 | "owned_by_bazel": True, |
Marcel Hlopko | 340dfd2 | 2018-10-19 11:33:01 +0200 | [diff] [blame] | 310 | }, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 311 | "rules_docker": { |
| 312 | "git_repository": "https://github.com/bazelbuild/rules_docker.git", |
| 313 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_docker/master/.bazelci/presubmit.yml", |
Jakob Buchgraber | a6a8ea8 | 2018-12-07 13:51:02 +0100 | [diff] [blame] | 314 | "pipeline_slug": "rules-docker-docker", |
Yun Peng | cfbab26 | 2021-12-23 13:01:06 +0100 | [diff] [blame] | 315 | "disabled_reason": "https://github.com/bazelbuild/rules_docker/issues/1988", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 316 | }, |
Florian Weikert | 5569c11 | 2021-04-01 14:04:33 +0200 | [diff] [blame] | 317 | "rules_dotnet": { |
| 318 | "git_repository": "https://github.com/bazelbuild/rules_dotnet.git", |
| 319 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_dotnet/master/.bazelci/presubmit.yml", |
| 320 | "pipeline_slug": "rules-dotnet-edge", |
| 321 | }, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 322 | "rules_foreign_cc": { |
| 323 | "git_repository": "https://github.com/bazelbuild/rules_foreign_cc.git", |
mai93 | 2d49452 | 2021-03-30 18:34:05 +0200 | [diff] [blame] | 324 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_foreign_cc/main/.bazelci/config.yaml", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 325 | "pipeline_slug": "rules-foreign-cc", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 326 | "owned_by_bazel": True, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 327 | }, |
Xin | db02c01 | 2018-11-07 14:10:54 -0500 | [diff] [blame] | 328 | "rules_go": { |
| 329 | "git_repository": "https://github.com/bazelbuild/rules_go.git", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 330 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_go/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 331 | "pipeline_slug": "rules-go-golang", |
Yun Peng | b7247ff | 2018-11-15 13:52:39 +0100 | [diff] [blame] | 332 | }, |
Yun Peng | 7deea57 | 2018-11-05 10:47:45 +0100 | [diff] [blame] | 333 | "rules_groovy": { |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 334 | "git_repository": "https://github.com/bazelbuild/rules_groovy.git", |
| 335 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_groovy/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 336 | "pipeline_slug": "rules-groovy", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 337 | }, |
| 338 | "rules_gwt": { |
| 339 | "git_repository": "https://github.com/bazelbuild/rules_gwt.git", |
| 340 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_gwt/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 341 | "pipeline_slug": "rules-gwt", |
Xùdōng Yáng | 99b86b3 | 2021-08-18 23:42:05 +1000 | [diff] [blame] | 342 | "disabled_reason": "https://github.com/bazelbuild/continuous-integration/issues/1202", |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 343 | }, |
Florian Weikert | ff6444e | 2019-09-16 16:08:57 +0200 | [diff] [blame] | 344 | "rules_haskell": { |
| 345 | "git_repository": "https://github.com/tweag/rules_haskell.git", |
| 346 | "http_config": "https://raw.githubusercontent.com/tweag/rules_haskell/master/.bazelci/presubmit.yml", |
| 347 | "pipeline_slug": "rules-haskell-haskell", |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 348 | }, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 349 | "rules_jsonnet": { |
| 350 | "git_repository": "https://github.com/bazelbuild/rules_jsonnet.git", |
| 351 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_jsonnet/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 352 | "pipeline_slug": "rules-jsonnet", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 353 | }, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 354 | "rules_jvm_external": { |
| 355 | "git_repository": "https://github.com/bazelbuild/rules_jvm_external.git", |
| 356 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_jvm_external/master/.bazelci/presubmit.yml", |
| 357 | "pipeline_slug": "rules-jvm-external", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 358 | "owned_by_bazel": True, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 359 | }, |
| 360 | "rules_jvm_external - examples": { |
| 361 | "git_repository": "https://github.com/bazelbuild/rules_jvm_external.git", |
| 362 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_jvm_external/master/.bazelci/examples.yml", |
| 363 | "pipeline_slug": "rules-jvm-external-examples", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 364 | "owned_by_bazel": True, |
Philipp Wollermann | 1dc7699 | 2019-05-28 16:42:51 +0200 | [diff] [blame] | 365 | }, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 366 | "rules_k8s": { |
| 367 | "git_repository": "https://github.com/bazelbuild/rules_k8s.git", |
| 368 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_k8s/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 369 | "pipeline_slug": "rules-k8s-k8s", |
Yun Peng | 9b1d343 | 2021-12-07 10:40:45 +0100 | [diff] [blame] | 370 | "disabled_reason": "https://github.com/bazelbuild/rules_k8s/issues/668", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 371 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 372 | "rules_kotlin": { |
| 373 | "git_repository": "https://github.com/bazelbuild/rules_kotlin.git", |
| 374 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_kotlin/master/.bazelci/presubmit.yml", |
| 375 | "pipeline_slug": "rules-kotlin-kotlin", |
| 376 | }, |
Yun Peng | a5650e1 | 2018-11-14 10:16:06 +0100 | [diff] [blame] | 377 | "rules_nodejs": { |
| 378 | "git_repository": "https://github.com/bazelbuild/rules_nodejs.git", |
Alex Eagle | 5ba0e7f | 2023-04-13 02:04:46 -0700 | [diff] [blame] | 379 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_nodejs/main/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 380 | "pipeline_slug": "rules-nodejs-nodejs", |
Yun Peng | a5650e1 | 2018-11-14 10:16:06 +0100 | [diff] [blame] | 381 | }, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 382 | "rules_perl": { |
| 383 | "git_repository": "https://github.com/bazelbuild/rules_perl.git", |
Philipp Wollermann | df8afd5 | 2022-02-08 16:36:10 +0100 | [diff] [blame] | 384 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_perl/main/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 385 | "pipeline_slug": "rules-perl", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 386 | }, |
Yannic | 6110b3c | 2019-08-12 15:09:37 +0000 | [diff] [blame] | 387 | "rules_proto": { |
| 388 | "git_repository": "https://github.com/bazelbuild/rules_proto.git", |
| 389 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_proto/master/.bazelci/presubmit.yml", |
| 390 | "pipeline_slug": "rules-proto", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 391 | "owned_by_bazel": True, |
Yannic | 6110b3c | 2019-08-12 15:09:37 +0000 | [diff] [blame] | 392 | }, |
Yun Peng | 3d5a8a6 | 2018-11-19 11:42:01 +0100 | [diff] [blame] | 393 | "rules_python": { |
| 394 | "git_repository": "https://github.com/bazelbuild/rules_python.git", |
Florian Weikert | f126dfc | 2021-07-05 15:39:24 +0200 | [diff] [blame] | 395 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_python/main/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 396 | "pipeline_slug": "rules-python-python", |
Yun Peng | 667750b | 2020-02-20 14:06:43 +0100 | [diff] [blame] | 397 | "owned_by_bazel": True, |
Yun Peng | 3d5a8a6 | 2018-11-19 11:42:01 +0100 | [diff] [blame] | 398 | }, |
Xin | db02c01 | 2018-11-07 14:10:54 -0500 | [diff] [blame] | 399 | "rules_rust": { |
| 400 | "git_repository": "https://github.com/bazelbuild/rules_rust.git", |
Yun Peng | 1e56ce8 | 2022-11-04 16:31:49 +0100 | [diff] [blame] | 401 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_rust/main/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 402 | "pipeline_slug": "rules-rust-rustlang", |
Xin | db02c01 | 2018-11-07 14:10:54 -0500 | [diff] [blame] | 403 | }, |
Yun Peng | ca62fff | 2018-10-31 11:22:03 +0100 | [diff] [blame] | 404 | "rules_sass": { |
| 405 | "git_repository": "https://github.com/bazelbuild/rules_sass.git", |
Paul Gschwendtner | 63ed21b | 2022-03-22 14:42:42 +0100 | [diff] [blame] | 406 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_sass/main/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 407 | "pipeline_slug": "rules-sass", |
Yun Peng | ca62fff | 2018-10-31 11:22:03 +0100 | [diff] [blame] | 408 | }, |
Xin | db02c01 | 2018-11-07 14:10:54 -0500 | [diff] [blame] | 409 | "rules_scala": { |
| 410 | "git_repository": "https://github.com/bazelbuild/rules_scala.git", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 411 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_scala/master/.bazelci/presubmit.yml", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 412 | "pipeline_slug": "rules-scala-scala", |
Xùdōng Yáng | 79deb04 | 2022-09-15 12:26:36 +0200 | [diff] [blame] | 413 | "disabled_reason": "waiting on https://github.com/bazelbuild/rules_scala/pull/1422", |
Xin | db02c01 | 2018-11-07 14:10:54 -0500 | [diff] [blame] | 414 | }, |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 415 | "rules_swift": { |
| 416 | "git_repository": "https://github.com/bazelbuild/rules_swift.git", |
| 417 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_swift/master/.bazelci/presubmit.yml", |
| 418 | "pipeline_slug": "rules-swift-swift", |
| 419 | }, |
Richard Levasseur | a9690c6 | 2023-03-06 08:39:36 -0800 | [diff] [blame] | 420 | "rules_testing": { |
| 421 | "git_repository": "https://github.com/bazelbuild/rules_testing.git", |
| 422 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_testing/master/.bazelci/presubmit.yml", |
| 423 | "pipeline_slug": "rules-testing", |
| 424 | "owned_by_bazel": True, |
| 425 | }, |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 426 | "rules_webtesting": { |
| 427 | "git_repository": "https://github.com/bazelbuild/rules_webtesting.git", |
Yun Peng | c2fab33 | 2019-01-04 10:53:49 +0100 | [diff] [blame] | 428 | "http_config": "https://raw.githubusercontent.com/bazelbuild/rules_webtesting/master/.bazelci/presubmit.yml", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 429 | "pipeline_slug": "rules-webtesting-saucelabs", |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 430 | }, |
Philipp Wollermann | 389acd8 | 2019-05-21 17:41:48 +0200 | [diff] [blame] | 431 | "upb": { |
| 432 | "git_repository": "https://github.com/protocolbuffers/upb.git", |
| 433 | "http_config": "https://raw.githubusercontent.com/protocolbuffers/upb/master/.bazelci/presubmit.yml", |
| 434 | "pipeline_slug": "upb", |
Yun Peng | ab700d5 | 2023-05-08 13:16:44 +0200 | [diff] [blame] | 435 | "disabled_reason": "https://github.com/protocolbuffers/upb/issues/1290", |
Philipp Wollermann | 389acd8 | 2019-05-21 17:41:48 +0200 | [diff] [blame] | 436 | }, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 439 | DOWNSTREAM_PROJECTS_TESTING = { |
Philipp Wollermann | bed211d | 2019-06-07 11:38:59 +0200 | [diff] [blame] | 440 | "Bazel": DOWNSTREAM_PROJECTS_PRODUCTION["Bazel"], |
| 441 | "Bazelisk": DOWNSTREAM_PROJECTS_PRODUCTION["Bazelisk"], |
Philipp Wollermann | bed211d | 2019-06-07 11:38:59 +0200 | [diff] [blame] | 442 | "rules_docker": DOWNSTREAM_PROJECTS_PRODUCTION["rules_docker"], |
| 443 | "rules_go": DOWNSTREAM_PROJECTS_PRODUCTION["rules_go"], |
| 444 | "rules_groovy": DOWNSTREAM_PROJECTS_PRODUCTION["rules_groovy"], |
| 445 | "rules_kotlin": DOWNSTREAM_PROJECTS_PRODUCTION["rules_kotlin"], |
| 446 | "rules_nodejs": DOWNSTREAM_PROJECTS_PRODUCTION["rules_nodejs"], |
| 447 | "rules_rust": DOWNSTREAM_PROJECTS_PRODUCTION["rules_rust"], |
| 448 | "rules_scala": DOWNSTREAM_PROJECTS_PRODUCTION["rules_scala"], |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | DOWNSTREAM_PROJECTS = { |
| 452 | "bazel-testing": DOWNSTREAM_PROJECTS_TESTING, |
| 453 | "bazel-trusted": {}, |
| 454 | "bazel": DOWNSTREAM_PROJECTS_PRODUCTION, |
| 455 | }[BUILDKITE_ORG] |
Philipp Wollermann | 6dd7aa3 | 2019-02-05 22:42:15 +0100 | [diff] [blame] | 456 | |
Philipp Wollermann | 81a8841 | 2019-07-12 10:34:33 +0200 | [diff] [blame] | 457 | DOCKER_REGISTRY_PREFIX = { |
| 458 | "bazel-testing": "bazel-public/testing", |
| 459 | "bazel-trusted": "bazel-public", |
| 460 | "bazel": "bazel-public", |
| 461 | }[BUILDKITE_ORG] |
| 462 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 463 | # A map containing all supported platform names as keys, with the values being |
| 464 | # the platform name in a human readable format, and a the buildkite-agent's |
| 465 | # working directory. |
| 466 | PLATFORMS = { |
Philipp Wollermann | effcd6e | 2019-06-21 18:30:34 +0200 | [diff] [blame] | 467 | "centos7": { |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 468 | "name": "CentOS 7 (OpenJDK 8, gcc 4.8.5)", |
| 469 | "emoji-name": ":centos: 7 (OpenJDK 8, gcc 4.8.5)", |
Philipp Wollermann | effcd6e | 2019-06-21 18:30:34 +0200 | [diff] [blame] | 470 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 2897871 | 2021-10-21 19:09:29 +0200 | [diff] [blame] | 471 | "publish_binary": [], |
Philipp Wollermann | 5d6765d | 2020-02-17 17:12:02 +0100 | [diff] [blame] | 472 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/centos7-java8", |
Philipp Wollermann | effcd6e | 2019-06-21 18:30:34 +0200 | [diff] [blame] | 473 | "python": "python3.6", |
| 474 | }, |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 475 | "centos7_java11": { |
| 476 | "name": "CentOS 7 (OpenJDK 11, gcc 4.8.5)", |
| 477 | "emoji-name": ":centos: 7 (OpenJDK 11, gcc 4.8.5)", |
| 478 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 479 | "publish_binary": [], |
| 480 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/centos7-java11", |
| 481 | "python": "python3.6", |
| 482 | }, |
| 483 | "centos7_java11_devtoolset10": { |
| 484 | "name": "CentOS 7 (OpenJDK 11, gcc 10.2.1)", |
| 485 | "emoji-name": ":centos: 7 (OpenJDK 11, gcc 10.2.1)", |
| 486 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 2897871 | 2021-10-21 19:09:29 +0200 | [diff] [blame] | 487 | "publish_binary": ["ubuntu1404", "centos7", "linux"], |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 488 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/centos7-java11-devtoolset10", |
| 489 | "python": "python3.6", |
| 490 | }, |
Philipp Wollermann | 67fc371 | 2019-06-12 15:39:21 +0200 | [diff] [blame] | 491 | "debian10": { |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 492 | "name": "Debian 10 Buster (OpenJDK 11, gcc 8.3.0)", |
| 493 | "emoji-name": ":debian: 10 Buster (OpenJDK 11, gcc 8.3.0)", |
Philipp Wollermann | 67fc371 | 2019-06-12 15:39:21 +0200 | [diff] [blame] | 494 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 495 | "publish_binary": [], |
Philipp Wollermann | 5d6765d | 2020-02-17 17:12:02 +0100 | [diff] [blame] | 496 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/debian10-java11", |
Philipp Wollermann | 67fc371 | 2019-06-12 15:39:21 +0200 | [diff] [blame] | 497 | "python": "python3.7", |
| 498 | }, |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 499 | "debian11": { |
| 500 | "name": "Debian 11 Bullseye (OpenJDK 17, gcc 10.2.1)", |
| 501 | "emoji-name": ":debian: 11 Buster (OpenJDK 17, gcc 10.2.1)", |
| 502 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 503 | "publish_binary": [], |
| 504 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/debian11-java17", |
| 505 | "python": "python3.9", |
| 506 | }, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 507 | "ubuntu1604": { |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 508 | "name": "Ubuntu 16.04 LTS (OpenJDK 8, gcc 5.4.0)", |
| 509 | "emoji-name": ":ubuntu: 16.04 LTS (OpenJDK 8, gcc 5.4.0)", |
Philipp Wollermann | d551bf6 | 2019-05-18 22:04:35 +0200 | [diff] [blame] | 510 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 6404708 | 2021-10-21 21:26:25 +0200 | [diff] [blame] | 511 | "publish_binary": [], |
Philipp Wollermann | 5d6765d | 2020-02-17 17:12:02 +0100 | [diff] [blame] | 512 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu1604-java8", |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 513 | "python": "python3.6", |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 514 | }, |
| 515 | "ubuntu1804": { |
Florian Weikert | d02ea36 | 2022-09-15 13:51:17 +0200 | [diff] [blame] | 516 | "name": "Ubuntu 18.04 LTS (OpenJDK 11, gcc 7.5.0)", |
| 517 | "emoji-name": ":ubuntu: 18.04 LTS (OpenJDK 11, gcc 7.5.0)", |
Philipp Wollermann | d551bf6 | 2019-05-18 22:04:35 +0200 | [diff] [blame] | 518 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 519 | "publish_binary": ["ubuntu1804"], |
Philipp Wollermann | 5d6765d | 2020-02-17 17:12:02 +0100 | [diff] [blame] | 520 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu1804-java11", |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 521 | "python": "python3.6", |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 522 | }, |
Mostyn Bramley-Moore | ab4599e | 2020-06-23 20:31:01 +0200 | [diff] [blame] | 523 | "ubuntu2004": { |
Florian Weikert | d02ea36 | 2022-09-15 13:51:17 +0200 | [diff] [blame] | 524 | "name": "Ubuntu 20.04 LTS (OpenJDK 11, gcc 9.4.0)", |
| 525 | "emoji-name": ":ubuntu: 20.04 LTS (OpenJDK 11, gcc 9.4.0)", |
Mostyn Bramley-Moore | ab4599e | 2020-06-23 20:31:01 +0200 | [diff] [blame] | 526 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 55f72ac | 2020-09-21 22:22:05 +0200 | [diff] [blame] | 527 | "publish_binary": [], |
Mostyn Bramley-Moore | ab4599e | 2020-06-23 20:31:01 +0200 | [diff] [blame] | 528 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu2004-java11", |
| 529 | "python": "python3.8", |
| 530 | }, |
Yun Peng | 07dafc5 | 2022-03-16 13:23:35 +0100 | [diff] [blame] | 531 | "ubuntu2004_arm64": { |
Florian Weikert | d02ea36 | 2022-09-15 13:51:17 +0200 | [diff] [blame] | 532 | "name": "Ubuntu 20.04 LTS ARM64 (OpenJDK 11, gcc 9.4.0)", |
| 533 | "emoji-name": ":ubuntu: 20.04 LTS ARM64 (OpenJDK 11, gcc 9.4.0)", |
Yun Peng | 07dafc5 | 2022-03-16 13:23:35 +0100 | [diff] [blame] | 534 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 535 | "publish_binary": [], |
| 536 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu2004-java11", |
| 537 | "python": "python3.8", |
| 538 | "queue": "arm64", |
| 539 | # TODO: Re-enable always-pull if we also publish docker containers for Linux ARM64 |
| 540 | "always-pull": False, |
| 541 | }, |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 542 | "kythe_ubuntu2004": { |
Florian Weikert | d02ea36 | 2022-09-15 13:51:17 +0200 | [diff] [blame] | 543 | "name": "Kythe (Ubuntu 20.04 LTS, OpenJDK 11, gcc 9.4.0)", |
| 544 | "emoji-name": "Kythe (:ubuntu: 20.04 LTS, OpenJDK 11, gcc 9.4.0)", |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 545 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 546 | "publish_binary": [], |
| 547 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu2004-java11-kythe", |
| 548 | "python": "python3.8", |
| 549 | }, |
Florian Weikert | dcc7520 | 2022-09-06 16:34:04 +0200 | [diff] [blame] | 550 | "ubuntu2204": { |
| 551 | "name": "Ubuntu 22.04 (OpenJDK 17, gcc 11.2.0)", |
| 552 | "emoji-name": ":ubuntu: 22.04 (OpenJDK 17, gcc 11.2.0)", |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 553 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 554 | "publish_binary": [], |
Florian Weikert | dcc7520 | 2022-09-06 16:34:04 +0200 | [diff] [blame] | 555 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu2204-java17", |
Philipp Wollermann | b6a399a | 2021-10-22 07:57:26 +0200 | [diff] [blame] | 556 | "python": "python3", |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 557 | }, |
David Ostrovsky | ba4478f | 2023-05-08 16:24:04 +0200 | [diff] [blame] | 558 | "fedora39": { |
| 559 | "name": "Fedora 39 (OpenJDK 17, gcc 13.1.1)", |
| 560 | "emoji-name": ":fedora: 39 (OpenJDK 17, gcc 13.1.1)", |
| 561 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 562 | "publish_binary": [], |
| 563 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/fedora39-java17", |
| 564 | "python": "python3", |
| 565 | }, |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 566 | "macos": { |
Philipp Wollermann | 5e3d09f | 2021-10-21 01:03:01 +0200 | [diff] [blame] | 567 | "name": "macOS (OpenJDK 11, Xcode)", |
| 568 | "emoji-name": ":darwin: (OpenJDK 11, Xcode)", |
Philipp Wollermann | 51147bf | 2019-05-08 15:50:10 +0200 | [diff] [blame] | 569 | "downstream-root": "/Users/buildkite/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 570 | "publish_binary": ["macos"], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 571 | "queue": "macos", |
Philipp Wollermann | 89d3649 | 2021-02-16 11:59:09 +0100 | [diff] [blame] | 572 | "python": "python3", |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 573 | }, |
Florian Weikert | a87e6f3 | 2023-04-14 19:58:32 +0200 | [diff] [blame] | 574 | "macos_qa": { |
| 575 | "name": "macOS QA (OpenJDK 11, Xcode)", |
| 576 | "emoji-name": ":darwin: :fire_extinguisher: (OpenJDK 11, Xcode)", |
| 577 | "downstream-root": "/Users/buildkite/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
| 578 | "publish_binary": [], |
| 579 | "queue": "macos_qa", |
| 580 | "python": "python3", |
| 581 | }, |
Yun Peng | 46d4391 | 2021-04-21 09:49:53 +0200 | [diff] [blame] | 582 | "macos_arm64": { |
Philipp Wollermann | 9af2b43 | 2021-10-20 22:37:17 +0200 | [diff] [blame] | 583 | "name": "macOS arm64 (OpenJDK 8, Xcode)", |
| 584 | "emoji-name": ":darwin: arm64 (OpenJDK 8, Xcode)", |
Yun Peng | 46d4391 | 2021-04-21 09:49:53 +0200 | [diff] [blame] | 585 | "downstream-root": "/Users/buildkite/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Yun Peng | 83f3277 | 2021-04-21 11:22:35 +0200 | [diff] [blame] | 586 | "publish_binary": ["macos_arm64"], |
Yun Peng | ab92213 | 2022-11-18 20:28:02 +0100 | [diff] [blame] | 587 | "queue": "macos_arm64", |
Yun Peng | 46d4391 | 2021-04-21 09:49:53 +0200 | [diff] [blame] | 588 | "python": "python3", |
| 589 | }, |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 590 | "windows": { |
Yun Peng | 8d7a2a5 | 2022-09-09 14:56:49 +0200 | [diff] [blame] | 591 | "name": "Windows (OpenJDK 11, VS2019)", |
| 592 | "emoji-name": ":windows: (OpenJDK 11, VS2019)", |
Philipp Wollermann | d5ab3d9 | 2020-02-05 16:55:13 +0100 | [diff] [blame] | 593 | "downstream-root": "c:/b/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 594 | "publish_binary": ["windows"], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 595 | "queue": "windows", |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 596 | "python": "python.exe", |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 597 | }, |
Yun Peng | 6a7a670 | 2022-02-02 15:02:47 +0100 | [diff] [blame] | 598 | "windows_arm64": { |
Yun Peng | 8d7a2a5 | 2022-09-09 14:56:49 +0200 | [diff] [blame] | 599 | "name": "Windows ARM64 (OpenJDK 11, VS2019)", |
| 600 | "emoji-name": ":windows: arm64 (OpenJDK 11, VS2019)", |
Yun Peng | 6a7a670 | 2022-02-02 15:02:47 +0100 | [diff] [blame] | 601 | "downstream-root": "c:/b/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Yun Peng | 0ae9eb7 | 2022-02-03 10:24:26 +0100 | [diff] [blame] | 602 | "publish_binary": ["windows_arm64"], |
Yun Peng | 6a7a670 | 2022-02-02 15:02:47 +0100 | [diff] [blame] | 603 | # TODO(pcloudy): Switch to windows_arm64 queue when Windows ARM64 machines are available, |
| 604 | # current we just use x86_64 machines to do cross compile. |
| 605 | "queue": "windows", |
| 606 | "python": "python.exe", |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 607 | }, |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 608 | "rbe_ubuntu1604": { |
Philipp Wollermann | db87733 | 2019-04-23 17:58:01 +0200 | [diff] [blame] | 609 | "name": "RBE (Ubuntu 16.04, OpenJDK 8)", |
Jakob Buchgraber | 1f37fbd | 2019-07-17 17:08:28 +0200 | [diff] [blame] | 610 | "emoji-name": "RBE (:ubuntu: 16.04, OpenJDK 8)", |
Philipp Wollermann | d551bf6 | 2019-05-18 22:04:35 +0200 | [diff] [blame] | 611 | "downstream-root": "/var/lib/buildkite-agent/builds/${BUILDKITE_AGENT_NAME}/${BUILDKITE_ORGANIZATION_SLUG}-downstream-projects", |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 612 | "publish_binary": [], |
Philipp Wollermann | 5d6765d | 2020-02-17 17:12:02 +0100 | [diff] [blame] | 613 | "docker-image": f"gcr.io/{DOCKER_REGISTRY_PREFIX}/ubuntu1604-java8", |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 614 | "python": "python3.6", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 615 | }, |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Philipp Wollermann | fce92bf | 2019-05-22 15:14:32 +0200 | [diff] [blame] | 618 | BUILDIFIER_DOCKER_IMAGE = "gcr.io/bazel-public/buildifier" |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 619 | |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 620 | # The platform used for various steps (e.g. stuff that formerly ran on the "pipeline" workers). |
| 621 | DEFAULT_PLATFORM = "ubuntu1804" |
| 622 | |
Philipp Wollermann | f4aabb7 | 2019-06-25 15:59:00 +0200 | [diff] [blame] | 623 | # In order to test that "the one Linux binary" that we build for our official releases actually |
| 624 | # works on all Linux distributions that we test on, we use the Linux binary built on our official |
| 625 | # release platform for all Linux downstream tests. |
Yun Peng | dae5a7d | 2022-01-11 16:08:58 +0100 | [diff] [blame] | 626 | LINUX_BINARY_PLATFORM = "centos7_java11_devtoolset10" |
Philipp Wollermann | f4aabb7 | 2019-06-25 15:59:00 +0200 | [diff] [blame] | 627 | |
Florian Weikert | f11f2bf | 2023-01-31 19:11:52 +0100 | [diff] [blame] | 628 | # Maps major MacOS version numbers to the Xcode version that should be activated on that particular OS |
| 629 | DEFAULT_XCODE_VERSION_PER_OS = {12: "13.0", 13: "14.2"} |
Philipp Wollermann | 380f1e6 | 2019-04-12 16:45:27 +0200 | [diff] [blame] | 630 | XCODE_VERSION_REGEX = re.compile(r"^\d+\.\d+(\.\d+)?$") |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 631 | XCODE_VERSION_OVERRIDES = {"10.2.1": "10.3", "11.2": "11.2.1", "11.3": "11.3.1"} |
Philipp Wollermann | 380f1e6 | 2019-04-12 16:45:27 +0200 | [diff] [blame] | 632 | |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 633 | BUILD_LABEL_PATTERN = re.compile(r"^Build label: (\S+)$", re.MULTILINE) |
| 634 | |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 635 | BUILDIFIER_STEP_NAME = "Buildifier" |
| 636 | |
Florian Weikert | 5f5d3cb | 2019-04-15 15:36:27 +0200 | [diff] [blame] | 637 | SKIP_TASKS_ENV_VAR = "CI_SKIP_TASKS" |
| 638 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 639 | # TODO: change to USE_BAZEL_DIFF once the feature has been tested in QA |
Florian Weikert | 7012a52 | 2023-05-04 16:49:40 +0200 | [diff] [blame] | 640 | USE_BAZEL_DIFF_ENV_VAR = "USE_BAZEL_DIFF" |
| 641 | |
Florian Weikert | 77d2006 | 2023-05-08 16:32:48 +0200 | [diff] [blame] | 642 | BAZEL_DIFF_ANNOTATION_CTX = "'diff'" |
| 643 | |
Florian Weikert | 7012a52 | 2023-05-04 16:49:40 +0200 | [diff] [blame] | 644 | # TODO(fweikert): Install bazel-diff on the Docker images and on the Mac machines |
| 645 | BAZEL_DIFF_URL = ( |
| 646 | "https://github.com/Tinder/bazel-diff/releases/download/4.5.0/bazel-diff_deploy.jar" |
| 647 | ) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 648 | |
| 649 | AUTO_DIFFBASE_VALUES = frozenset(["1", "true", "auto"]) |
| 650 | |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 651 | # Always run all test targets if any of the paths here are modified by the current commit. |
| 652 | # Values can be directory paths (with a trailing slash) or file paths. |
| 653 | DISABLE_BAZEL_DIFF_IF_MODIFIED = (".bazelci/", ".bazelversion") |
| 654 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 655 | COMMIT_RE = re.compile(r"[0-9a-z]{40}") |
| 656 | |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 657 | CONFIG_FILE_EXTENSIONS = {".yml", ".yaml"} |
Florian Weikert | 778251c | 2019-04-25 15:14:44 +0200 | [diff] [blame] | 658 | |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 659 | KYTHE_DIR = "/usr/local/kythe" |
| 660 | |
| 661 | INDEX_UPLOAD_POLICY_ALWAYS = "Always" |
| 662 | |
| 663 | INDEX_UPLOAD_POLICY_IF_BUILD_SUCCESS = "IfBuildSuccess" |
| 664 | |
| 665 | INDEX_UPLOAD_POLICY_NEVER = "Never" |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 666 | |
Yun Peng | 686f459 | 2022-01-17 15:38:48 +0100 | [diff] [blame] | 667 | # The maximum number of tasks allowed in one pipeline yaml config file. |
| 668 | # This is to prevent accidentally creating too many tasks with the martix testing feature. |
Yun Peng | 68e8a4c | 2022-06-15 18:31:41 +0200 | [diff] [blame] | 669 | MAX_TASK_NUMBER = 80 |
Yun Peng | 686f459 | 2022-01-17 15:38:48 +0100 | [diff] [blame] | 670 | |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 671 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 672 | class BuildkiteException(Exception): |
| 673 | """ |
| 674 | Raised whenever something goes wrong and we should exit with an error. |
| 675 | """ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 676 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 677 | pass |
| 678 | |
| 679 | |
Yun Peng | d433d4f | 2022-12-09 10:53:15 +0100 | [diff] [blame] | 680 | class BuildkiteInfraException(Exception): |
| 681 | """ |
| 682 | Raised whenever something goes wrong with the CI infra and we should immediately exit with an error. |
| 683 | """ |
| 684 | |
| 685 | pass |
| 686 | |
| 687 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 688 | class BinaryUploadRaceException(Exception): |
| 689 | """ |
| 690 | Raised when try_publish_binaries wasn't able to publish a set of binaries, |
| 691 | because the generation of the current file didn't match the expected value. |
| 692 | """ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 693 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 694 | pass |
| 695 | |
| 696 | |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 697 | class BuildkiteClient(object): |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 698 | _ENCRYPTED_BUILDKITE_API_TOKEN = """ |
| 699 | CiQA4DEB9ldzC+E39KomywtqXfaQ86hhulgeDsicds2BuvbCYzsSUAAqwcvXZPh9IMWlwWh94J2F |
| 700 | exosKKaWB0tSRJiPKnv2NPDfEqGul0ZwVjtWeASpugwxxKeLhFhPMcgHMPfndH6j2GEIY6nkKRbP |
| 701 | uwoRMCwe |
| 702 | """.strip() |
| 703 | |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 704 | _ENCRYPTED_BUILDKITE_API_TESTING_TOKEN = """ |
| 705 | CiQAMTBkWjL1C+F5oon3+cC1vmum5+c1y5+96WQY44p0Lxd0PeASUQAy7iU0c6E3W5EOSFYfD5fA |
| 706 | MWy/SHaMno1NQSUa4xDOl5yc2kizrtxPPVkX4x9pLNuGUY/xwAn2n1DdiUdWZNWlY1bX2C4ex65e |
| 707 | P9w8kNhEbw== |
| 708 | """.strip() |
| 709 | |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 710 | _BUILD_STATUS_URL_TEMPLATE = ( |
| 711 | "https://api.buildkite.com/v2/organizations/{}/pipelines/{}/builds/{}" |
| 712 | ) |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 713 | |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 714 | _NEW_BUILD_URL_TEMPLATE = "https://api.buildkite.com/v2/organizations/{}/pipelines/{}/builds" |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 715 | |
| 716 | _RETRY_JOB_URL_TEMPLATE = ( |
| 717 | "https://api.buildkite.com/v2/organizations/{}/pipelines/{}/builds/{}/jobs/{}/retry" |
| 718 | ) |
| 719 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 720 | _PIPELINE_INFO_URL_TEMPLATE = "https://api.buildkite.com/v2/organizations/{}/pipelines/{}" |
Mai Hussien | fe58c06 | 2022-07-07 01:29:46 -0700 | [diff] [blame] | 721 | |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 722 | def __init__(self, org, pipeline): |
| 723 | self._org = org |
| 724 | self._pipeline = pipeline |
| 725 | self._token = self._get_buildkite_token() |
| 726 | |
| 727 | def _get_buildkite_token(self): |
Florian Weikert | 849afb2 | 2019-12-14 12:22:29 -0800 | [diff] [blame] | 728 | return decrypt_token( |
| 729 | encrypted_token=self._ENCRYPTED_BUILDKITE_API_TESTING_TOKEN |
| 730 | if THIS_IS_TESTING |
| 731 | else self._ENCRYPTED_BUILDKITE_API_TOKEN, |
| 732 | kms_key="buildkite-testing-api-token" |
| 733 | if THIS_IS_TESTING |
| 734 | else "buildkite-untrusted-api-token", |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 735 | ) |
| 736 | |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 737 | def _open_url(self, url, params=[]): |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 738 | try: |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 739 | params_str = "".join("&{}={}".format(k, v) for k, v in params) |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 740 | return ( |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 741 | urllib.request.urlopen("{}?access_token={}{}".format(url, self._token, params_str)) |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 742 | .read() |
Yun Peng | dbedc12 | 2020-02-28 13:32:04 +0100 | [diff] [blame] | 743 | .decode("utf-8", "ignore") |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 744 | ) |
| 745 | except urllib.error.HTTPError as ex: |
| 746 | raise BuildkiteException("Failed to open {}: {} - {}".format(url, ex.code, ex.reason)) |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 747 | |
Mai Hussien | fe58c06 | 2022-07-07 01:29:46 -0700 | [diff] [blame] | 748 | def get_pipeline_info(self): |
| 749 | """Get details for a pipeline given its organization slug |
| 750 | and pipeline slug. |
| 751 | See https://buildkite.com/docs/apis/rest-api/pipelines#get-a-pipeline |
| 752 | |
| 753 | Returns |
| 754 | ------- |
| 755 | dict |
| 756 | the metadata for the pipeline |
| 757 | """ |
| 758 | url = self._PIPELINE_INFO_URL_TEMPLATE.format(self._org, self._pipeline) |
| 759 | output = self._open_url(url) |
| 760 | return json.loads(output) |
| 761 | |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 762 | def get_build_info(self, build_number): |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 763 | """Get build info for a pipeline with a given build number |
| 764 | See https://buildkite.com/docs/apis/rest-api/builds#get-a-build |
| 765 | |
| 766 | Parameters |
| 767 | ---------- |
| 768 | build_number : the build number |
| 769 | |
| 770 | Returns |
| 771 | ------- |
| 772 | dict |
| 773 | the metadata for the build |
| 774 | """ |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 775 | url = self._BUILD_STATUS_URL_TEMPLATE.format(self._org, self._pipeline, build_number) |
| 776 | output = self._open_url(url) |
| 777 | return json.loads(output) |
| 778 | |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 779 | def get_build_info_list(self, params): |
| 780 | """Get a list of build infos for this pipeline |
| 781 | See https://buildkite.com/docs/apis/rest-api/builds#list-builds-for-a-pipeline |
| 782 | |
| 783 | Parameters |
| 784 | ---------- |
| 785 | params : the parameters to filter the result |
| 786 | |
| 787 | Returns |
| 788 | ------- |
| 789 | list of dict |
| 790 | the metadata for a list of builds |
| 791 | """ |
| 792 | url = self._BUILD_STATUS_URL_TEMPLATE.format(self._org, self._pipeline, "") |
| 793 | output = self._open_url(url, params) |
| 794 | return json.loads(output) |
| 795 | |
Florian Weikert | a0e7459 | 2019-03-07 11:56:12 +0100 | [diff] [blame] | 796 | def get_build_log(self, job): |
| 797 | return self._open_url(job["raw_log_url"]) |
| 798 | |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 799 | @staticmethod |
| 800 | def _check_response(response, expected_status_code): |
| 801 | if response.status_code != expected_status_code: |
| 802 | eprint("Exit code:", response.status_code) |
| 803 | eprint("Response:\n", response.text) |
| 804 | response.raise_for_status() |
| 805 | |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 806 | def trigger_new_build(self, commit, message=None, env={}): |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 807 | """Trigger a new build at a given commit and return the build metadata. |
| 808 | See https://buildkite.com/docs/apis/rest-api/builds#create-a-build |
| 809 | |
| 810 | Parameters |
| 811 | ---------- |
| 812 | commit : the commit we want to build at |
| 813 | message : the message we should as the build titile |
| 814 | env : (optional) the environment variables to set |
| 815 | |
| 816 | Returns |
| 817 | ------- |
| 818 | dict |
| 819 | the metadata for the build |
| 820 | """ |
Salma Samy | f54c75b | 2022-11-04 16:28:18 +0200 | [diff] [blame] | 821 | pipeline_info = self.get_pipeline_info() |
| 822 | if not pipeline_info: |
| 823 | raise BuildkiteException(f"Cannot find pipeline info for pipeline {self._pipeline}.") |
| 824 | |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 825 | url = self._NEW_BUILD_URL_TEMPLATE.format(self._org, self._pipeline) |
| 826 | data = { |
| 827 | "commit": commit, |
Salma Samy | f54c75b | 2022-11-04 16:28:18 +0200 | [diff] [blame] | 828 | "branch": pipeline_info.get("default_branch") or "master", |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 829 | "message": message if message else f"Trigger build at {commit}", |
| 830 | "env": env, |
Yun Peng | 867b5a5 | 2022-01-11 13:59:41 +0100 | [diff] [blame] | 831 | "ignore_pipeline_branch_filters": "true", |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 832 | } |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 833 | response = requests.post(url + "?access_token=" + self._token, json=data) |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 834 | BuildkiteClient._check_response(response, requests.codes.created) |
| 835 | return json.loads(response.text) |
| 836 | |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 837 | def trigger_job_retry(self, build_number, job_id): |
| 838 | """Trigger a job retry and return the job metadata. |
| 839 | See https://buildkite.com/docs/apis/rest-api/jobs#retry-a-job |
| 840 | |
| 841 | Parameters |
| 842 | ---------- |
| 843 | build_number : the number of the build we want to retry |
| 844 | job_id : the id of the job we want to retry |
| 845 | |
| 846 | Returns |
| 847 | ------- |
| 848 | dict |
| 849 | the metadata for the job |
| 850 | """ |
| 851 | url = self._RETRY_JOB_URL_TEMPLATE.format(self._org, self._pipeline, build_number, job_id) |
| 852 | response = requests.put(url + "?access_token=" + self._token) |
| 853 | BuildkiteClient._check_response(response, requests.codes.ok) |
| 854 | return json.loads(response.text) |
| 855 | |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 856 | def wait_job_to_finish(self, build_number, job_id, interval_time=30, logger=None): |
| 857 | """Wait a job to finish and return the job metadata |
| 858 | |
| 859 | Parameters |
| 860 | ---------- |
| 861 | build_number : the number of the build we want to wait |
| 862 | job_id : the id of the job we want to wait |
| 863 | interval_time : (optional) the interval time to check the build status, default to 30s |
| 864 | logger : (optional) a logger to report progress |
| 865 | |
| 866 | Returns |
| 867 | ------- |
| 868 | dict |
| 869 | the latest metadata for the job |
| 870 | """ |
| 871 | t = 0 |
| 872 | build_info = self.get_build_info(build_number) |
| 873 | while True: |
| 874 | for job in build_info["jobs"]: |
| 875 | if job["id"] == job_id: |
| 876 | state = job["state"] |
| 877 | if state != "scheduled" and state != "running" and state != "assigned": |
| 878 | return job |
| 879 | break |
| 880 | else: |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 881 | raise BuildkiteException( |
| 882 | f"job id {job_id} doesn't exist in build " + build_info["web_url"] |
| 883 | ) |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 884 | url = build_info["web_url"] |
| 885 | if logger: |
| 886 | logger.log(f"Waiting for {url}, waited {t} seconds...") |
| 887 | time.sleep(interval_time) |
| 888 | t += interval_time |
| 889 | build_info = self.get_build_info(build_number) |
| 890 | |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 891 | def wait_build_to_finish(self, build_number, interval_time=30, logger=None): |
| 892 | """Wait a build to finish and return the build metadata |
| 893 | |
| 894 | Parameters |
| 895 | ---------- |
| 896 | build_number : the number of the build we want to wait |
| 897 | interval_time : (optional) the interval time to check the build status, default to 30s |
| 898 | logger : (optional) a logger to report progress |
| 899 | |
| 900 | Returns |
| 901 | ------- |
| 902 | dict |
| 903 | the latest metadata for the build |
| 904 | """ |
| 905 | t = 0 |
| 906 | build_info = self.get_build_info(build_number) |
| 907 | while build_info["state"] == "scheduled" or build_info["state"] == "running": |
| 908 | url = build_info["web_url"] |
| 909 | if logger: |
| 910 | logger.log(f"Waiting for {url}, waited {t} seconds...") |
| 911 | time.sleep(interval_time) |
| 912 | t += interval_time |
| 913 | build_info = self.get_build_info(build_number) |
| 914 | return build_info |
| 915 | |
| 916 | |
Chi Wang | 5e3998f | 2023-05-10 11:51:02 +0000 | [diff] [blame] | 917 | def decrypt_token(encrypted_token, kms_key, project="bazel-untrusted"): |
Florian Weikert | 849afb2 | 2019-12-14 12:22:29 -0800 | [diff] [blame] | 918 | return ( |
| 919 | subprocess.check_output( |
| 920 | [ |
| 921 | gcloud_command(), |
| 922 | "kms", |
| 923 | "decrypt", |
| 924 | "--project", |
Chi Wang | 5e3998f | 2023-05-10 11:51:02 +0000 | [diff] [blame] | 925 | project, |
Florian Weikert | 849afb2 | 2019-12-14 12:22:29 -0800 | [diff] [blame] | 926 | "--location", |
| 927 | "global", |
| 928 | "--keyring", |
| 929 | "buildkite", |
| 930 | "--key", |
| 931 | kms_key, |
| 932 | "--ciphertext-file", |
| 933 | "-", |
| 934 | "--plaintext-file", |
| 935 | "-", |
| 936 | ], |
| 937 | input=base64.b64decode(encrypted_token), |
| 938 | env=os.environ, |
| 939 | ) |
| 940 | .decode("utf-8") |
| 941 | .strip() |
| 942 | ) |
| 943 | |
| 944 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 945 | def eprint(*args, **kwargs): |
| 946 | """ |
| 947 | Print to stderr and flush (just in case). |
| 948 | """ |
| 949 | print(*args, flush=True, file=sys.stderr, **kwargs) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 950 | |
| 951 | |
Jakob Buchgraber | 9f15354 | 2018-02-27 10:56:04 +0100 | [diff] [blame] | 952 | def is_windows(): |
Jakob Buchgraber | 09048fa | 2018-02-27 11:39:39 +0100 | [diff] [blame] | 953 | return os.name == "nt" |
Jakob Buchgraber | 9f15354 | 2018-02-27 10:56:04 +0100 | [diff] [blame] | 954 | |
Jakob Buchgraber | e6de16b | 2018-02-28 12:42:12 +0100 | [diff] [blame] | 955 | |
Florian Weikert | a6110a9 | 2022-10-20 01:16:09 +0200 | [diff] [blame] | 956 | def is_mac(): |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 957 | return platform_module.system() == "Darwin" |
Florian Weikert | a6110a9 | 2022-10-20 01:16:09 +0200 | [diff] [blame] | 958 | |
| 959 | |
Jakob Buchgraber | 9f15354 | 2018-02-27 10:56:04 +0100 | [diff] [blame] | 960 | def gsutil_command(): |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 961 | return "gsutil.cmd" if is_windows() else "gsutil" |
Jakob Buchgraber | 9f15354 | 2018-02-27 10:56:04 +0100 | [diff] [blame] | 962 | |
Jakob Buchgraber | e6de16b | 2018-02-28 12:42:12 +0100 | [diff] [blame] | 963 | |
Jakob Buchgraber | 9f15354 | 2018-02-27 10:56:04 +0100 | [diff] [blame] | 964 | def gcloud_command(): |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 965 | return "gcloud.cmd" if is_windows() else "gcloud" |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 966 | |
Jakob Buchgraber | e6de16b | 2018-02-28 12:42:12 +0100 | [diff] [blame] | 967 | |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 968 | def downstream_projects_root(platform): |
Philipp Wollermann | 51147bf | 2019-05-08 15:50:10 +0200 | [diff] [blame] | 969 | downstream_root = os.path.expandvars(PLATFORMS[platform]["downstream-root"]) |
Philipp Wollermann | d5ab3d9 | 2020-02-05 16:55:13 +0100 | [diff] [blame] | 970 | if platform == "windows" and os.path.exists("d:/b"): |
| 971 | # If this is a Windows machine with a local SSD, the build directory is |
| 972 | # on drive D. |
| 973 | downstream_root = downstream_root.replace("c:/b/", "d:/b/") |
Philipp Wollermann | 51147bf | 2019-05-08 15:50:10 +0200 | [diff] [blame] | 974 | if not os.path.exists(downstream_root): |
| 975 | os.makedirs(downstream_root) |
| 976 | return downstream_root |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 977 | |
| 978 | |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 979 | def match_matrix_attr_pattern(s): |
| 980 | return re.match("^\${{\s*(\w+)\s*}}$", s) |
| 981 | |
| 982 | |
| 983 | def get_matrix_attributes(task): |
| 984 | """Get unexpanded matrix attributes from the given task. |
| 985 | |
| 986 | If a value of field matches "${{<name>}}", then <name> is a wanted matrix attribute. |
| 987 | eg. platform: ${{ platform }} |
| 988 | """ |
| 989 | attributes = [] |
| 990 | for key, value in task.items(): |
| 991 | if type(value) is str: |
| 992 | res = match_matrix_attr_pattern(value) |
| 993 | if res: |
| 994 | attributes.append(res.groups()[0]) |
| 995 | return list(set(attributes)) |
| 996 | |
| 997 | |
| 998 | def get_combinations(matrix, attributes): |
| 999 | """Given a matrix and the wanted attributes, return all possible combinations. |
| 1000 | |
| 1001 | eg. |
| 1002 | With matrix = {'a': [1, 2], 'b': [1], 'c': [1]}, |
| 1003 | if attributes = ['a', 'b'], then returns [[('a', 1), ('b', 1)], [('a', 2), ('b', 1)]] |
| 1004 | if attributes = ['b', 'c'], then returns [[('b', 1), ('c', 1)]] |
| 1005 | if attributes = ['c'], then returns [[('c', 1)]] |
| 1006 | """ |
Yun Peng | 2b59cde | 2023-05-08 15:44:38 +0200 | [diff] [blame] | 1007 | # Sort the attributes to make the output deterministic. |
| 1008 | attributes.sort() |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 1009 | for attr in attributes: |
| 1010 | if attr not in matrix: |
| 1011 | raise BuildkiteException("${{ %s }} is not defined in `matrix` section." % attr) |
| 1012 | pairs = [[(attr, value) for value in matrix[attr]] for attr in attributes] |
Yun Peng | 237309f | 2023-04-25 15:30:43 +0200 | [diff] [blame] | 1013 | return sorted(itertools.product(*pairs)) |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 1014 | |
| 1015 | |
| 1016 | def get_expanded_task(task, combination): |
| 1017 | """Expand a task with the given combination of values of attributes.""" |
| 1018 | combination = dict(combination) |
| 1019 | expanded_task = copy.deepcopy(task) |
| 1020 | for key, value in task.items(): |
| 1021 | if type(value) is str: |
| 1022 | res = match_matrix_attr_pattern(value) |
| 1023 | if res: |
| 1024 | attr = res.groups()[0] |
| 1025 | expanded_task[key] = combination[attr] |
| 1026 | return expanded_task |
| 1027 | |
| 1028 | |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 1029 | def fetch_configs(http_url, file_config): |
Philipp Wollermann | db02486 | 2018-02-19 17:16:56 +0100 | [diff] [blame] | 1030 | """ |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 1031 | If specified fetches the build configuration from file_config or http_url, else tries to |
Jakob Buchgraber | 25bb50f | 2018-02-22 18:06:21 +0100 | [diff] [blame] | 1032 | read it from .bazelci/presubmit.yml. |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1033 | Returns the json configuration as a python data structure. |
Philipp Wollermann | db02486 | 2018-02-19 17:16:56 +0100 | [diff] [blame] | 1034 | """ |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 1035 | if file_config is not None and http_url is not None: |
| 1036 | raise BuildkiteException("file_config and http_url cannot be set at the same time") |
| 1037 | |
Florian Weikert | c8b3ed2 | 2019-05-31 16:14:12 +0200 | [diff] [blame] | 1038 | return load_config(http_url, file_config) |
| 1039 | |
| 1040 | |
Yun Peng | fde4858 | 2022-01-11 14:37:47 +0100 | [diff] [blame] | 1041 | def expand_task_config(config): |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 1042 | # Expand tasks that uses attributes defined in the matrix section. |
| 1043 | # The original task definition expands to multiple tasks for each possible combination. |
| 1044 | tasks_to_expand = [] |
| 1045 | expanded_tasks = {} |
| 1046 | matrix = config.pop("matrix", {}) |
| 1047 | for key, value in matrix.items(): |
| 1048 | if type(key) is not str or type(value) is not list: |
| 1049 | raise BuildkiteException("Expect `matrix` is a map of str -> list") |
| 1050 | |
| 1051 | for task in config["tasks"]: |
| 1052 | attributes = get_matrix_attributes(config["tasks"][task]) |
| 1053 | if attributes: |
| 1054 | tasks_to_expand.append(task) |
| 1055 | count = 1 |
| 1056 | for combination in get_combinations(matrix, attributes): |
| 1057 | expanded_task_name = "%s_config_%.2d" % (task, count) |
| 1058 | count += 1 |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 1059 | expanded_tasks[expanded_task_name] = get_expanded_task( |
| 1060 | config["tasks"][task], combination |
| 1061 | ) |
Yun Peng | 5a1a944 | 2022-01-11 14:26:48 +0100 | [diff] [blame] | 1062 | |
| 1063 | for task in tasks_to_expand: |
| 1064 | config["tasks"].pop(task) |
| 1065 | config["tasks"].update(expanded_tasks) |
| 1066 | |
Yun Peng | fde4858 | 2022-01-11 14:37:47 +0100 | [diff] [blame] | 1067 | |
| 1068 | def load_config(http_url, file_config, allow_imports=True): |
| 1069 | if http_url: |
| 1070 | config = load_remote_yaml_file(http_url) |
| 1071 | else: |
| 1072 | file_config = file_config or ".bazelci/presubmit.yml" |
| 1073 | with open(file_config, "r") as fd: |
| 1074 | config = yaml.safe_load(fd) |
| 1075 | |
| 1076 | # Legacy mode means that there is exactly one task per platform (e.g. ubuntu1604_nojdk), |
| 1077 | # which means that we can get away with using the platform name as task ID. |
| 1078 | # No other updates are needed since get_platform_for_task() falls back to using the |
| 1079 | # task ID as platform if there is no explicit "platforms" field. |
| 1080 | if "platforms" in config: |
| 1081 | config["tasks"] = config.pop("platforms") |
| 1082 | |
| 1083 | if "tasks" not in config: |
| 1084 | config["tasks"] = {} |
| 1085 | |
| 1086 | expand_task_config(config) |
| 1087 | |
Florian Weikert | c8b3ed2 | 2019-05-31 16:14:12 +0200 | [diff] [blame] | 1088 | imports = config.pop("imports", None) |
| 1089 | if imports: |
| 1090 | if not allow_imports: |
| 1091 | raise BuildkiteException("Nested imports are not allowed") |
| 1092 | |
| 1093 | for i in imports: |
| 1094 | imported_tasks = load_imported_tasks(i, http_url, file_config) |
| 1095 | config["tasks"].update(imported_tasks) |
| 1096 | |
Yun Peng | 686f459 | 2022-01-17 15:38:48 +0100 | [diff] [blame] | 1097 | if len(config["tasks"]) > MAX_TASK_NUMBER: |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 1098 | raise BuildkiteException( |
| 1099 | "The number of tasks in one config file is limited to %s!" % MAX_TASK_NUMBER |
| 1100 | ) |
Yun Peng | 686f459 | 2022-01-17 15:38:48 +0100 | [diff] [blame] | 1101 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 1102 | return config |
| 1103 | |
| 1104 | |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 1105 | def load_remote_yaml_file(http_url): |
| 1106 | with urllib.request.urlopen(http_url) as resp: |
| 1107 | reader = codecs.getreader("utf-8") |
Philipp Wollermann | d00107e | 2019-05-18 23:50:59 +0200 | [diff] [blame] | 1108 | return yaml.safe_load(reader(resp)) |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 1109 | |
| 1110 | |
Florian Weikert | c8b3ed2 | 2019-05-31 16:14:12 +0200 | [diff] [blame] | 1111 | def load_imported_tasks(import_name, http_url, file_config): |
| 1112 | if "/" in import_name: |
| 1113 | raise BuildkiteException("Invalid import '%s'" % import_name) |
| 1114 | |
| 1115 | old_path = http_url or file_config |
| 1116 | new_path = "%s%s" % (old_path[: old_path.rfind("/") + 1], import_name) |
| 1117 | if http_url: |
| 1118 | http_url = new_path |
| 1119 | else: |
| 1120 | file_config = new_path |
| 1121 | |
| 1122 | imported_config = load_config(http_url=http_url, file_config=file_config, allow_imports=False) |
| 1123 | |
| 1124 | namespace = import_name.partition(".")[0] |
| 1125 | tasks = {} |
| 1126 | for task_name, task_config in imported_config["tasks"].items(): |
Florian Weikert | 61f29b8 | 2019-08-12 16:56:56 +0200 | [diff] [blame] | 1127 | fix_imported_task_platform(task_name, task_config) |
| 1128 | fix_imported_task_name(namespace, task_config) |
| 1129 | fix_imported_task_working_directory(namespace, task_config) |
Florian Weikert | c8b3ed2 | 2019-05-31 16:14:12 +0200 | [diff] [blame] | 1130 | tasks["%s_%s" % (namespace, task_name)] = task_config |
| 1131 | |
| 1132 | return tasks |
| 1133 | |
| 1134 | |
Florian Weikert | 61f29b8 | 2019-08-12 16:56:56 +0200 | [diff] [blame] | 1135 | def fix_imported_task_platform(task_name, task_config): |
| 1136 | if "platform" not in task_config: |
| 1137 | task_config["platform"] = task_name |
| 1138 | |
| 1139 | |
| 1140 | def fix_imported_task_name(namespace, task_config): |
| 1141 | old_name = task_config.get("name") |
| 1142 | task_config["name"] = "%s (%s)" % (namespace, old_name) if old_name else namespace |
| 1143 | |
| 1144 | |
| 1145 | def fix_imported_task_working_directory(namespace, task_config): |
| 1146 | old_dir = task_config.get("working_directory") |
| 1147 | task_config["working_directory"] = os.path.join(namespace, old_dir) if old_dir else namespace |
| 1148 | |
| 1149 | |
Jakob Buchgraber | 3120f7a | 2018-02-18 13:28:02 +0100 | [diff] [blame] | 1150 | def print_collapsed_group(name): |
Jakob Buchgraber | 5c9b13d | 2018-02-21 22:28:14 +0100 | [diff] [blame] | 1151 | eprint("\n\n--- {0}\n\n".format(name)) |
Jakob Buchgraber | 3120f7a | 2018-02-18 13:28:02 +0100 | [diff] [blame] | 1152 | |
Jakob Buchgraber | 9c83de7 | 2018-02-18 15:32:44 +0100 | [diff] [blame] | 1153 | |
Jakob Buchgraber | 3120f7a | 2018-02-18 13:28:02 +0100 | [diff] [blame] | 1154 | def print_expanded_group(name): |
Jakob Buchgraber | 5c9b13d | 2018-02-21 22:28:14 +0100 | [diff] [blame] | 1155 | eprint("\n\n+++ {0}\n\n".format(name)) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1156 | |
Yun Peng | 9b1d343 | 2021-12-07 10:40:45 +0100 | [diff] [blame] | 1157 | |
Philipp Wollermann | c8b86ac | 2021-10-25 17:52:07 +0200 | [diff] [blame] | 1158 | def is_trueish(s): |
| 1159 | return str(s).lower() in ["true", "1", "t", "y", "yes"] |
| 1160 | |
Jakob Buchgraber | 9c83de7 | 2018-02-18 15:32:44 +0100 | [diff] [blame] | 1161 | |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 1162 | def use_bazelisk_migrate(): |
| 1163 | """ |
| 1164 | If USE_BAZELISK_MIGRATE is set, we use `bazelisk --migrate` to test incompatible flags. |
| 1165 | """ |
Philipp Wollermann | c8b86ac | 2021-10-25 17:52:07 +0200 | [diff] [blame] | 1166 | return is_trueish(os.environ.get("USE_BAZELISK_MIGRATE")) |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 1167 | |
| 1168 | |
| 1169 | def bazelisk_flags(): |
| 1170 | return ["--migrate"] if use_bazelisk_migrate() else [] |
| 1171 | |
| 1172 | |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1173 | def calculate_flags(task_config, task_config_key, action_key, tmpdir, test_env_vars): |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1174 | include_json_profile = task_config.get("include_json_profile", []) |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1175 | capture_corrupted_outputs = task_config.get("capture_corrupted_outputs", []) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1176 | |
| 1177 | json_profile_flags = [] |
| 1178 | json_profile_out = None |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1179 | if action_key in include_json_profile: |
| 1180 | json_profile_out = os.path.join(tmpdir, "{}.profile.gz".format(action_key)) |
Tobias Werth | c22e4c4 | 2021-10-08 12:03:14 +0200 | [diff] [blame] | 1181 | json_profile_flags = ["--profile={}".format(json_profile_out)] |
| 1182 | |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1183 | capture_corrupted_outputs_flags = [] |
| 1184 | capture_corrupted_outputs_dir = None |
| 1185 | if action_key in capture_corrupted_outputs: |
Philipp Wollermann | f436e74 | 2021-08-11 11:06:55 +0200 | [diff] [blame] | 1186 | capture_corrupted_outputs_dir = os.path.join( |
| 1187 | tmpdir, "{}_corrupted_outputs".format(action_key) |
| 1188 | ) |
| 1189 | capture_corrupted_outputs_flags = [ |
| 1190 | "--experimental_remote_capture_corrupted_outputs={}".format( |
| 1191 | capture_corrupted_outputs_dir |
| 1192 | ) |
| 1193 | ] |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1194 | |
| 1195 | flags = task_config.get(task_config_key) or [] |
| 1196 | flags += json_profile_flags |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1197 | flags += capture_corrupted_outputs_flags |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1198 | # We have to add --test_env flags to `build`, too, otherwise Bazel |
| 1199 | # discards its analysis cache between `build` and `test`. |
| 1200 | if test_env_vars: |
| 1201 | flags += ["--test_env={}".format(v) for v in test_env_vars] |
| 1202 | |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1203 | return flags, json_profile_out, capture_corrupted_outputs_dir |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1204 | |
| 1205 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1206 | def execute_commands( |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 1207 | task_config, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1208 | platform, |
| 1209 | git_repository, |
| 1210 | git_commit, |
Yun Peng | 5012a86 | 2021-09-16 16:35:43 +0200 | [diff] [blame] | 1211 | repo_location, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1212 | use_bazel_at_commit, |
| 1213 | use_but, |
| 1214 | save_but, |
Yun Peng | 4d1d654 | 2019-01-17 18:30:33 +0100 | [diff] [blame] | 1215 | needs_clean, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1216 | build_only, |
| 1217 | test_only, |
| 1218 | monitor_flaky_tests, |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 1219 | bazel_version=None, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1220 | ): |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 1221 | if use_bazelisk_migrate(): |
| 1222 | # If we are testing incompatible flags with Bazelisk, |
| 1223 | # use Bazel@last_green if USE_BAZEL_VERSION env var is not set explicitly. |
| 1224 | if "USE_BAZEL_VERSION" not in os.environ: |
| 1225 | bazel_version = "last_green" |
| 1226 | |
| 1227 | # Override use_but in case we are in the downstream pipeline so that it doesn't try to |
| 1228 | # download Bazel built from previous jobs. |
| 1229 | use_but = False |
| 1230 | |
| 1231 | # Set BAZELISK_INCOMPATIBLE_FLAGS to tell Bazelisk which flags to test. |
| 1232 | os.environ["BAZELISK_INCOMPATIBLE_FLAGS"] = ",".join(fetch_incompatible_flags().keys()) |
| 1233 | |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 1234 | if not bazel_version: |
| 1235 | # The last good version of Bazel can be specified in an emergency file. |
| 1236 | # However, we only use last_good_bazel for pipelines that do not |
| 1237 | # explicitly specify a version of Bazel. |
| 1238 | try: |
| 1239 | emergency_settings = load_remote_yaml_file(EMERGENCY_FILE_URL) |
| 1240 | bazel_version = emergency_settings.get("last_good_bazel") |
| 1241 | except urllib.error.HTTPError: |
| 1242 | # Ignore this error. The Setup step will have already complained about |
| 1243 | # it by showing an error message. |
| 1244 | pass |
Yun Peng | f50f7b7 | 2019-02-28 19:09:52 +0100 | [diff] [blame] | 1245 | |
Jakob Buchgraber | fb95a2f | 2018-02-22 11:46:25 +0100 | [diff] [blame] | 1246 | if build_only and test_only: |
| 1247 | raise BuildkiteException("build_only and test_only cannot be true at the same time") |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 1248 | |
Florian Weikert | d7cb83d | 2023-02-24 19:51:52 +0100 | [diff] [blame] | 1249 | if use_but: |
| 1250 | if use_bazel_at_commit: |
| 1251 | raise BuildkiteException("use_bazel_at_commit cannot be set when use_but is true") |
| 1252 | |
| 1253 | print_collapsed_group(":printer: Printing task config for downstream job...") |
Florian Weikert | 7d89478 | 2023-02-24 20:28:14 +0100 | [diff] [blame] | 1254 | eprint(json.dumps(task_config, indent=2)) |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 1255 | |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 1256 | tmpdir = tempfile.mkdtemp() |
| 1257 | sc_process = None |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1258 | try: |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1259 | if is_mac(): |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1260 | activate_xcode(task_config) |
Philipp Wollermann | 380f1e6 | 2019-04-12 16:45:27 +0200 | [diff] [blame] | 1261 | |
Florian Weikert | 4ee0bed | 2019-02-21 18:03:00 +0100 | [diff] [blame] | 1262 | # If the CI worker runs Bazelisk, we need to forward all required env variables to the test. |
| 1263 | # Otherwise any integration test that invokes Bazel (=Bazelisk in this case) will fail. |
Marcel Hlopko | 198328b | 2019-02-25 09:19:55 +0100 | [diff] [blame] | 1264 | test_env_vars = ["LocalAppData"] if platform == "windows" else ["HOME"] |
Florian Weikert | c12580c | 2021-07-13 17:09:25 +0200 | [diff] [blame] | 1265 | |
| 1266 | # CI should have its own user agent so that we can remove it from Bazel download statistics. |
| 1267 | os.environ["BAZELISK_USER_AGENT"] = "Bazelisk/BazelCI" |
| 1268 | test_env_vars.append("BAZELISK_USER_AGENT") |
| 1269 | |
Yun Peng | 5012a86 | 2021-09-16 16:35:43 +0200 | [diff] [blame] | 1270 | if repo_location: |
| 1271 | os.chdir(repo_location) |
Yun Peng | 376d2b3 | 2018-11-29 10:24:54 +0100 | [diff] [blame] | 1272 | elif git_repository: |
| 1273 | clone_git_repository(git_repository, platform, git_commit) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1274 | |
Philipp Wollermann | f4aabb7 | 2019-06-25 15:59:00 +0200 | [diff] [blame] | 1275 | # We use one binary for all Linux platforms (because we also just release one binary for all |
| 1276 | # Linux versions and we have to ensure that it works on all of them). |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1277 | binary_platform = platform if is_mac() or is_windows() else LINUX_BINARY_PLATFORM |
Philipp Wollermann | f4aabb7 | 2019-06-25 15:59:00 +0200 | [diff] [blame] | 1278 | |
Yun Peng | eec2cd9 | 2022-07-14 14:44:30 +0200 | [diff] [blame] | 1279 | bazel_binary = "bazel" |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 1280 | if use_bazel_at_commit: |
| 1281 | print_collapsed_group(":gcloud: Downloading Bazel built at " + use_bazel_at_commit) |
Yun Peng | dae5a7d | 2022-01-11 16:08:58 +0100 | [diff] [blame] | 1282 | # Linux binaries are published under platform name "centos7" |
| 1283 | if binary_platform == LINUX_BINARY_PLATFORM: |
| 1284 | binary_platform = "centos7" |
Yun Peng | eec2cd9 | 2022-07-14 14:44:30 +0200 | [diff] [blame] | 1285 | os.environ["USE_BAZEL_VERSION"] = download_bazel_binary_at_commit( |
Philipp Wollermann | f4aabb7 | 2019-06-25 15:59:00 +0200 | [diff] [blame] | 1286 | tmpdir, binary_platform, use_bazel_at_commit |
| 1287 | ) |
Yun Peng | eec2cd9 | 2022-07-14 14:44:30 +0200 | [diff] [blame] | 1288 | print_collapsed_group(":bazel: Using Bazel at " + os.environ["USE_BAZEL_VERSION"]) |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1289 | elif use_but: |
Jakob Buchgraber | 92755d7 | 2018-02-22 15:33:37 +0100 | [diff] [blame] | 1290 | print_collapsed_group(":gcloud: Downloading Bazel Under Test") |
Yun Peng | eec2cd9 | 2022-07-14 14:44:30 +0200 | [diff] [blame] | 1291 | os.environ["USE_BAZEL_VERSION"] = download_bazel_binary(tmpdir, binary_platform) |
| 1292 | print_collapsed_group(":bazel: Using Bazel at " + os.environ["USE_BAZEL_VERSION"]) |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1293 | else: |
Yun Peng | eec2cd9 | 2022-07-14 14:44:30 +0200 | [diff] [blame] | 1294 | print_collapsed_group(":bazel: Using Bazel version " + bazel_version) |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 1295 | if bazel_version: |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 1296 | os.environ["USE_BAZEL_VERSION"] = bazel_version |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 1297 | if "USE_BAZEL_VERSION" in os.environ and not task_config.get( |
| 1298 | "skip_use_bazel_version_for_test", False |
| 1299 | ): |
Yun Peng | f0a66e2 | 2019-10-14 12:45:42 +0200 | [diff] [blame] | 1300 | # This will only work if the bazel binary in $PATH is actually a bazelisk binary |
| 1301 | # (https://github.com/bazelbuild/bazelisk). |
| 1302 | test_env_vars.append("USE_BAZEL_VERSION") |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1303 | |
Philipp Wollermann | 5c7ea41 | 2019-05-24 15:26:57 +0200 | [diff] [blame] | 1304 | for key, value in task_config.get("environment", {}).items(): |
Philipp Wollermann | 4ad4aac | 2019-05-24 15:23:09 +0200 | [diff] [blame] | 1305 | # We have to explicitly convert the value to a string, because sometimes YAML tries to |
| 1306 | # be smart and converts strings like "true" and "false" to booleans. |
Philipp Wollermann | 7df2d0d | 2021-08-11 13:26:04 +0200 | [diff] [blame] | 1307 | os.environ[key] = os.path.expandvars(str(value)) |
Philipp Wollermann | 213ac9d | 2019-02-06 11:50:05 +0100 | [diff] [blame] | 1308 | |
Yun Peng | 366f04c | 2020-08-10 16:55:58 +0200 | [diff] [blame] | 1309 | # Set BAZELISK_SHUTDOWN to 1 when we use bazelisk --migrate on Windows. |
| 1310 | # This is a workaround for https://github.com/bazelbuild/continuous-integration/issues/1012 |
| 1311 | if use_bazelisk_migrate() and platform == "windows": |
| 1312 | os.environ["BAZELISK_SHUTDOWN"] = "1" |
| 1313 | |
Florian Weikert | 9b805ce | 2023-05-10 18:04:03 +0200 | [diff] [blame] | 1314 | def PrepareRepoInCwd(print_cmd_groups, initial_setup=False): |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 1315 | # Allow the config to override the current working directory. |
| 1316 | requested_working_dir = task_config.get("working_directory") |
| 1317 | if requested_working_dir: |
| 1318 | if os.path.isabs(requested_working_dir): |
| 1319 | raise BuildkiteException( |
| 1320 | f"working_directory must be relative to the repository root, " |
| 1321 | "but was {requested_working_dir}" |
| 1322 | ) |
| 1323 | |
| 1324 | full_requested_working_dir = os.path.abspath(requested_working_dir) |
| 1325 | if not os.path.isdir(full_requested_working_dir): |
| 1326 | raise BuildkiteException( |
| 1327 | f"{full_requested_working_dir} does not exist or is not a directory" |
| 1328 | ) |
| 1329 | |
| 1330 | os.chdir(full_requested_working_dir) |
| 1331 | |
Florian Weikert | 9b805ce | 2023-05-10 18:04:03 +0200 | [diff] [blame] | 1332 | # Dirty workaround for #1660 |
| 1333 | if initial_setup: |
| 1334 | # Set OUTPUT_BASE environment variable |
| 1335 | os.environ["OUTPUT_BASE"] = get_output_base(bazel_binary) |
| 1336 | |
| 1337 | cmd_exec_func = ( |
| 1338 | execute_batch_commands if platform == "windows" else execute_shell_commands |
| 1339 | ) |
| 1340 | cmd_exec_func(task_config.get("setup", None)) |
Yun Peng | 28a9a53 | 2023-05-10 14:19:46 +0200 | [diff] [blame] | 1341 | |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 1342 | if platform == "windows": |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 1343 | execute_batch_commands(task_config.get("batch_commands", None), print_cmd_groups) |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 1344 | else: |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 1345 | execute_shell_commands(task_config.get("shell_commands", None), print_cmd_groups) |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 1346 | |
Florian Weikert | 9b805ce | 2023-05-10 18:04:03 +0200 | [diff] [blame] | 1347 | PrepareRepoInCwd(True, initial_setup=True) |
Florian Weikert | e72d68a | 2019-03-08 18:56:33 +0100 | [diff] [blame] | 1348 | |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 1349 | bazel_version = print_bazel_version_info(bazel_binary, platform) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1350 | |
Yun Peng | a5a1ee0 | 2018-12-05 15:00:58 +0100 | [diff] [blame] | 1351 | print_environment_variables_info() |
| 1352 | |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 1353 | execute_bazel_run(bazel_binary, platform, task_config.get("run_targets", None)) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1354 | |
Yun Peng | 4d1d654 | 2019-01-17 18:30:33 +0100 | [diff] [blame] | 1355 | if needs_clean: |
Yun Peng | ea0359e | 2019-01-17 15:37:47 +0100 | [diff] [blame] | 1356 | execute_bazel_clean(bazel_binary, platform) |
| 1357 | |
Florian Weikert | 25e92c4 | 2023-04-28 10:56:46 +0200 | [diff] [blame] | 1358 | # The git_commit paramter only has a value in the downstream pipeline, |
| 1359 | # but we need the commit here in order to calculate the correct targets. |
| 1360 | git_commit = git_commit or os.getenv("BUILDKITE_COMMIT") |
| 1361 | if not git_commit: |
| 1362 | raise BuildkiteInfraException("Unable to determine Git commit for this build") |
| 1363 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 1364 | test_flags, json_profile_out_test, capture_corrupted_outputs_dir_test = calculate_flags( |
| 1365 | task_config, "test_flags", "test", tmpdir, test_env_vars |
| 1366 | ) |
| 1367 | |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 1368 | build_targets, test_targets, coverage_targets, index_targets = calculate_targets( |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 1369 | task_config, |
| 1370 | bazel_binary, |
| 1371 | build_only, |
| 1372 | test_only, |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 1373 | os.getcwd(), |
| 1374 | PrepareRepoInCwd, |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 1375 | git_commit, |
| 1376 | test_flags, |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 1377 | ) |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 1378 | |
| 1379 | if build_targets: |
Philipp Wollermann | f436e74 | 2021-08-11 11:06:55 +0200 | [diff] [blame] | 1380 | ( |
| 1381 | build_flags, |
| 1382 | json_profile_out_build, |
| 1383 | capture_corrupted_outputs_dir_build, |
| 1384 | ) = calculate_flags(task_config, "build_flags", "build", tmpdir, test_env_vars) |
joeleba | 7688795 | 2019-05-16 15:22:17 +0200 | [diff] [blame] | 1385 | try: |
Yun Peng | c8bb9e9 | 2021-07-28 11:56:53 +0200 | [diff] [blame] | 1386 | release_name = get_release_name_from_branch_name() |
joeleba | 7688795 | 2019-05-16 15:22:17 +0200 | [diff] [blame] | 1387 | execute_bazel_build( |
| 1388 | bazel_version, |
| 1389 | bazel_binary, |
| 1390 | platform, |
Philipp Wollermann | f436e74 | 2021-08-11 11:06:55 +0200 | [diff] [blame] | 1391 | build_flags |
| 1392 | + ( |
| 1393 | ["--stamp", "--embed_label=%s" % release_name] |
| 1394 | if save_but and release_name |
| 1395 | else [] |
| 1396 | ), |
joeleba | 7688795 | 2019-05-16 15:22:17 +0200 | [diff] [blame] | 1397 | build_targets, |
| 1398 | None, |
joeleba | 7688795 | 2019-05-16 15:22:17 +0200 | [diff] [blame] | 1399 | ) |
| 1400 | if save_but: |
| 1401 | upload_bazel_binary(platform) |
| 1402 | finally: |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1403 | if json_profile_out_build: |
Philipp Wollermann | 92cf51e | 2019-05-16 15:31:11 +0200 | [diff] [blame] | 1404 | upload_json_profile(json_profile_out_build, tmpdir) |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1405 | if capture_corrupted_outputs_dir_build: |
| 1406 | upload_corrupted_outputs(capture_corrupted_outputs_dir_build, tmpdir) |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1407 | |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 1408 | if test_targets: |
Florian Weikert | 4901c66 | 2019-02-26 13:20:11 +0100 | [diff] [blame] | 1409 | if not is_windows(): |
| 1410 | # On platforms that support sandboxing (Linux, MacOS) we have |
| 1411 | # to allow access to Bazelisk's cache directory. |
| 1412 | # However, the flag requires the directory to exist, |
| 1413 | # so we create it here in order to not crash when a test |
| 1414 | # does not invoke Bazelisk. |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1415 | bazelisk_cache_dir = get_bazelisk_cache_directory() |
Florian Weikert | 4901c66 | 2019-02-26 13:20:11 +0100 | [diff] [blame] | 1416 | os.makedirs(bazelisk_cache_dir, mode=0o755, exist_ok=True) |
| 1417 | test_flags.append("--sandbox_writable_path={}".format(bazelisk_cache_dir)) |
Florian Weikert | 5b89033 | 2019-02-25 14:57:43 +0100 | [diff] [blame] | 1418 | |
Chi Wang | 5e3998f | 2023-05-10 11:51:02 +0000 | [diff] [blame] | 1419 | # Set BUILDKITE_ANALYTICS_TOKEN so that bazelci-agent can upload test results to Test Analytics |
| 1420 | if "ENCRYPTED_BUILDKITE_ANALYTICS_TOKEN" in os.environ: |
| 1421 | if THIS_IS_TESTING: |
| 1422 | kms_key = "buildkite-testing-api-token" |
| 1423 | project = "bazel-untrusted" |
| 1424 | elif THIS_IS_TRUSTED: |
| 1425 | kms_key = "buildkite-trusted-api-token" |
| 1426 | project = "bazel-public" |
| 1427 | else: |
| 1428 | kms_key = "buildkite-untrusted-api-token" |
| 1429 | project = "bazel-untrusted" |
| 1430 | os.environ["BUILDKITE_ANALYTICS_TOKEN"] = decrypt_token( |
| 1431 | encrypted_token=os.environ["ENCRYPTED_BUILDKITE_ANALYTICS_TOKEN"], |
| 1432 | kms_key=kms_key, |
| 1433 | project=project, |
| 1434 | ) |
| 1435 | |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 1436 | test_bep_file = os.path.join(tmpdir, "test_bep.json") |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 1437 | upload_thread = threading.Thread( |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 1438 | target=upload_test_logs_from_bep, |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1439 | args=(test_bep_file, tmpdir, monitor_flaky_tests), |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 1440 | ) |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 1441 | try: |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 1442 | upload_thread.start() |
| 1443 | try: |
| 1444 | execute_bazel_test( |
| 1445 | bazel_version, |
| 1446 | bazel_binary, |
| 1447 | platform, |
| 1448 | test_flags, |
| 1449 | test_targets, |
| 1450 | test_bep_file, |
| 1451 | monitor_flaky_tests, |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 1452 | ) |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 1453 | finally: |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1454 | if json_profile_out_test: |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 1455 | upload_json_profile(json_profile_out_test, tmpdir) |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1456 | if capture_corrupted_outputs_dir_test: |
| 1457 | upload_corrupted_outputs(capture_corrupted_outputs_dir_test, tmpdir) |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1458 | finally: |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 1459 | upload_thread.join() |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1460 | |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 1461 | if coverage_targets: |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 1462 | ( |
| 1463 | coverage_flags, |
| 1464 | json_profile_out_coverage, |
| 1465 | capture_corrupted_outputs_dir_coverage, |
| 1466 | ) = calculate_flags(task_config, "coverage_flags", "coverage", tmpdir, test_env_vars) |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 1467 | try: |
| 1468 | execute_bazel_coverage( |
| 1469 | bazel_version, |
| 1470 | bazel_binary, |
| 1471 | platform, |
| 1472 | coverage_flags, |
| 1473 | coverage_targets, |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 1474 | ) |
| 1475 | finally: |
| 1476 | if json_profile_out_coverage: |
| 1477 | upload_json_profile(json_profile_out_coverage, tmpdir) |
| 1478 | if capture_corrupted_outputs_dir_coverage: |
| 1479 | upload_corrupted_outputs(capture_corrupted_outputs_dir_coverage, tmpdir) |
| 1480 | |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1481 | if index_targets: |
Philipp Wollermann | f436e74 | 2021-08-11 11:06:55 +0200 | [diff] [blame] | 1482 | ( |
| 1483 | index_flags, |
| 1484 | json_profile_out_index, |
| 1485 | capture_corrupted_outputs_dir_index, |
| 1486 | ) = calculate_flags(task_config, "index_flags", "index", tmpdir, test_env_vars) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1487 | index_upload_policy = task_config.get("index_upload_policy", "IfBuildSuccess") |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1488 | index_upload_gcs = task_config.get("index_upload_gcs", False) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1489 | |
| 1490 | try: |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 1491 | should_upload_kzip = ( |
| 1492 | True if index_upload_policy == INDEX_UPLOAD_POLICY_ALWAYS else False |
| 1493 | ) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1494 | try: |
| 1495 | execute_bazel_build_with_kythe( |
| 1496 | bazel_version, |
| 1497 | bazel_binary, |
| 1498 | platform, |
| 1499 | index_flags, |
| 1500 | index_targets, |
| 1501 | None, |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1502 | ) |
| 1503 | |
| 1504 | if index_upload_policy == INDEX_UPLOAD_POLICY_IF_BUILD_SUCCESS: |
| 1505 | should_upload_kzip = True |
| 1506 | except subprocess.CalledProcessError as e: |
| 1507 | # If not running with Always policy, raise the build error. |
| 1508 | if index_upload_policy != INDEX_UPLOAD_POLICY_ALWAYS: |
| 1509 | handle_bazel_failure(e, "build") |
| 1510 | |
Philipp Wollermann | a038b00 | 2021-05-05 22:04:38 +0200 | [diff] [blame] | 1511 | if should_upload_kzip and not is_pull_request(): |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1512 | try: |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1513 | merge_and_upload_kythe_kzip(platform, index_upload_gcs) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1514 | except subprocess.CalledProcessError: |
| 1515 | raise BuildkiteException("Failed to upload kythe kzip") |
| 1516 | finally: |
| 1517 | if json_profile_out_index: |
| 1518 | upload_json_profile(json_profile_out_index, tmpdir) |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 1519 | if capture_corrupted_outputs_dir_index: |
| 1520 | upload_corrupted_outputs(capture_corrupted_outputs_dir_index, tmpdir) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1521 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1522 | finally: |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 1523 | terminate_background_process(sc_process) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1524 | if tmpdir: |
| 1525 | shutil.rmtree(tmpdir) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 1526 | |
Philipp Wollermann | 3c8b851 | 2019-07-16 15:28:03 +0200 | [diff] [blame] | 1527 | |
Florian Weikert | f11f2bf | 2023-01-31 19:11:52 +0100 | [diff] [blame] | 1528 | def get_default_xcode_version(): |
Florian Weikert | 9e34259 | 2023-02-07 16:32:36 +0100 | [diff] [blame] | 1529 | # Cannot use platform.mac_ver() since it returns 10.16 on both 12.x and 13.x |
| 1530 | macos = execute_command_and_get_output(["sw_vers", "-productVersion"], print_output=False) |
Florian Weikert | f11f2bf | 2023-01-31 19:11:52 +0100 | [diff] [blame] | 1531 | major = int(macos.split(".")[0]) |
| 1532 | return DEFAULT_XCODE_VERSION_PER_OS.get(major, "13.0") # we use 13.0 due to legacy reasons |
| 1533 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 1534 | |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1535 | def activate_xcode(task_config): |
Florian Weikert | f11f2bf | 2023-01-31 19:11:52 +0100 | [diff] [blame] | 1536 | default_xcode_version = get_default_xcode_version() |
| 1537 | |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1538 | # Get the Xcode version from the config. |
Florian Weikert | f11f2bf | 2023-01-31 19:11:52 +0100 | [diff] [blame] | 1539 | wanted_xcode_version = task_config.get("xcode_version", default_xcode_version) |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1540 | print_collapsed_group(":xcode: Activating Xcode {}...".format(wanted_xcode_version)) |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1541 | |
| 1542 | # Ensure it's a valid version number. |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1543 | if not isinstance(wanted_xcode_version, str): |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1544 | raise BuildkiteException( |
| 1545 | "Version number '{}' is not a string. Did you forget to put it in quotes?".format( |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1546 | wanted_xcode_version |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1547 | ) |
| 1548 | ) |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1549 | if not XCODE_VERSION_REGEX.match(wanted_xcode_version): |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1550 | raise BuildkiteException( |
| 1551 | "Invalid Xcode version format '{}', must match the format X.Y[.Z].".format( |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1552 | wanted_xcode_version |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1553 | ) |
| 1554 | ) |
| 1555 | |
Philipp Wollermann | 06e5697 | 2020-01-29 14:46:41 +0100 | [diff] [blame] | 1556 | # This is used to replace e.g. 11.2 with 11.2.1 without having to update all configs. |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1557 | xcode_version = XCODE_VERSION_OVERRIDES.get(wanted_xcode_version, wanted_xcode_version) |
| 1558 | |
| 1559 | # This falls back to a default version if the selected version is not available. |
| 1560 | supported_versions = sorted( |
| 1561 | # Stripping "Xcode" prefix and ".app" suffix from e.g. "Xcode12.0.1.app" leaves just the version number. |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 1562 | [os.path.basename(x)[5:-4] for x in glob("/Applications/Xcode*.app")], |
| 1563 | reverse=True, |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1564 | ) |
| 1565 | if xcode_version not in supported_versions: |
Florian Weikert | f11f2bf | 2023-01-31 19:11:52 +0100 | [diff] [blame] | 1566 | xcode_version = default_xcode_version |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1567 | if xcode_version != wanted_xcode_version: |
| 1568 | print_collapsed_group( |
| 1569 | ":xcode: Fixed Xcode version: {} -> {}...".format(wanted_xcode_version, xcode_version) |
| 1570 | ) |
| 1571 | lines = [ |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 1572 | "Your selected Xcode version {} was not available on the machine.".format( |
| 1573 | wanted_xcode_version |
| 1574 | ), |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1575 | "Bazel CI automatically picked a fallback version: {}.".format(xcode_version), |
| 1576 | "Available versions are: {}.".format(supported_versions), |
| 1577 | ] |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 1578 | execute_command( |
| 1579 | [ |
| 1580 | "buildkite-agent", |
| 1581 | "annotate", |
| 1582 | "--style=warning", |
| 1583 | "\n".join(lines), |
| 1584 | "--context", |
| 1585 | "ctx-xcode_version_fixed", |
| 1586 | ] |
| 1587 | ) |
Philipp Wollermann | 06e5697 | 2020-01-29 14:46:41 +0100 | [diff] [blame] | 1588 | |
Florian Weikert | ee84c5c | 2019-05-28 11:21:51 +0200 | [diff] [blame] | 1589 | # Check that the selected Xcode version is actually installed on the host. |
| 1590 | xcode_path = "/Applications/Xcode{}.app".format(xcode_version) |
| 1591 | if not os.path.exists(xcode_path): |
| 1592 | raise BuildkiteException("Xcode not found at '{}'.".format(xcode_path)) |
| 1593 | |
| 1594 | # Now activate the specified Xcode version and let it install its required components. |
| 1595 | # The CI machines have a sudoers config that allows the 'buildkite' user to run exactly |
| 1596 | # these two commands, so don't change them without also modifying the file there. |
| 1597 | execute_command(["/usr/bin/sudo", "/usr/bin/xcode-select", "--switch", xcode_path]) |
| 1598 | execute_command(["/usr/bin/sudo", "/usr/bin/xcodebuild", "-runFirstLaunch"]) |
| 1599 | |
| 1600 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1601 | def get_bazelisk_cache_directory(): |
Florian Weikert | 4901c66 | 2019-02-26 13:20:11 +0100 | [diff] [blame] | 1602 | # The path relies on the behavior of Go's os.UserCacheDir() |
| 1603 | # and of the Go version of Bazelisk. |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1604 | cache_dir = "Library/Caches" if is_mac() else ".cache" |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 1605 | return os.path.join(os.environ.get("HOME"), cache_dir, "bazelisk") |
Florian Weikert | 4901c66 | 2019-02-26 13:20:11 +0100 | [diff] [blame] | 1606 | |
Florian Weikert | 5b89033 | 2019-02-25 14:57:43 +0100 | [diff] [blame] | 1607 | |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 1608 | def current_branch_is_main_branch(): |
Mai Hussien | 0731b4d | 2022-06-28 11:16:07 -0700 | [diff] [blame] | 1609 | return os.getenv("BUILDKITE_BRANCH") in ("master", "stable", "main", "google") |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 1610 | |
| 1611 | |
Yun Peng | 92c0ef8 | 2021-07-26 10:41:21 +0200 | [diff] [blame] | 1612 | def get_release_name_from_branch_name(): |
Yun Peng | 9894836 | 2022-11-08 16:14:20 +0100 | [diff] [blame] | 1613 | # TODO(pcloudy): Find a better way to do this |
| 1614 | if os.getenv("BUILDKITE_PIPELINE_SLUG") == "publish-bazel-binaries": |
| 1615 | return None |
Yun Peng | 26e01ff | 2021-07-26 12:05:53 +0200 | [diff] [blame] | 1616 | res = re.match(r"release-(\d+\.\d+\.\d+(rc\d+)?).*", os.getenv("BUILDKITE_BRANCH")) |
Yun Peng | 9894836 | 2022-11-08 16:14:20 +0100 | [diff] [blame] | 1617 | return res.group(1) if res else None |
Yun Peng | 92c0ef8 | 2021-07-26 10:41:21 +0200 | [diff] [blame] | 1618 | |
| 1619 | |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 1620 | def is_pull_request(): |
Jakob Buchgraber | 67761d3 | 2018-02-21 19:00:21 +0100 | [diff] [blame] | 1621 | third_party_repo = os.getenv("BUILDKITE_PULL_REQUEST_REPO", "") |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 1622 | return len(third_party_repo) > 0 |
| 1623 | |
| 1624 | |
Yun Peng | e3cf12d | 2018-12-05 15:01:09 +0100 | [diff] [blame] | 1625 | def print_bazel_version_info(bazel_binary, platform): |
Jakob Buchgraber | 99c4bbb | 2018-02-22 11:59:31 +0100 | [diff] [blame] | 1626 | print_collapsed_group(":information_source: Bazel Info") |
Philipp Wollermann | f13804b | 2019-02-05 21:08:30 +0100 | [diff] [blame] | 1627 | version_output = execute_command_and_get_output( |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 1628 | [bazel_binary] + common_startup_flags() + ["--nosystem_rc", "--nohome_rc", "version"] |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1629 | ) |
| 1630 | execute_command( |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 1631 | [bazel_binary] + common_startup_flags() + ["--nosystem_rc", "--nohome_rc", "info"] |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1632 | ) |
Jakob Buchgraber | 7e690a7 | 2018-02-18 13:22:15 +0100 | [diff] [blame] | 1633 | |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 1634 | match = BUILD_LABEL_PATTERN.search(version_output) |
| 1635 | return match.group(1) if match else "unreleased binary" |
| 1636 | |
Jakob Buchgraber | 7e690a7 | 2018-02-18 13:22:15 +0100 | [diff] [blame] | 1637 | |
Yun Peng | a5a1ee0 | 2018-12-05 15:00:58 +0100 | [diff] [blame] | 1638 | def print_environment_variables_info(): |
| 1639 | print_collapsed_group(":information_source: Environment Variables") |
| 1640 | for key, value in os.environ.items(): |
| 1641 | eprint("%s=(%s)" % (key, value)) |
| 1642 | |
| 1643 | |
Jakob Buchgraber | 426399e | 2018-03-20 19:45:46 +0100 | [diff] [blame] | 1644 | def upload_bazel_binary(platform): |
Jakob Buchgraber | 7d1d3bb | 2018-02-21 22:38:22 +0100 | [diff] [blame] | 1645 | print_collapsed_group(":gcloud: Uploading Bazel Under Test") |
Jakob Buchgraber | 426399e | 2018-03-20 19:45:46 +0100 | [diff] [blame] | 1646 | if platform == "windows": |
Philipp Wollermann | 1018321 | 2020-02-04 21:54:14 +0100 | [diff] [blame] | 1647 | binary_dir = r"bazel-bin\src" |
| 1648 | binary_name = r"bazel.exe" |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1649 | binary_nojdk_name = r"bazel_nojdk.exe" |
Philipp Wollermann | 1018321 | 2020-02-04 21:54:14 +0100 | [diff] [blame] | 1650 | else: |
| 1651 | binary_dir = "bazel-bin/src" |
| 1652 | binary_name = "bazel" |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1653 | binary_nojdk_name = "bazel_nojdk" |
Philipp Wollermann | 1018321 | 2020-02-04 21:54:14 +0100 | [diff] [blame] | 1654 | execute_command(["buildkite-agent", "artifact", "upload", binary_name], cwd=binary_dir) |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1655 | execute_command(["buildkite-agent", "artifact", "upload", binary_nojdk_name], cwd=binary_dir) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1656 | |
| 1657 | |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1658 | def merge_and_upload_kythe_kzip(platform, index_upload_gcs): |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1659 | print_collapsed_group(":gcloud: Uploading kythe kzip") |
| 1660 | |
Philipp Wollermann | 2b4ee9f | 2021-02-11 16:32:35 +0100 | [diff] [blame] | 1661 | kzips = glob("bazel-out/*/extra_actions/**/*.kzip", recursive=True) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1662 | |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1663 | build_number = os.getenv("BUILDKITE_BUILD_NUMBER") |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1664 | git_commit = os.getenv("BUILDKITE_COMMIT") |
| 1665 | final_kzip_name = "{}-{}-{}.kzip".format(build_number, platform, git_commit) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1666 | |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1667 | execute_command([f"{KYTHE_DIR}/tools/kzip", "merge", "--output", final_kzip_name] + kzips) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1668 | execute_command(["buildkite-agent", "artifact", "upload", final_kzip_name]) |
| 1669 | |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1670 | if index_upload_gcs: |
| 1671 | pipeline = os.getenv("BUILDKITE_PIPELINE_SLUG") |
Chi Wang | 08aea1c | 2022-03-21 18:04:52 +0800 | [diff] [blame] | 1672 | branch = os.getenv("BUILDKITE_BRANCH") |
| 1673 | destination = KZIPS_BUCKET + pipeline + "/" + branch + "/" + final_kzip_name |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1674 | print("Uploading to GCS {}".format(destination)) |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 1675 | execute_command([gsutil_command(), "cp", final_kzip_name, destination]) |
Chi Wang | b2b6568 | 2020-08-27 10:36:15 +0800 | [diff] [blame] | 1676 | |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 1677 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1678 | def download_binary(dest_dir, platform, binary_name): |
Philipp Wollermann | c52e26a | 2019-05-18 22:10:47 +0200 | [diff] [blame] | 1679 | source_step = create_label(platform, "Bazel", build_only=True) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1680 | execute_command( |
Philipp Wollermann | 1018321 | 2020-02-04 21:54:14 +0100 | [diff] [blame] | 1681 | ["buildkite-agent", "artifact", "download", binary_name, dest_dir, "--step", source_step] |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1682 | ) |
Philipp Wollermann | 1018321 | 2020-02-04 21:54:14 +0100 | [diff] [blame] | 1683 | bazel_binary_path = os.path.join(dest_dir, binary_name) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1684 | st = os.stat(bazel_binary_path) |
| 1685 | os.chmod(bazel_binary_path, st.st_mode | stat.S_IEXEC) |
| 1686 | return bazel_binary_path |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1687 | |
| 1688 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1689 | def download_bazel_binary(dest_dir, platform): |
| 1690 | binary_name = "bazel.exe" if platform == "windows" else "bazel" |
| 1691 | return download_binary(dest_dir, platform, binary_name) |
| 1692 | |
| 1693 | |
| 1694 | def download_bazel_nojdk_binary(dest_dir, platform): |
| 1695 | binary_name = "bazel_nojdk.exe" if platform == "windows" else "bazel_nojdk" |
| 1696 | return download_binary(dest_dir, platform, binary_name) |
| 1697 | |
| 1698 | |
Yun Peng | d433d4f | 2022-12-09 10:53:15 +0100 | [diff] [blame] | 1699 | def download_binary_at_commit(bazel_git_commit, bazel_binary_url, bazel_binary_path): |
Yun Peng | 0231273 | 2019-01-17 18:17:05 +0100 | [diff] [blame] | 1700 | try: |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 1701 | execute_command([gsutil_command(), "cp", bazel_binary_url, bazel_binary_path]) |
Yun Peng | 0231273 | 2019-01-17 18:17:05 +0100 | [diff] [blame] | 1702 | except subprocess.CalledProcessError as e: |
Yun Peng | d433d4f | 2022-12-09 10:53:15 +0100 | [diff] [blame] | 1703 | raise BuildkiteInfraException( |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 1704 | "Failed to download Bazel binary at %s, error message:\n%s" % (bazel_git_commit, str(e)) |
| 1705 | ) |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 1706 | st = os.stat(bazel_binary_path) |
| 1707 | os.chmod(bazel_binary_path, st.st_mode | stat.S_IEXEC) |
| 1708 | return bazel_binary_path |
| 1709 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1710 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1711 | def download_bazel_binary_at_commit(dest_dir, platform, bazel_git_commit): |
| 1712 | url = bazelci_builds_gs_url(platform, bazel_git_commit) |
| 1713 | path = os.path.join(dest_dir, "bazel.exe" if platform == "windows" else "bazel") |
Yun Peng | d433d4f | 2022-12-09 10:53:15 +0100 | [diff] [blame] | 1714 | return download_binary_at_commit(bazel_git_commit, url, path) |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1715 | |
| 1716 | |
| 1717 | def download_bazel_nojdk_binary_at_commit(dest_dir, platform, bazel_git_commit): |
| 1718 | url = bazelci_builds_nojdk_gs_url(platform, bazel_git_commit) |
| 1719 | path = os.path.join(dest_dir, "bazel_nojdk.exe" if platform == "windows" else "bazel_nojdk") |
Yun Peng | d433d4f | 2022-12-09 10:53:15 +0100 | [diff] [blame] | 1720 | return download_binary_at_commit(bazel_git_commit, url, path) |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1721 | |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 1722 | |
Chi Wang | d61eb97 | 2023-01-18 11:36:18 +0100 | [diff] [blame] | 1723 | def download_bazelci_agent(dest_dir): |
Chi Wang | af6d5b1 | 2023-05-10 11:48:05 +0000 | [diff] [blame] | 1724 | repo = "bazelbuild/continuous-integration" |
Chi Wang | 4412ef1 | 2023-05-10 16:29:22 +0000 | [diff] [blame^] | 1725 | if THIS_IS_TESTING and "BAZELCI_AGENT_REPO" in os.environ: |
Chi Wang | af6d5b1 | 2023-05-10 11:48:05 +0000 | [diff] [blame] | 1726 | repo = os.environ["BAZELCI_AGENT_REPO"] |
Chi Wang | d61eb97 | 2023-01-18 11:36:18 +0100 | [diff] [blame] | 1727 | version = "0.1.4" |
Chi Wang | 4412ef1 | 2023-05-10 16:29:22 +0000 | [diff] [blame^] | 1728 | if THIS_IS_TESTING and "BAZELCI_AGENT_VERSION" in os.environ: |
Chi Wang | af6d5b1 | 2023-05-10 11:48:05 +0000 | [diff] [blame] | 1729 | version = os.environ["BAZELCI_AGENT_VERSION"] |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 1730 | postfix = "" |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1731 | if is_windows(): |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 1732 | postfix = "x86_64-pc-windows-msvc.exe" |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1733 | elif is_mac(): |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 1734 | if platform_module.machine() == "arm64": |
Chi Wang | 74ad6ca | 2022-10-21 11:20:36 +0200 | [diff] [blame] | 1735 | postfix = "aarch64-apple-darwin" |
| 1736 | else: |
| 1737 | postfix = "x86_64-apple-darwin" |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 1738 | else: |
Chi Wang | aac1ead | 2023-01-17 11:10:48 +0100 | [diff] [blame] | 1739 | if platform_module.machine() == "aarch64": |
| 1740 | postfix = "aarch64-unknown-linux-musl" |
| 1741 | else: |
| 1742 | postfix = "x86_64-unknown-linux-musl" |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 1743 | |
| 1744 | name = "bazelci-agent-{}-{}".format(version, postfix) |
Florian Weikert | 9b805ce | 2023-05-10 18:04:03 +0200 | [diff] [blame] | 1745 | url = "https://github.com/{}/releases/download/agent-{}/{}".format(repo, version, name) |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1746 | path = os.path.join(dest_dir, "bazelci-agent.exe" if is_windows() else "bazelci-agent") |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 1747 | execute_command(["curl", "-sSL", url, "-o", path]) |
| 1748 | st = os.stat(path) |
| 1749 | os.chmod(path, st.st_mode | stat.S_IEXEC) |
| 1750 | return path |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 1751 | |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 1752 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1753 | def get_mirror_root(): |
| 1754 | if is_mac(): |
| 1755 | return "/usr/local/var/bazelbuild/" |
| 1756 | elif is_windows(): |
| 1757 | return "c:\\buildkite\\bazelbuild\\" |
joeleba | 7050d84 | 2019-05-23 17:03:31 +0200 | [diff] [blame] | 1758 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1759 | return "/var/lib/bazelbuild/" |
joeleba | 7050d84 | 2019-05-23 17:03:31 +0200 | [diff] [blame] | 1760 | |
| 1761 | |
Yun Peng | 376d2b3 | 2018-11-29 10:24:54 +0100 | [diff] [blame] | 1762 | def clone_git_repository(git_repository, platform, git_commit=None): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1763 | root = downstream_projects_root(platform) |
Philipp Wollermann | ff39ef5 | 2018-02-21 14:18:52 +0100 | [diff] [blame] | 1764 | project_name = re.search(r"/([^/]+)\.git$", git_repository).group(1) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1765 | clone_path = os.path.join(root, project_name) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1766 | print_collapsed_group( |
| 1767 | "Fetching %s sources at %s" % (project_name, git_commit if git_commit else "HEAD") |
| 1768 | ) |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 1769 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1770 | mirror_path = get_mirror_root() + re.sub(r"[^0-9A-Za-z]", "-", git_repository) |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 1771 | |
Philipp Wollermann | 414703d | 2018-08-28 16:40:38 +0200 | [diff] [blame] | 1772 | if not os.path.exists(clone_path): |
Philipp Wollermann | 62f4a03 | 2019-05-08 17:44:14 +0200 | [diff] [blame] | 1773 | if os.path.exists(mirror_path): |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1774 | execute_command( |
Philipp Wollermann | 62f4a03 | 2019-05-08 17:44:14 +0200 | [diff] [blame] | 1775 | ["git", "clone", "-v", "--reference", mirror_path, git_repository, clone_path] |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1776 | ) |
Philipp Wollermann | d4cd0d8 | 2018-05-01 09:56:24 +0200 | [diff] [blame] | 1777 | else: |
Philipp Wollermann | ea12828 | 2019-05-08 11:56:14 +0200 | [diff] [blame] | 1778 | execute_command(["git", "clone", "-v", git_repository, clone_path]) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1779 | |
Philipp Wollermann | 414703d | 2018-08-28 16:40:38 +0200 | [diff] [blame] | 1780 | os.chdir(clone_path) |
| 1781 | execute_command(["git", "remote", "set-url", "origin", git_repository]) |
| 1782 | execute_command(["git", "clean", "-fdqx"]) |
Florian Weikert | d8f497c | 2019-06-19 15:44:20 +0200 | [diff] [blame] | 1783 | execute_command(["git", "submodule", "foreach", "--recursive", "git clean -fdqx"]) |
Philipp Wollermann | 414703d | 2018-08-28 16:40:38 +0200 | [diff] [blame] | 1784 | execute_command(["git", "fetch", "origin"]) |
Yun Peng | 376d2b3 | 2018-11-29 10:24:54 +0100 | [diff] [blame] | 1785 | if git_commit: |
| 1786 | # sync to a specific commit of this repository |
| 1787 | execute_command(["git", "reset", git_commit, "--hard"]) |
| 1788 | else: |
| 1789 | # sync to the latest commit of HEAD. Unlikely git pull this also works after a force push. |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1790 | remote_head = ( |
| 1791 | subprocess.check_output(["git", "symbolic-ref", "refs/remotes/origin/HEAD"]) |
| 1792 | .decode("utf-8") |
| 1793 | .rstrip() |
| 1794 | ) |
Yun Peng | 376d2b3 | 2018-11-29 10:24:54 +0100 | [diff] [blame] | 1795 | execute_command(["git", "reset", remote_head, "--hard"]) |
Philipp Wollermann | 414703d | 2018-08-28 16:40:38 +0200 | [diff] [blame] | 1796 | execute_command(["git", "submodule", "sync", "--recursive"]) |
| 1797 | execute_command(["git", "submodule", "update", "--init", "--recursive", "--force"]) |
Florian Weikert | d8f497c | 2019-06-19 15:44:20 +0200 | [diff] [blame] | 1798 | execute_command(["git", "submodule", "foreach", "--recursive", "git reset --hard"]) |
Philipp Wollermann | 414703d | 2018-08-28 16:40:38 +0200 | [diff] [blame] | 1799 | execute_command(["git", "clean", "-fdqx"]) |
Florian Weikert | d8f497c | 2019-06-19 15:44:20 +0200 | [diff] [blame] | 1800 | execute_command(["git", "submodule", "foreach", "--recursive", "git clean -fdqx"]) |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 1801 | return clone_path |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1802 | |
Philipp Wollermann | 438ec24 | 2018-09-05 14:39:24 +0200 | [diff] [blame] | 1803 | |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 1804 | def execute_batch_commands(commands, print_group=True): |
Yun Peng | a935a54 | 2018-05-18 15:08:53 +0200 | [diff] [blame] | 1805 | if not commands: |
| 1806 | return |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 1807 | |
| 1808 | if print_group: |
| 1809 | print_collapsed_group(":batch: Setup (Batch Commands)") |
| 1810 | |
Yun Peng | a935a54 | 2018-05-18 15:08:53 +0200 | [diff] [blame] | 1811 | batch_commands = "&".join(commands) |
Jakob Buchgraber | 4a82441 | 2018-06-22 12:56:10 +0200 | [diff] [blame] | 1812 | return subprocess.run(batch_commands, shell=True, check=True, env=os.environ).returncode |
Yun Peng | a935a54 | 2018-05-18 15:08:53 +0200 | [diff] [blame] | 1813 | |
Philipp Wollermann | 414703d | 2018-08-28 16:40:38 +0200 | [diff] [blame] | 1814 | |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 1815 | def execute_shell_commands(commands, print_group=True): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1816 | if not commands: |
| 1817 | return |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 1818 | |
| 1819 | if print_group: |
| 1820 | print_collapsed_group(":bash: Setup (Shell Commands)") |
| 1821 | |
mostynb | 1444091 | 2020-03-17 17:11:47 +0100 | [diff] [blame] | 1822 | shell_command = "\n".join(["set -e"] + commands) |
Philipp Wollermann | 3e1a771 | 2018-02-19 17:34:24 +0100 | [diff] [blame] | 1823 | execute_command([shell_command], shell=True) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1824 | |
| 1825 | |
Yun Peng | 0a6a98a | 2019-03-06 13:07:54 +0100 | [diff] [blame] | 1826 | def handle_bazel_failure(exception, action): |
| 1827 | msg = "bazel {0} failed with exit code {1}".format(action, exception.returncode) |
| 1828 | if use_bazelisk_migrate(): |
| 1829 | print_collapsed_group(msg) |
| 1830 | else: |
| 1831 | raise BuildkiteException(msg) |
| 1832 | |
| 1833 | |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 1834 | def execute_bazel_run(bazel_binary, platform, targets): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 1835 | if not targets: |
| 1836 | return |
| 1837 | print_collapsed_group("Setup (Run Targets)") |
| 1838 | for target in targets: |
Yun Peng | 0a6a98a | 2019-03-06 13:07:54 +0100 | [diff] [blame] | 1839 | try: |
| 1840 | execute_command( |
| 1841 | [bazel_binary] |
| 1842 | + bazelisk_flags() |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1843 | + common_startup_flags() |
Yun Peng | 0a6a98a | 2019-03-06 13:07:54 +0100 | [diff] [blame] | 1844 | + ["run"] |
| 1845 | + common_build_flags(None, platform) |
Yun Peng | 0a6a98a | 2019-03-06 13:07:54 +0100 | [diff] [blame] | 1846 | + [target] |
| 1847 | ) |
| 1848 | except subprocess.CalledProcessError as e: |
| 1849 | handle_bazel_failure(e, "run") |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 1850 | |
| 1851 | |
Philipp Wollermann | c4752e4 | 2022-02-08 16:35:39 +0100 | [diff] [blame] | 1852 | def remote_caching_flags(platform, accept_cached=True): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 1853 | # Only enable caching for untrusted and testing builds. |
Philipp Wollermann | fce92bf | 2019-05-22 15:14:32 +0200 | [diff] [blame] | 1854 | if CLOUD_PROJECT not in ["bazel-untrusted"]: |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1855 | return [] |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 1856 | |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 1857 | platform_cache_key = [BUILDKITE_ORG.encode("utf-8")] |
Jakob Buchgraber | 89df398 | 2019-08-06 13:07:02 +0200 | [diff] [blame] | 1858 | # Whenever the remote cache was known to have been poisoned increase the number below |
Yun Peng | d7e28c0 | 2022-09-12 16:40:36 +0200 | [diff] [blame] | 1859 | platform_cache_key += ["cache-poisoning-20220912".encode("utf-8")] |
Philipp Wollermann | fce92bf | 2019-05-22 15:14:32 +0200 | [diff] [blame] | 1860 | |
Yun Peng | 07dafc5 | 2022-03-16 13:23:35 +0100 | [diff] [blame] | 1861 | # We don't enable remote caching on the Linux ARM64 machine since it doesn't have access to GCS. |
| 1862 | if platform == "ubuntu2004_arm64": |
| 1863 | return [] |
| 1864 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1865 | if is_mac(): |
Philipp Wollermann | fce92bf | 2019-05-22 15:14:32 +0200 | [diff] [blame] | 1866 | platform_cache_key += [ |
Philipp Wollermann | ef89d2f | 2019-04-18 15:52:24 +0200 | [diff] [blame] | 1867 | # macOS version: |
| 1868 | subprocess.check_output(["/usr/bin/sw_vers", "-productVersion"]), |
| 1869 | # Path to Xcode: |
| 1870 | subprocess.check_output(["/usr/bin/xcode-select", "-p"]), |
| 1871 | # Xcode version: |
| 1872 | subprocess.check_output(["/usr/bin/xcodebuild", "-version"]), |
| 1873 | ] |
| 1874 | # Use a local cache server for our macOS machines. |
Philipp Wollermann | b9e9628 | 2020-02-18 13:59:27 +0100 | [diff] [blame] | 1875 | flags = ["--remote_cache=http://100.107.73.148"] |
Philipp Wollermann | ef89d2f | 2019-04-18 15:52:24 +0200 | [diff] [blame] | 1876 | else: |
Philipp Wollermann | fce92bf | 2019-05-22 15:14:32 +0200 | [diff] [blame] | 1877 | platform_cache_key += [ |
Philipp Wollermann | ef89d2f | 2019-04-18 15:52:24 +0200 | [diff] [blame] | 1878 | # Platform name: |
| 1879 | platform.encode("utf-8") |
| 1880 | ] |
Philipp Wollermann | e74da4e | 2019-06-07 11:31:02 +0200 | [diff] [blame] | 1881 | # Use RBE for caching builds running on GCE. |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 1882 | flags = [ |
| 1883 | "--google_default_credentials", |
Philipp Wollermann | e74da4e | 2019-06-07 11:31:02 +0200 | [diff] [blame] | 1884 | "--remote_cache=remotebuildexecution.googleapis.com", |
| 1885 | "--remote_instance_name=projects/{}/instances/default_instance".format(CLOUD_PROJECT), |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 1886 | ] |
Philipp Wollermann | 380f1e6 | 2019-04-12 16:45:27 +0200 | [diff] [blame] | 1887 | |
| 1888 | platform_cache_digest = hashlib.sha256() |
| 1889 | for key in platform_cache_key: |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 1890 | eprint("Adding to platform cache key: {}".format(key)) |
Philipp Wollermann | 380f1e6 | 2019-04-12 16:45:27 +0200 | [diff] [blame] | 1891 | platform_cache_digest.update(key) |
| 1892 | platform_cache_digest.update(b":") |
| 1893 | |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 1894 | flags += [ |
Philipp Wollermann | 9493772 | 2019-01-11 14:33:18 +0100 | [diff] [blame] | 1895 | "--remote_timeout=60", |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1896 | "--remote_max_connections=200", |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 1897 | '--remote_default_platform_properties=properties:{name:"cache-silo-key" value:"%s"}' |
| 1898 | % platform_cache_digest.hexdigest(), |
Yun Peng | 5985f74 | 2023-04-17 11:32:42 +0200 | [diff] [blame] | 1899 | "--remote_download_toplevel", |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1900 | ] |
Jakob Buchgraber | 4f1d271 | 2018-02-20 10:22:47 +0100 | [diff] [blame] | 1901 | |
Yun Peng | b2fbce3 | 2022-02-04 12:56:34 +0100 | [diff] [blame] | 1902 | if not accept_cached: |
| 1903 | flags += ["--noremote_accept_cached"] |
| 1904 | |
Philipp Wollermann | d96d8fa | 2019-01-11 14:37:47 +0100 | [diff] [blame] | 1905 | return flags |
| 1906 | |
Jakob Buchgraber | 4f1d271 | 2018-02-20 10:22:47 +0100 | [diff] [blame] | 1907 | |
Jakob Buchgraber | b4342cd | 2018-02-20 16:35:07 +0100 | [diff] [blame] | 1908 | def remote_enabled(flags): |
| 1909 | # Detect if the project configuration enabled its own remote caching / execution. |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1910 | remote_flags = ["--remote_executor", "--remote_cache", "--remote_http_cache"] |
Jakob Buchgraber | b4342cd | 2018-02-20 16:35:07 +0100 | [diff] [blame] | 1911 | for flag in flags: |
| 1912 | for remote_flag in remote_flags: |
| 1913 | if flag.startswith(remote_flag): |
| 1914 | return True |
| 1915 | return False |
| 1916 | |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 1917 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1918 | def concurrent_jobs(platform): |
| 1919 | return "75" if platform.startswith("rbe_") else str(multiprocessing.cpu_count()) |
Jakob Buchgraber | 51a8366 | 2018-02-22 19:49:24 +0100 | [diff] [blame] | 1920 | |
| 1921 | |
Philipp Wollermann | 3e28d3b | 2018-02-23 23:19:37 +0100 | [diff] [blame] | 1922 | def concurrent_test_jobs(platform): |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1923 | if platform.startswith("rbe_"): |
| 1924 | return "75" |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1925 | elif is_windows(): |
Jakob Buchgraber | e3ccda3 | 2018-06-22 23:29:48 +0200 | [diff] [blame] | 1926 | return "8" |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1927 | elif is_mac() and THIS_IS_TESTING: |
Philipp Wollermann | 85877cb | 2021-07-02 19:20:33 +0200 | [diff] [blame] | 1928 | return "4" |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1929 | elif is_mac(): |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 1930 | # TODO(twerth): This is an experiment, remove. |
| 1931 | return str(int(multiprocessing.cpu_count() / 2)) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1932 | return "12" |
Philipp Wollermann | 3e28d3b | 2018-02-23 23:19:37 +0100 | [diff] [blame] | 1933 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1934 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1935 | def common_startup_flags(): |
| 1936 | if is_windows(): |
Philipp Wollermann | d5ab3d9 | 2020-02-05 16:55:13 +0100 | [diff] [blame] | 1937 | if os.path.exists("D:/b"): |
| 1938 | # This machine has a local SSD mounted as drive D. |
| 1939 | return ["--output_user_root=D:/b"] |
| 1940 | else: |
| 1941 | # This machine uses its PD-SSD as the build directory. |
| 1942 | return ["--output_user_root=C:/b"] |
| 1943 | return [] |
Yun Peng | 58977d6 | 2018-11-16 12:19:20 +0100 | [diff] [blame] | 1944 | |
| 1945 | |
| 1946 | def common_build_flags(bep_file, platform): |
Yun Peng | 088cc93 | 2018-11-16 12:11:46 +0100 | [diff] [blame] | 1947 | flags = [ |
Yun Peng | f51e784 | 2018-11-16 11:35:43 +0100 | [diff] [blame] | 1948 | "--show_progress_rate_limit=5", |
| 1949 | "--curses=yes", |
| 1950 | "--color=yes", |
Philipp Wollermann | d99414c | 2019-05-28 17:26:09 +0200 | [diff] [blame] | 1951 | "--terminal_columns=143", |
Philipp Wollermann | 4c8391e | 2019-05-28 18:03:35 +0200 | [diff] [blame] | 1952 | "--show_timestamps", |
Yun Peng | f51e784 | 2018-11-16 11:35:43 +0100 | [diff] [blame] | 1953 | "--verbose_failures", |
Yun Peng | f51e784 | 2018-11-16 11:35:43 +0100 | [diff] [blame] | 1954 | "--jobs=" + concurrent_jobs(platform), |
Yun Peng | f51e784 | 2018-11-16 11:35:43 +0100 | [diff] [blame] | 1955 | "--announce_rc", |
Philipp Wollermann | b97f910 | 2019-04-16 18:05:56 +0200 | [diff] [blame] | 1956 | "--experimental_repository_cache_hardlinks", |
Philipp Wollermann | ef89d2f | 2019-04-18 15:52:24 +0200 | [diff] [blame] | 1957 | # Some projects set --disk_cache in their project-specific bazelrc, which we never want on |
| 1958 | # CI, so let's just disable it explicitly. |
| 1959 | "--disk_cache=", |
Yun Peng | 088cc93 | 2018-11-16 12:11:46 +0100 | [diff] [blame] | 1960 | ] |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1961 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1962 | if is_windows(): |
Philipp Wollermann | b97f910 | 2019-04-16 18:05:56 +0200 | [diff] [blame] | 1963 | pass |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 1964 | elif is_mac(): |
Philipp Wollermann | b97f910 | 2019-04-16 18:05:56 +0200 | [diff] [blame] | 1965 | flags += [ |
| 1966 | "--sandbox_writable_path=/var/tmp/_bazel_buildkite/cache/repos/v1", |
| 1967 | "--test_env=REPOSITORY_CACHE=/var/tmp/_bazel_buildkite/cache/repos/v1", |
| 1968 | ] |
| 1969 | else: |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1970 | flags += ["--sandbox_tmpfs_path=/tmp"] |
| 1971 | |
Yun Peng | 088cc93 | 2018-11-16 12:11:46 +0100 | [diff] [blame] | 1972 | if bep_file: |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 1973 | flags += [ |
| 1974 | "--experimental_build_event_json_file_path_conversion=false", |
| 1975 | "--build_event_json_file=" + bep_file, |
| 1976 | ] |
| 1977 | |
Yun Peng | 088cc93 | 2018-11-16 12:11:46 +0100 | [diff] [blame] | 1978 | return flags |
Philipp Wollermann | 94bd9e3 | 2018-04-30 15:32:28 +0200 | [diff] [blame] | 1979 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1980 | |
Yun Peng | b7247ff | 2018-11-15 13:52:39 +0100 | [diff] [blame] | 1981 | def rbe_flags(original_flags, accept_cached): |
Philipp Wollermann | bcfd9da | 2018-08-09 15:31:18 +0200 | [diff] [blame] | 1982 | # Enable remote execution via RBE. |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1983 | flags = [ |
| 1984 | "--remote_executor=remotebuildexecution.googleapis.com", |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 1985 | "--remote_instance_name=projects/bazel-untrusted/instances/default_instance", |
Philipp Wollermann | 2df9348 | 2021-06-16 04:39:49 +0200 | [diff] [blame] | 1986 | "--remote_timeout=3600", |
Philipp Wollermann | 57dadb8 | 2020-02-17 14:32:24 +0100 | [diff] [blame] | 1987 | "--incompatible_strict_action_env", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 1988 | "--google_default_credentials", |
Philipp Wollermann | 57dadb8 | 2020-02-17 14:32:24 +0100 | [diff] [blame] | 1989 | "--toolchain_resolution_debug", |
Yun Peng | 5985f74 | 2023-04-17 11:32:42 +0200 | [diff] [blame] | 1990 | "--remote_download_toplevel", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 1991 | ] |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 1992 | |
Philipp Wollermann | bcfd9da | 2018-08-09 15:31:18 +0200 | [diff] [blame] | 1993 | # Enable BES / Build Results reporting. |
| 1994 | flags += [ |
| 1995 | "--bes_backend=buildeventservice.googleapis.com", |
Philipp Wollermann | bcfd9da | 2018-08-09 15:31:18 +0200 | [diff] [blame] | 1996 | "--bes_timeout=360s", |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 1997 | "--project_id=bazel-untrusted", |
Philipp Wollermann | bcfd9da | 2018-08-09 15:31:18 +0200 | [diff] [blame] | 1998 | ] |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 1999 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2000 | if not accept_cached: |
| 2001 | flags += ["--noremote_accept_cached"] |
Philipp Wollermann | bcfd9da | 2018-08-09 15:31:18 +0200 | [diff] [blame] | 2002 | |
Nicolas Lopez | 3699622 | 2019-05-28 12:21:28 -0400 | [diff] [blame] | 2003 | # Adapted from https://github.com/bazelbuild/bazel-toolchains/blob/master/bazelrc/.bazelrc |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2004 | flags += [ |
Nicolas Lopez | 3699622 | 2019-05-28 12:21:28 -0400 | [diff] [blame] | 2005 | # These should NOT longer need to be modified. |
| 2006 | # All that is needed is updating the @bazel_toolchains repo pin |
| 2007 | # in projects' WORKSPACE files. |
Xin | db02c01 | 2018-11-07 14:10:54 -0500 | [diff] [blame] | 2008 | # |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2009 | # Toolchain related flags to append at the end of your .bazelrc file. |
Nicolas Lopez | 3699622 | 2019-05-28 12:21:28 -0400 | [diff] [blame] | 2010 | "--host_javabase=@buildkite_config//java:jdk", |
| 2011 | "--javabase=@buildkite_config//java:jdk", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2012 | "--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8", |
| 2013 | "--java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8", |
Nicolas Lopez | 3699622 | 2019-05-28 12:21:28 -0400 | [diff] [blame] | 2014 | "--crosstool_top=@buildkite_config//cc:toolchain", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2015 | "--action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1", |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2016 | ] |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 2017 | |
Yun Peng | b7247ff | 2018-11-15 13:52:39 +0100 | [diff] [blame] | 2018 | # Platform flags: |
| 2019 | # The toolchain container used for execution is defined in the target indicated |
| 2020 | # by "extra_execution_platforms", "host_platform" and "platforms". |
Xin | 03a88ab | 2019-03-11 19:18:50 -0400 | [diff] [blame] | 2021 | # If you are using your own toolchain container, you need to create a platform |
| 2022 | # target with "constraint_values" that allow for the toolchain specified with |
| 2023 | # "extra_toolchains" to be selected (given constraints defined in |
| 2024 | # "exec_compatible_with"). |
Yun Peng | b7247ff | 2018-11-15 13:52:39 +0100 | [diff] [blame] | 2025 | # More about platforms: https://docs.bazel.build/versions/master/platforms.html |
| 2026 | # Don't add platform flags if they are specified already. |
| 2027 | platform_flags = { |
Nicolas Lopez | 3699622 | 2019-05-28 12:21:28 -0400 | [diff] [blame] | 2028 | "--extra_toolchains": "@buildkite_config//config:cc-toolchain", |
| 2029 | "--extra_execution_platforms": "@buildkite_config//config:platform", |
| 2030 | "--host_platform": "@buildkite_config//config:platform", |
| 2031 | "--platforms": "@buildkite_config//config:platform", |
Yun Peng | b7247ff | 2018-11-15 13:52:39 +0100 | [diff] [blame] | 2032 | } |
Yun Peng | 67ab506 | 2018-11-15 13:58:15 +0100 | [diff] [blame] | 2033 | for platform_flag, value in list(platform_flags.items()): |
Yun Peng | b7247ff | 2018-11-15 13:52:39 +0100 | [diff] [blame] | 2034 | found = False |
| 2035 | for original_flag in original_flags: |
| 2036 | if original_flag.startswith(platform_flag): |
| 2037 | found = True |
| 2038 | break |
| 2039 | if not found: |
| 2040 | flags += [platform_flag + "=" + value] |
| 2041 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2042 | return flags |
| 2043 | |
| 2044 | |
Yun Peng | 28a9a53 | 2023-05-10 14:19:46 +0200 | [diff] [blame] | 2045 | def get_output_base(bazel_binary): |
Yun Peng | 2b6de29 | 2022-02-10 14:28:06 +0100 | [diff] [blame] | 2046 | return execute_command_and_get_output( |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2047 | [bazel_binary] + common_startup_flags() + ["info", "output_base"], |
Yun Peng | 2b6de29 | 2022-02-10 14:28:06 +0100 | [diff] [blame] | 2048 | print_output=False, |
| 2049 | ).strip() |
| 2050 | |
| 2051 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2052 | def compute_flags(platform, flags, bep_file, bazel_binary, enable_remote_cache=False): |
Yun Peng | 58977d6 | 2018-11-16 12:19:20 +0100 | [diff] [blame] | 2053 | aggregated_flags = common_build_flags(bep_file, platform) |
Yun Peng | 32dbec3 | 2018-11-02 12:47:41 +0100 | [diff] [blame] | 2054 | if not remote_enabled(flags): |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2055 | if platform.startswith("rbe_"): |
Florian Weikert | 24a4b48 | 2018-11-30 19:05:38 +0100 | [diff] [blame] | 2056 | aggregated_flags += rbe_flags(flags, accept_cached=enable_remote_cache) |
Yun Peng | b2fbce3 | 2022-02-04 12:56:34 +0100 | [diff] [blame] | 2057 | else: |
| 2058 | aggregated_flags += remote_caching_flags(platform, accept_cached=enable_remote_cache) |
Yun Peng | 7578655 | 2018-11-13 15:23:30 +0100 | [diff] [blame] | 2059 | aggregated_flags += flags |
Yun Peng | 5359800 | 2018-12-03 10:42:02 +0100 | [diff] [blame] | 2060 | |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2061 | for i, flag in enumerate(aggregated_flags): |
| 2062 | if "$HOME" in flag: |
Florian Weikert | a6110a9 | 2022-10-20 01:16:09 +0200 | [diff] [blame] | 2063 | if is_windows(): |
Philipp Wollermann | d5ab3d9 | 2020-02-05 16:55:13 +0100 | [diff] [blame] | 2064 | if os.path.exists("D:/"): |
| 2065 | home = "D:" |
| 2066 | else: |
| 2067 | home = "C:/b" |
Florian Weikert | a6110a9 | 2022-10-20 01:16:09 +0200 | [diff] [blame] | 2068 | elif is_mac(): |
Philipp Wollermann | d5ab3d9 | 2020-02-05 16:55:13 +0100 | [diff] [blame] | 2069 | home = "/Users/buildkite" |
| 2070 | else: |
| 2071 | home = "/var/lib/buildkite-agent" |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2072 | aggregated_flags[i] = flag.replace("$HOME", home) |
| 2073 | if "$OUTPUT_BASE" in flag: |
Yun Peng | 28a9a53 | 2023-05-10 14:19:46 +0200 | [diff] [blame] | 2074 | output_base = get_output_base(bazel_binary) |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2075 | aggregated_flags[i] = flag.replace("$OUTPUT_BASE", output_base) |
| 2076 | |
Florian Weikert | 24a4b48 | 2018-11-30 19:05:38 +0100 | [diff] [blame] | 2077 | return aggregated_flags |
Yun Peng | 5359800 | 2018-12-03 10:42:02 +0100 | [diff] [blame] | 2078 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2079 | |
Yun Peng | ea0359e | 2019-01-17 15:37:47 +0100 | [diff] [blame] | 2080 | def execute_bazel_clean(bazel_binary, platform): |
| 2081 | print_expanded_group(":bazel: Clean") |
| 2082 | |
| 2083 | try: |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2084 | execute_command([bazel_binary] + common_startup_flags() + ["clean", "--expunge"]) |
Yun Peng | ea0359e | 2019-01-17 15:37:47 +0100 | [diff] [blame] | 2085 | except subprocess.CalledProcessError as e: |
| 2086 | raise BuildkiteException("bazel clean failed with exit code {}".format(e.returncode)) |
| 2087 | |
| 2088 | |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2089 | def kythe_startup_flags(): |
| 2090 | return [f"--bazelrc={KYTHE_DIR}/extractors.bazelrc"] |
| 2091 | |
| 2092 | |
| 2093 | def kythe_build_flags(): |
Philipp Wollermann | f61a20b | 2021-05-05 22:04:20 +0200 | [diff] [blame] | 2094 | return [ |
| 2095 | "--experimental_convenience_symlinks=normal", |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 2096 | f"--override_repository=kythe_release={KYTHE_DIR}", |
Philipp Wollermann | f61a20b | 2021-05-05 22:04:20 +0200 | [diff] [blame] | 2097 | ] |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2098 | |
| 2099 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2100 | def execute_bazel_build(bazel_version, bazel_binary, platform, flags, targets, bep_file): |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 2101 | print_collapsed_group(":bazel: Computing flags for build step") |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2102 | aggregated_flags = compute_flags( |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 2103 | platform, |
| 2104 | flags, |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 2105 | bep_file, |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2106 | bazel_binary, |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2107 | enable_remote_cache=True, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2108 | ) |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 2109 | |
| 2110 | print_expanded_group(":bazel: Build ({})".format(bazel_version)) |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 2111 | try: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2112 | execute_command( |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2113 | [bazel_binary] |
| 2114 | + bazelisk_flags() |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2115 | + common_startup_flags() |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2116 | + ["build"] |
| 2117 | + aggregated_flags |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 2118 | + ["--"] |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2119 | + targets |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2120 | ) |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 2121 | except subprocess.CalledProcessError as e: |
Yun Peng | 0a6a98a | 2019-03-06 13:07:54 +0100 | [diff] [blame] | 2122 | handle_bazel_failure(e, "build") |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2123 | |
| 2124 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2125 | def execute_bazel_build_with_kythe(bazel_version, bazel_binary, platform, flags, targets, bep_file): |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2126 | print_collapsed_group(":bazel: Computing flags for build step") |
| 2127 | aggregated_flags = compute_flags( |
| 2128 | platform, |
| 2129 | flags, |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2130 | bep_file, |
| 2131 | bazel_binary, |
| 2132 | enable_remote_cache=False, |
| 2133 | ) |
| 2134 | |
| 2135 | print_expanded_group(":bazel: Build ({})".format(bazel_version)) |
| 2136 | |
| 2137 | execute_command( |
| 2138 | [bazel_binary] |
| 2139 | + bazelisk_flags() |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2140 | + common_startup_flags() |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2141 | + kythe_startup_flags() |
| 2142 | + ["build"] |
| 2143 | + kythe_build_flags() |
| 2144 | + aggregated_flags |
| 2145 | + ["--"] |
| 2146 | + targets |
| 2147 | ) |
| 2148 | |
| 2149 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2150 | def calculate_targets( |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2151 | task_config, |
| 2152 | bazel_binary, |
| 2153 | build_only, |
| 2154 | test_only, |
| 2155 | workspace_dir, |
| 2156 | ws_setup_func, |
| 2157 | git_commit, |
| 2158 | test_flags, |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2159 | ): |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2160 | print_collapsed_group(":dart: Calculating targets") |
| 2161 | |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2162 | build_targets = [] if test_only else task_config.get("build_targets", []) |
| 2163 | test_targets = [] if build_only else task_config.get("test_targets", []) |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 2164 | coverage_targets = [] if (build_only or test_only) else task_config.get("coverage_targets", []) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2165 | index_targets = [] if (build_only or test_only) else task_config.get("index_targets", []) |
| 2166 | |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2167 | index_targets_query = ( |
| 2168 | None if (build_only or test_only) else task_config.get("index_targets_query", None) |
| 2169 | ) |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2170 | if index_targets_query: |
| 2171 | output = execute_command_and_get_output( |
| 2172 | [bazel_binary] |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2173 | + common_startup_flags() |
Yun Peng | 8e8cdcf | 2022-03-16 13:08:15 +0100 | [diff] [blame] | 2174 | + ["--nosystem_rc", "--nohome_rc", "query", index_targets_query], |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2175 | print_output=False, |
| 2176 | ) |
| 2177 | index_targets += output.strip().split("\n") |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2178 | |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 2179 | # Remove the "--" argument splitter from the list that some configs explicitly |
| 2180 | # include. We'll add it back again later where needed. |
| 2181 | build_targets = [x.strip() for x in build_targets if x.strip() != "--"] |
| 2182 | test_targets = [x.strip() for x in test_targets if x.strip() != "--"] |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 2183 | coverage_targets = [x.strip() for x in coverage_targets if x.strip() != "--"] |
Chi Wang | 6357efe | 2020-08-25 16:23:38 +0800 | [diff] [blame] | 2184 | index_targets = [x.strip() for x in index_targets if x.strip() != "--"] |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 2185 | |
Florian Weikert | dcbbdf3 | 2023-05-02 11:58:53 +0200 | [diff] [blame] | 2186 | diffbase = os.getenv(USE_BAZEL_DIFF_ENV_VAR, "").lower() |
| 2187 | shard_id = int(os.getenv("BUILDKITE_PARALLEL_JOB", "-1")) |
| 2188 | shard_count = int(os.getenv("BUILDKITE_PARALLEL_JOB_COUNT", "-1")) |
| 2189 | sharding_enabled = shard_id > -1 and shard_count > -1 |
| 2190 | |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2191 | use_bazel_diff = diffbase and can_use_bazel_diff() |
| 2192 | |
Florian Weikert | dcbbdf3 | 2023-05-02 11:58:53 +0200 | [diff] [blame] | 2193 | # Skip target expansion if we don't need to calculate test targets |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2194 | if not use_bazel_diff and not sharding_enabled: |
Florian Weikert | dcbbdf3 | 2023-05-02 11:58:53 +0200 | [diff] [blame] | 2195 | return build_targets, test_targets, coverage_targets, index_targets |
| 2196 | |
| 2197 | # TODO(#1614): Fix target expansion |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2198 | expanded_test_targets = expand_test_target_patterns(bazel_binary, test_targets, test_flags) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2199 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2200 | actual_test_targets = ( |
| 2201 | filter_unchanged_targets( |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2202 | expanded_test_targets, |
| 2203 | workspace_dir, |
| 2204 | ws_setup_func, |
| 2205 | bazel_binary, |
| 2206 | diffbase, |
| 2207 | git_commit, |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2208 | ) |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2209 | if use_bazel_diff |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2210 | else expanded_test_targets |
| 2211 | ) |
| 2212 | |
Florian Weikert | dcbbdf3 | 2023-05-02 11:58:53 +0200 | [diff] [blame] | 2213 | if sharding_enabled: |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2214 | print_collapsed_group( |
| 2215 | ":female-detective: Calculating targets for shard {}/{}".format( |
| 2216 | shard_id + 1, shard_count |
| 2217 | ) |
| 2218 | ) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2219 | actual_test_targets = get_targets_for_shard(actual_test_targets, shard_id, shard_count) |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2220 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2221 | return build_targets, actual_test_targets, coverage_targets, index_targets |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2222 | |
| 2223 | |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2224 | def can_use_bazel_diff(): |
| 2225 | matched_files = [] |
| 2226 | for f in get_modified_files(): |
| 2227 | for d in DISABLE_BAZEL_DIFF_IF_MODIFIED: |
| 2228 | if d.endswith("/") and f.startswith(d) or f == d: |
| 2229 | matched_files.append(f) |
| 2230 | |
| 2231 | if matched_files: |
| 2232 | eprint( |
| 2233 | "Cannot enable bazel-diff since the following files were modified:\n\t{}".format( |
| 2234 | "\n\t".join(sorted(matched_files)) |
| 2235 | ) |
| 2236 | ) |
| 2237 | |
| 2238 | return not matched_files |
| 2239 | |
| 2240 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2241 | def expand_test_target_patterns(bazel_binary, test_targets, test_flags): |
| 2242 | if not test_targets: |
| 2243 | return [] |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2244 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2245 | print_collapsed_group(":ninja: Resolving test targets via bazel query") |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 2246 | |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2247 | output = execute_command_and_get_output( |
| 2248 | [bazel_binary] |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2249 | + common_startup_flags() |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2250 | + [ |
Yun Peng | 8e8cdcf | 2022-03-16 13:08:15 +0100 | [diff] [blame] | 2251 | "--nosystem_rc", |
| 2252 | "--nohome_rc", |
Florian Weikert | 5242a59 | 2023-05-04 19:19:28 +0200 | [diff] [blame] | 2253 | "cquery" if os.getenv("EXP_USE_CQUERY") else "query", |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2254 | get_test_query(test_targets, test_flags), |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2255 | ], |
| 2256 | print_output=False, |
Philipp Wollermann | 54719fe | 2021-07-02 21:54:08 +0200 | [diff] [blame] | 2257 | ).strip() |
| 2258 | return output.split("\n") if output else [] |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2259 | |
| 2260 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2261 | def get_test_query(test_targets, test_flags): |
| 2262 | included_targets, excluded_targets = partition_list(test_targets) |
| 2263 | |
| 2264 | def FormatTargetList(targets): |
| 2265 | return " ".join("'{}'".format(t) for t in targets) |
| 2266 | |
Florian Weikert | 38a9921 | 2023-05-04 15:12:41 +0200 | [diff] [blame] | 2267 | query = "let t = tests(set({})) in $t".format(FormatTargetList(included_targets)) |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2268 | |
| 2269 | if excluded_targets: |
| 2270 | query += " except tests(set({}))".format(FormatTargetList(excluded_targets)) |
| 2271 | |
| 2272 | included_tags, excluded_tags = get_test_tags(test_flags) |
| 2273 | |
| 2274 | for t in excluded_tags: |
Florian Weikert | 38a9921 | 2023-05-04 15:12:41 +0200 | [diff] [blame] | 2275 | query += " except attr('tags', '\\b{}\\b', $t)".format(t) |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2276 | |
| 2277 | if included_tags: |
Florian Weikert | 38a9921 | 2023-05-04 15:12:41 +0200 | [diff] [blame] | 2278 | parts = ["attr('tags', '\\b{}\\b', $tt)".format(t) for t in included_tags] |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2279 | query = "let tt = {} in {}".format(query, " union ".join(parts)) |
| 2280 | |
| 2281 | return query |
| 2282 | |
| 2283 | |
| 2284 | def get_test_tags(test_flags): |
| 2285 | wanted_prefix = "--test_tag_filters=" |
| 2286 | |
| 2287 | for f in test_flags: |
| 2288 | if not f.startswith(wanted_prefix): |
| 2289 | continue |
| 2290 | |
Florian Weikert | c833a7c | 2023-05-05 21:26:36 +0200 | [diff] [blame] | 2291 | tags = removeprefix(f, wanted_prefix).split(",") |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2292 | include, exclude = partition_list(tags) |
| 2293 | |
| 2294 | # Skip tests tagged as "manual" by default, unless explicitly requested |
| 2295 | manual_tag = "manual" |
| 2296 | if manual_tag not in include and manual_tag not in exclude: |
| 2297 | exclude.append(manual_tag) |
| 2298 | |
| 2299 | return include, exclude |
| 2300 | |
Yun Peng | 01e617e | 2023-05-04 16:03:46 +0200 | [diff] [blame] | 2301 | return [], ["manual"] |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2302 | |
| 2303 | |
Florian Weikert | c833a7c | 2023-05-05 21:26:36 +0200 | [diff] [blame] | 2304 | def removeprefix(s, prefix): |
| 2305 | def rp(p): |
| 2306 | if s.startswith(p): |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2307 | return s[len(p) :] |
Florian Weikert | c833a7c | 2023-05-05 21:26:36 +0200 | [diff] [blame] | 2308 | return s |
| 2309 | |
| 2310 | func = getattr(s, "removeprefix", rp) |
| 2311 | return func(prefix) |
| 2312 | |
| 2313 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2314 | def filter_unchanged_targets( |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2315 | expanded_test_targets, workspace_dir, ws_setup_func, bazel_binary, diffbase, git_commit |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2316 | ): |
| 2317 | print_collapsed_group( |
| 2318 | f":scissors: Filtering targets that haven't been affected since {diffbase}" |
| 2319 | ) |
| 2320 | |
| 2321 | tmpdir = tempfile.mkdtemp() |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2322 | try: |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2323 | resolved_diffbase = resolve_diffbase(diffbase) |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2324 | eprint(f"Resolved diffbase to {resolved_diffbase}") |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2325 | |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2326 | eprint("Cloning comparison repository...") |
| 2327 | diffbase_archive_url = get_commit_archive_url(resolved_diffbase) |
| 2328 | local_archive_path = download_file(diffbase_archive_url, tmpdir, "repo.tar.gz") |
| 2329 | diffbase_repo_dir = os.path.join(tmpdir, resolved_diffbase) |
| 2330 | extract_archive(local_archive_path, diffbase_repo_dir) |
| 2331 | |
| 2332 | eprint("Setting up comparison repository...") |
| 2333 | os.chdir(diffbase_repo_dir) |
Florian Weikert | 4141ce9 | 2023-05-09 09:45:55 +0200 | [diff] [blame] | 2334 | ws_setup_func(False) |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2335 | |
| 2336 | eprint(f"Downloading bazel-diff to {tmpdir}") |
| 2337 | bazel_diff_path = download_file(BAZEL_DIFF_URL, tmpdir, "bazel-diff.jar") |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2338 | eprint(f"Running bazel-diff for {resolved_diffbase} and {git_commit}") |
| 2339 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2340 | affected_targets = run_bazel_diff( |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2341 | bazel_diff_path, diffbase_repo_dir, workspace_dir, bazel_binary, tmpdir |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2342 | ) |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2343 | except (BuildkiteException, BuildkiteInfraException) as ex: |
| 2344 | try: |
| 2345 | execute_command( |
| 2346 | [ |
| 2347 | "buildkite-agent", |
| 2348 | "annotate", |
| 2349 | "--style=warning", |
| 2350 | "--context", |
| 2351 | "'diff_failed'", |
| 2352 | "This build runs all test targets even though `{}` is set " |
Florian Weikert | 9029ccf | 2023-05-08 17:07:04 +0200 | [diff] [blame] | 2353 | "since bazel-diff failed with an error:\n```\n{}\n```".format( |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2354 | USE_BAZEL_DIFF_ENV_VAR, ex |
| 2355 | ), |
| 2356 | ] |
| 2357 | ) |
Florian Weikert | 77d2006 | 2023-05-08 16:32:48 +0200 | [diff] [blame] | 2358 | execute_command( |
| 2359 | ["buildkite-agent", "annotation", "remove", "--context", BAZEL_DIFF_ANNOTATION_CTX] |
| 2360 | ) |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2361 | finally: |
| 2362 | return expanded_test_targets |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2363 | finally: |
Florian Weikert | e747d4f | 2023-05-09 09:43:47 +0200 | [diff] [blame] | 2364 | try: |
| 2365 | shutil.rmtree(tmpdir) |
| 2366 | except: |
| 2367 | pass |
| 2368 | |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2369 | os.chdir(workspace_dir) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2370 | |
Florian Weikert | aa0488f | 2023-05-03 15:06:13 +0200 | [diff] [blame] | 2371 | config_target_set = set(expanded_test_targets) |
| 2372 | remaining_targets = list(config_target_set.intersection(affected_targets)) |
| 2373 | if len(remaining_targets) < len(expanded_test_targets): |
| 2374 | print_collapsed_group( |
| 2375 | ":scissors: Successfully reduced test targets from {} to {}".format( |
| 2376 | len(expanded_test_targets), len(remaining_targets) |
| 2377 | ) |
| 2378 | ) |
| 2379 | |
| 2380 | skipped_targets = sorted(config_target_set.difference(remaining_targets)) |
| 2381 | eprint("Skipped targets:\n\t{}".format("\n\t".join(skipped_targets))) |
| 2382 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2383 | execute_command( |
| 2384 | [ |
| 2385 | "buildkite-agent", |
| 2386 | "annotate", |
| 2387 | "--style=info", |
Florian Weikert | 20151ab | 2023-05-04 20:32:36 +0200 | [diff] [blame] | 2388 | "--context", |
Florian Weikert | 77d2006 | 2023-05-08 16:32:48 +0200 | [diff] [blame] | 2389 | BAZEL_DIFF_ANNOTATION_CTX, |
Florian Weikert | 76736e9 | 2023-04-28 11:23:27 +0200 | [diff] [blame] | 2390 | "This run only contains test targets that have been changed since " |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2391 | "{} due to the `{}` env variable".format(resolved_diffbase, USE_BAZEL_DIFF_ENV_VAR), |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2392 | ] |
| 2393 | ) |
| 2394 | |
Florian Weikert | aa0488f | 2023-05-03 15:06:13 +0200 | [diff] [blame] | 2395 | return remaining_targets |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2396 | |
| 2397 | |
| 2398 | def resolve_diffbase(diffbase): |
| 2399 | if diffbase in AUTO_DIFFBASE_VALUES: |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2400 | return resolve_revision("HEAD^") |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2401 | elif COMMIT_RE.fullmatch(diffbase): |
| 2402 | return diffbase |
| 2403 | |
| 2404 | raise BuildkiteException( |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2405 | "Invalid value '{}' for `{}` env variable. Must be a Git commit hash or one of {}".format( |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2406 | diffbase, ", ".join(AUTO_DIFFBASE_VALUES) |
| 2407 | ) |
| 2408 | ) |
| 2409 | |
| 2410 | |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2411 | def get_commit_archive_url(resolved_diffbase): |
| 2412 | repo_url = os.getenv("BUILDKITE_REPO", "") |
| 2413 | prefix = "+" if "googlesource" in repo_url else "" |
| 2414 | return repo_url.replace(".git", "/{}archive/{}.tar.gz".format(prefix, resolved_diffbase)) |
| 2415 | |
| 2416 | |
| 2417 | def extract_archive(archive_url, dest_dir): |
| 2418 | if not os.path.isdir(dest_dir): |
| 2419 | os.mkdir(dest_dir) |
| 2420 | |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2421 | try: |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2422 | with tarfile.open(archive_url, mode="r:gz") as archive: |
| 2423 | archive.extractall(dest_dir) |
| 2424 | except tarfile.TarError as ex: |
| 2425 | raise BuildkiteInfraException("Failed to extract repository archive: {}".format(ex)) from ex |
| 2426 | |
| 2427 | |
| 2428 | def download_file(url, dest_dir, dest_filename): |
| 2429 | local_path = os.path.join(dest_dir, dest_filename) |
| 2430 | try: |
Florian Weikert | dfd8db4 | 2023-05-09 15:41:30 +0200 | [diff] [blame] | 2431 | execute_command(["curl", "-sSL", url, "-o", local_path], capture_stderr=True) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2432 | except subprocess.CalledProcessError as ex: |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2433 | raise BuildkiteInfraException("Failed to download {}: {}\n{}".format(url, ex, ex.stderr)) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2434 | return local_path |
| 2435 | |
| 2436 | |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2437 | def run_bazel_diff(bazel_diff_path, old_workspace_dir, new_workspace_dir, bazel_binary, data_dir): |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2438 | before_json = os.path.join(data_dir, "before.json") |
| 2439 | after_json = os.path.join(data_dir, "after.json") |
| 2440 | targets_file = os.path.join(data_dir, "targets.txt") |
| 2441 | |
| 2442 | try: |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2443 | for repo_dir, json_path in ( |
| 2444 | (old_workspace_dir, before_json), |
| 2445 | (new_workspace_dir, after_json), |
| 2446 | ): |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2447 | execute_command( |
| 2448 | [ |
| 2449 | "java", |
| 2450 | "-jar", |
| 2451 | bazel_diff_path, |
| 2452 | "generate-hashes", |
| 2453 | "-w", |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 2454 | repo_dir, |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2455 | "-b", |
| 2456 | bazel_binary, |
| 2457 | json_path, |
Florian Weikert | dfd8db4 | 2023-05-09 15:41:30 +0200 | [diff] [blame] | 2458 | ], |
| 2459 | capture_stderr=True, |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2460 | ) |
| 2461 | |
| 2462 | execute_command( |
| 2463 | [ |
| 2464 | "java", |
| 2465 | "-jar", |
| 2466 | bazel_diff_path, |
| 2467 | "get-impacted-targets", |
| 2468 | "-sh", |
| 2469 | before_json, |
| 2470 | "-fh", |
| 2471 | after_json, |
| 2472 | "-o", |
| 2473 | targets_file, |
Florian Weikert | dfd8db4 | 2023-05-09 15:41:30 +0200 | [diff] [blame] | 2474 | ], |
| 2475 | capture_stderr=True, |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2476 | ) |
| 2477 | except subprocess.CalledProcessError as ex: |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2478 | raise BuildkiteInfraException("Failed to run bazel-diff: {}\n{}".format(ex, ex.stderr)) |
Florian Weikert | ecf091c | 2023-04-28 10:22:23 +0200 | [diff] [blame] | 2479 | |
| 2480 | with open(targets_file, "rt") as f: |
| 2481 | contents = f.read() |
| 2482 | |
| 2483 | return contents.split("\n") |
| 2484 | |
| 2485 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2486 | def partition_list(items): |
| 2487 | included, excluded = [], [] |
| 2488 | for i in items: |
| 2489 | if i.startswith("-"): |
| 2490 | excluded.append(i[1:]) |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2491 | else: |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2492 | included.append(i) |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2493 | |
Florian Weikert | 7dd9f66 | 2023-05-04 15:05:42 +0200 | [diff] [blame] | 2494 | return included, excluded |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2495 | |
| 2496 | |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2497 | def get_targets_for_shard(test_targets, shard_id, shard_count): |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2498 | # TODO(fweikert): implement a more sophisticated algorithm |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2499 | return sorted(test_targets)[shard_id::shard_count] |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2500 | |
| 2501 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2502 | def execute_bazel_test( |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 2503 | bazel_version, |
| 2504 | bazel_binary, |
| 2505 | platform, |
| 2506 | flags, |
| 2507 | targets, |
| 2508 | bep_file, |
| 2509 | monitor_flaky_tests, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2510 | ): |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2511 | aggregated_flags = [ |
| 2512 | "--flaky_test_attempts=3", |
| 2513 | "--build_tests_only", |
Tobias Werth | 08a9383 | 2023-04-25 16:29:52 +0200 | [diff] [blame] | 2514 | "--local_test_jobs=" + concurrent_test_jobs(platform), |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2515 | ] |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2516 | # Don't enable remote caching if the user enabled remote execution / caching themselves |
Jakob Buchgraber | c340f58 | 2018-06-22 13:48:33 +0200 | [diff] [blame] | 2517 | # or flaky test monitoring is enabled, as remote caching makes tests look less flaky than |
| 2518 | # they are. |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 2519 | print_collapsed_group(":bazel: Computing flags for test step") |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2520 | aggregated_flags += compute_flags( |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 2521 | platform, |
| 2522 | flags, |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 2523 | bep_file, |
Philipp Wollermann | 87b4525 | 2020-01-22 12:43:42 +0100 | [diff] [blame] | 2524 | bazel_binary, |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2525 | enable_remote_cache=not monitor_flaky_tests, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2526 | ) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2527 | |
Philipp Wollermann | bda4b7d | 2019-05-16 20:04:17 +0200 | [diff] [blame] | 2528 | print_expanded_group(":bazel: Test ({})".format(bazel_version)) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 2529 | try: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2530 | execute_command( |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2531 | [bazel_binary] |
| 2532 | + bazelisk_flags() |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2533 | + common_startup_flags() |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2534 | + ["test"] |
| 2535 | + aggregated_flags |
Philipp Wollermann | 2a16043 | 2019-09-19 15:57:28 +0200 | [diff] [blame] | 2536 | + ["--"] |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2537 | + targets |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2538 | ) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 2539 | except subprocess.CalledProcessError as e: |
Yun Peng | 0a6a98a | 2019-03-06 13:07:54 +0100 | [diff] [blame] | 2540 | handle_bazel_failure(e, "test") |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2541 | |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 2542 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2543 | def execute_bazel_coverage(bazel_version, bazel_binary, platform, flags, targets): |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 2544 | aggregated_flags = [ |
| 2545 | "--build_tests_only", |
Tobias Werth | 08a9383 | 2023-04-25 16:29:52 +0200 | [diff] [blame] | 2546 | "--local_test_jobs=" + concurrent_test_jobs(platform), |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 2547 | ] |
| 2548 | print_collapsed_group(":bazel: Computing flags for coverage step") |
| 2549 | aggregated_flags += compute_flags( |
| 2550 | platform, |
| 2551 | flags, |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 2552 | None, |
| 2553 | bazel_binary, |
| 2554 | enable_remote_cache=True, |
| 2555 | ) |
| 2556 | |
| 2557 | print_expanded_group(":bazel: Coverage ({})".format(bazel_version)) |
| 2558 | try: |
| 2559 | execute_command( |
| 2560 | [bazel_binary] |
| 2561 | + bazelisk_flags() |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2562 | + common_startup_flags() |
Xavier Bonaventura | 3755ea0 | 2022-02-02 13:56:54 +0100 | [diff] [blame] | 2563 | + ["coverage"] |
| 2564 | + aggregated_flags |
| 2565 | + ["--"] |
| 2566 | + targets |
| 2567 | ) |
| 2568 | except subprocess.CalledProcessError as e: |
| 2569 | handle_bazel_failure(e, "coverage") |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2570 | |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 2571 | |
Florian Weikert | da94a10 | 2022-10-21 12:24:37 +0200 | [diff] [blame] | 2572 | def upload_test_logs_from_bep(bep_file, tmpdir, monitor_flaky_tests): |
Chi Wang | d61eb97 | 2023-01-18 11:36:18 +0100 | [diff] [blame] | 2573 | bazelci_agent_binary = download_bazelci_agent(tmpdir) |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 2574 | execute_command( |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 2575 | [ |
| 2576 | bazelci_agent_binary, |
| 2577 | "artifact", |
| 2578 | "upload", |
| 2579 | "--delay=5", |
| 2580 | "--mode=buildkite", |
| 2581 | "--build_event_json_file={}".format(bep_file), |
| 2582 | ] |
Chi Wang | d279d58 | 2021-09-29 10:59:06 +0800 | [diff] [blame] | 2583 | + (["--monitor_flaky_tests"] if monitor_flaky_tests else []) |
| 2584 | ) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2585 | |
Philipp Wollermann | 3c8b851 | 2019-07-16 15:28:03 +0200 | [diff] [blame] | 2586 | |
joeleba | 7688795 | 2019-05-16 15:22:17 +0200 | [diff] [blame] | 2587 | def upload_json_profile(json_profile_path, tmpdir): |
| 2588 | if not os.path.exists(json_profile_path): |
| 2589 | return |
| 2590 | print_collapsed_group(":gcloud: Uploading JSON Profile") |
Philipp Wollermann | 92cf51e | 2019-05-16 15:31:11 +0200 | [diff] [blame] | 2591 | execute_command(["buildkite-agent", "artifact", "upload", json_profile_path], cwd=tmpdir) |
joeleba | 7688795 | 2019-05-16 15:22:17 +0200 | [diff] [blame] | 2592 | |
Philipp Wollermann | f436e74 | 2021-08-11 11:06:55 +0200 | [diff] [blame] | 2593 | |
Chi Wang | 54595a2 | 2021-06-11 17:49:58 +0800 | [diff] [blame] | 2594 | def upload_corrupted_outputs(capture_corrupted_outputs_dir, tmpdir): |
| 2595 | if not os.path.exists(capture_corrupted_outputs_dir): |
| 2596 | return |
| 2597 | print_collapsed_group(":gcloud: Uploading corrupted outputs") |
Philipp Wollermann | f436e74 | 2021-08-11 11:06:55 +0200 | [diff] [blame] | 2598 | execute_command( |
| 2599 | ["buildkite-agent", "artifact", "upload", "{}/**/*".format(capture_corrupted_outputs_dir)], |
| 2600 | cwd=tmpdir, |
| 2601 | ) |
| 2602 | |
Philipp Wollermann | 5b00a70 | 2019-07-18 11:21:38 +0200 | [diff] [blame] | 2603 | |
Philipp Wollermann | af35abf | 2019-05-22 17:52:01 +0200 | [diff] [blame] | 2604 | def execute_command_and_get_output(args, shell=False, fail_if_nonzero=True, print_output=True): |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 2605 | eprint(" ".join(args)) |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 2606 | process = subprocess.run( |
| 2607 | args, |
| 2608 | shell=shell, |
| 2609 | check=fail_if_nonzero, |
| 2610 | env=os.environ, |
Florian Weikert | 9029ccf | 2023-05-08 17:07:04 +0200 | [diff] [blame] | 2611 | stdout=subprocess.PIPE, # We cannot use capture_output since some workers run Python <3.7 |
Philipp Wollermann | f13804b | 2019-02-05 21:08:30 +0100 | [diff] [blame] | 2612 | errors="replace", |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 2613 | universal_newlines=True, |
| 2614 | ) |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2615 | if print_output: |
| 2616 | eprint(process.stdout) |
| 2617 | |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 2618 | return process.stdout |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2619 | |
| 2620 | |
Florian Weikert | dfd8db4 | 2023-05-09 15:41:30 +0200 | [diff] [blame] | 2621 | def execute_command( |
| 2622 | args, shell=False, fail_if_nonzero=True, cwd=None, print_output=True, capture_stderr=False |
| 2623 | ): |
Yun Peng | 9337bb3 | 2020-02-28 13:31:29 +0100 | [diff] [blame] | 2624 | if print_output: |
| 2625 | eprint(" ".join(args)) |
Philipp Wollermann | 92cf51e | 2019-05-16 15:31:11 +0200 | [diff] [blame] | 2626 | return subprocess.run( |
Florian Weikert | b0fcf90 | 2023-05-05 22:01:50 +0200 | [diff] [blame] | 2627 | args, |
| 2628 | shell=shell, |
| 2629 | check=fail_if_nonzero, |
| 2630 | env=os.environ, |
| 2631 | cwd=cwd, |
| 2632 | errors="replace", |
Florian Weikert | dfd8db4 | 2023-05-09 15:41:30 +0200 | [diff] [blame] | 2633 | stderr=subprocess.PIPE |
| 2634 | if capture_stderr |
| 2635 | else None, # capture_stderr=True when we want exceptions to contain stderr |
Philipp Wollermann | 92cf51e | 2019-05-16 15:31:11 +0200 | [diff] [blame] | 2636 | ).returncode |
Philipp Wollermann | f13804b | 2019-02-05 21:08:30 +0100 | [diff] [blame] | 2637 | |
| 2638 | |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 2639 | def execute_command_background(args): |
| 2640 | eprint(" ".join(args)) |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 2641 | return subprocess.Popen(args, env=os.environ) |
| 2642 | |
Philipp Wollermann | 3c8b851 | 2019-07-16 15:28:03 +0200 | [diff] [blame] | 2643 | |
Jakob Buchgraber | 2b63a7f | 2019-07-16 15:27:34 +0200 | [diff] [blame] | 2644 | def terminate_background_process(process): |
| 2645 | if process: |
| 2646 | process.terminate() |
| 2647 | try: |
| 2648 | process.wait(timeout=10) |
| 2649 | except subprocess.TimeoutExpired: |
| 2650 | process.kill() |
Philipp Wollermann | e1318eb | 2018-08-13 15:08:01 +0200 | [diff] [blame] | 2651 | |
Philipp Wollermann | 3c8b851 | 2019-07-16 15:28:03 +0200 | [diff] [blame] | 2652 | |
mai93 | b49bad7 | 2021-05-06 00:50:34 +0200 | [diff] [blame] | 2653 | def create_step(label, commands, platform, shards=1, soft_fail=None): |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 2654 | if "docker-image" in PLATFORMS[platform]: |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2655 | step = create_docker_step( |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2656 | label, |
| 2657 | image=PLATFORMS[platform]["docker-image"], |
| 2658 | commands=commands, |
| 2659 | queue=PLATFORMS[platform].get("queue", "default"), |
| 2660 | always_pull=PLATFORMS[platform].get("always-pull", True), |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 2661 | ) |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 2662 | else: |
Philipp Wollermann | f3750fa | 2019-05-21 17:11:59 +0200 | [diff] [blame] | 2663 | step = { |
| 2664 | "label": label, |
| 2665 | "command": commands, |
| 2666 | "agents": {"queue": PLATFORMS[platform]["queue"]}, |
| 2667 | } |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 2668 | |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2669 | if shards > 1: |
| 2670 | step["label"] += " (shard %n)" |
| 2671 | step["parallelism"] = shards |
| 2672 | |
mai93 | b49bad7 | 2021-05-06 00:50:34 +0200 | [diff] [blame] | 2673 | if soft_fail is not None: |
| 2674 | step["soft_fail"] = soft_fail |
| 2675 | |
Philipp Wollermann | 5b2f3fc | 2019-05-18 22:36:17 +0200 | [diff] [blame] | 2676 | # Enforce a global 8 hour job timeout. |
| 2677 | step["timeout_in_minutes"] = 8 * 60 |
| 2678 | |
| 2679 | # Automatically retry when an agent got lost (usually due to an infra flake). |
Philipp Wollermann | f22bba3 | 2019-07-18 11:22:50 +0200 | [diff] [blame] | 2680 | step["retry"] = { |
| 2681 | "automatic": [ |
| 2682 | {"exit_status": -1, "limit": 3}, # Buildkite internal "agent lost" exit code |
| 2683 | {"exit_status": 137, "limit": 3}, # SIGKILL |
| 2684 | {"exit_status": 143, "limit": 3}, # SIGTERM |
| 2685 | ] |
| 2686 | } |
Philipp Wollermann | 5b2f3fc | 2019-05-18 22:36:17 +0200 | [diff] [blame] | 2687 | |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2688 | return step |
| 2689 | |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 2690 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2691 | def create_docker_step( |
| 2692 | label, image, commands=None, additional_env_vars=None, queue="default", always_pull=True |
| 2693 | ): |
Philipp Wollermann | 0e051dd | 2019-05-16 11:37:52 +0200 | [diff] [blame] | 2694 | env = ["ANDROID_HOME", "ANDROID_NDK_HOME", "BUILDKITE_ARTIFACT_UPLOAD_DESTINATION"] |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2695 | if additional_env_vars: |
| 2696 | env += ["{}={}".format(k, v) for k, v in additional_env_vars.items()] |
| 2697 | |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 2698 | step = { |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2699 | "label": label, |
| 2700 | "command": commands, |
Yun Peng | 07dafc5 | 2022-03-16 13:23:35 +0100 | [diff] [blame] | 2701 | "agents": {"queue": queue}, |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2702 | "plugins": { |
Philipp Wollermann | 9fa0354 | 2021-07-01 23:27:53 +0200 | [diff] [blame] | 2703 | "docker#v3.8.0": { |
Yun Peng | 07dafc5 | 2022-03-16 13:23:35 +0100 | [diff] [blame] | 2704 | "always-pull": always_pull, |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2705 | "environment": env, |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 2706 | "image": image, |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2707 | "network": "host", |
| 2708 | "privileged": True, |
| 2709 | "propagate-environment": True, |
Philipp Wollermann | 7aa9549 | 2019-05-18 22:03:24 +0200 | [diff] [blame] | 2710 | "propagate-uid-gid": True, |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2711 | "volumes": [ |
Philipp Wollermann | 7aa9549 | 2019-05-18 22:03:24 +0200 | [diff] [blame] | 2712 | "/etc/group:/etc/group:ro", |
| 2713 | "/etc/passwd:/etc/passwd:ro", |
Philipp Wollermann | 3dc99b3 | 2021-10-12 00:34:30 +0200 | [diff] [blame] | 2714 | "/etc/shadow:/etc/shadow:ro", |
Philipp Wollermann | 562ef1d | 2021-10-20 22:15:29 +0200 | [diff] [blame] | 2715 | "/opt/android-ndk-r15c:/opt/android-ndk-r15c:ro", |
Yun Peng | 7287421 | 2022-09-13 19:08:03 +0200 | [diff] [blame] | 2716 | "/opt/android-ndk-r25b:/opt/android-ndk-r25b:ro", |
Philipp Wollermann | 562ef1d | 2021-10-20 22:15:29 +0200 | [diff] [blame] | 2717 | "/opt/android-sdk-linux:/opt/android-sdk-linux:ro", |
Philipp Wollermann | 7aa9549 | 2019-05-18 22:03:24 +0200 | [diff] [blame] | 2718 | "/var/lib/buildkite-agent:/var/lib/buildkite-agent", |
Philipp Wollermann | 338db4a | 2019-05-18 11:21:04 +0200 | [diff] [blame] | 2719 | "/var/lib/gitmirrors:/var/lib/gitmirrors:ro", |
Philipp Wollermann | a65944a | 2020-02-03 12:45:22 +0100 | [diff] [blame] | 2720 | "/var/run/docker.sock:/var/run/docker.sock", |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2721 | ], |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2722 | } |
| 2723 | }, |
| 2724 | } |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 2725 | if not step["command"]: |
| 2726 | del step["command"] |
| 2727 | return step |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2728 | |
| 2729 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2730 | def print_project_pipeline( |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 2731 | configs, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2732 | project_name, |
| 2733 | http_config, |
| 2734 | file_config, |
| 2735 | git_repository, |
| 2736 | monitor_flaky_tests, |
| 2737 | use_but, |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 2738 | notify, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2739 | ): |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 2740 | task_configs = configs.get("tasks", None) |
| 2741 | if not task_configs: |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 2742 | raise BuildkiteException("{0} pipeline configuration is empty.".format(project_name)) |
| 2743 | |
Jakob Buchgraber | aa2af38 | 2018-02-21 19:56:54 +0100 | [diff] [blame] | 2744 | pipeline_steps = [] |
mai93 | f2e116c | 2020-10-19 09:33:14 +0200 | [diff] [blame] | 2745 | # If the repository is hosted on Git-on-borg, we show the link to the commit Gerrit review |
| 2746 | buildkite_repo = os.getenv("BUILDKITE_REPO") |
| 2747 | if is_git_on_borg_repo(buildkite_repo): |
| 2748 | show_gerrit_review_link(buildkite_repo, pipeline_steps) |
| 2749 | |
Florian Weikert | 5f5d3cb | 2019-04-15 15:36:27 +0200 | [diff] [blame] | 2750 | task_configs = filter_tasks_that_should_be_skipped(task_configs, pipeline_steps) |
Jakob Buchgraber | ff2bdad | 2018-02-25 13:06:30 +0100 | [diff] [blame] | 2751 | |
Philipp Wollermann | dac6551 | 2019-02-05 22:14:10 +0100 | [diff] [blame] | 2752 | # In Bazel Downstream Project pipelines, git_repository and project_name must be specified. |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 2753 | is_downstream_project = use_but and git_repository and project_name |
Philipp Wollermann | dac6551 | 2019-02-05 22:14:10 +0100 | [diff] [blame] | 2754 | |
Florian Weikert | 8520891 | 2019-03-07 17:08:39 +0100 | [diff] [blame] | 2755 | buildifier_config = configs.get("buildifier") |
Philipp Wollermann | dac6551 | 2019-02-05 22:14:10 +0100 | [diff] [blame] | 2756 | # Skip Buildifier when we test downstream projects. |
Florian Weikert | 8520891 | 2019-03-07 17:08:39 +0100 | [diff] [blame] | 2757 | if buildifier_config and not is_downstream_project: |
| 2758 | buildifier_env_vars = {} |
| 2759 | if isinstance(buildifier_config, str): |
| 2760 | # Simple format: |
| 2761 | # --- |
| 2762 | # buildifier: latest |
Philipp Wollermann | 22538e7 | 2021-10-02 09:43:28 +0200 | [diff] [blame] | 2763 | buildifier_env_vars["BUILDIFIER_VERSION"] = buildifier_config |
Florian Weikert | 8520891 | 2019-03-07 17:08:39 +0100 | [diff] [blame] | 2764 | else: |
| 2765 | # Advanced format: |
| 2766 | # --- |
| 2767 | # buildifier: |
| 2768 | # version: latest |
| 2769 | # warnings: all |
Philipp Wollermann | 22538e7 | 2021-10-02 09:43:28 +0200 | [diff] [blame] | 2770 | if "version" in buildifier_config: |
| 2771 | buildifier_env_vars["BUILDIFIER_VERSION"] = buildifier_config["version"] |
| 2772 | if "warnings" in buildifier_config: |
| 2773 | buildifier_env_vars["BUILDIFIER_WARNINGS"] = buildifier_config["warnings"] |
Florian Weikert | 8520891 | 2019-03-07 17:08:39 +0100 | [diff] [blame] | 2774 | |
| 2775 | if not buildifier_env_vars: |
| 2776 | raise BuildkiteException( |
| 2777 | 'Invalid buildifier configuration entry "{}"'.format(buildifier_config) |
| 2778 | ) |
| 2779 | |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2780 | pipeline_steps.append( |
| 2781 | create_docker_step( |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 2782 | BUILDIFIER_STEP_NAME, |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2783 | image=BUILDIFIER_DOCKER_IMAGE, |
Florian Weikert | 8520891 | 2019-03-07 17:08:39 +0100 | [diff] [blame] | 2784 | additional_env_vars=buildifier_env_vars, |
Florian Weikert | 29cb7ec | 2019-03-07 14:52:18 +0100 | [diff] [blame] | 2785 | ) |
| 2786 | ) |
Philipp Wollermann | c05ac68 | 2019-01-19 12:37:28 +0100 | [diff] [blame] | 2787 | |
Philipp Wollermann | dac6551 | 2019-02-05 22:14:10 +0100 | [diff] [blame] | 2788 | # In Bazel Downstream Project pipelines, we should test the project at the last green commit. |
Yun Peng | 376d2b3 | 2018-11-29 10:24:54 +0100 | [diff] [blame] | 2789 | git_commit = None |
Philipp Wollermann | dac6551 | 2019-02-05 22:14:10 +0100 | [diff] [blame] | 2790 | if is_downstream_project: |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 2791 | last_green_commit_url = bazelci_last_green_commit_url( |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2792 | git_repository, DOWNSTREAM_PROJECTS[project_name]["pipeline_slug"] |
| 2793 | ) |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 2794 | git_commit = get_last_green_commit(last_green_commit_url) |
Philipp Wollermann | dac6551 | 2019-02-05 22:14:10 +0100 | [diff] [blame] | 2795 | |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2796 | config_hashes = set() |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2797 | skipped_downstream_tasks = [] |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 2798 | for task, task_config in task_configs.items(): |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2799 | platform = get_platform_for_task(task, task_config) |
| 2800 | task_name = task_config.get("name") |
mai93 | b49bad7 | 2021-05-06 00:50:34 +0200 | [diff] [blame] | 2801 | soft_fail = task_config.get("soft_fail") |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2802 | |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2803 | # We override the Bazel version in downstream pipelines. This means that two tasks that |
| 2804 | # only differ in the value of their explicit "bazel" field will be identical in the |
| 2805 | # downstream pipeline, thus leading to duplicate work. |
| 2806 | # Consequently, we filter those duplicate tasks here. |
| 2807 | if is_downstream_project: |
| 2808 | h = hash_task_config(task, task_config) |
| 2809 | if h in config_hashes: |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2810 | skipped_downstream_tasks.append( |
Yun Peng | 9d905fb | 2023-04-24 14:13:26 +0200 | [diff] [blame] | 2811 | "{}: {}".format( |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2812 | create_label(platform, project_name, task_name=task_name), |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2813 | "The same task already exists after ignoring bazel version.", |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2814 | ) |
| 2815 | ) |
Florian Weikert | 11d3143 | 2023-02-27 11:33:23 +0100 | [diff] [blame] | 2816 | continue |
| 2817 | |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2818 | config_hashes.add(h) |
| 2819 | |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2820 | # Skip tasks with `skip_in_bazel_downstream_pipeline` specified. |
| 2821 | skipped_reason = task_config.get("skip_in_bazel_downstream_pipeline", "") |
| 2822 | if skipped_reason: |
| 2823 | skipped_downstream_tasks.append( |
Yun Peng | 9d905fb | 2023-04-24 14:13:26 +0200 | [diff] [blame] | 2824 | "{}: {}".format( |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2825 | create_label(platform, project_name, task_name=task_name), |
| 2826 | skipped_reason, |
| 2827 | ) |
| 2828 | ) |
| 2829 | continue |
| 2830 | |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2831 | shards = task_config.get("shards", "1") |
| 2832 | try: |
| 2833 | shards = int(shards) |
| 2834 | except ValueError: |
| 2835 | raise BuildkiteException("Task {} has invalid shard value '{}'".format(task, shards)) |
| 2836 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2837 | step = runner_step( |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2838 | platform=platform, |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 2839 | task=task, |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2840 | task_name=task_name, |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 2841 | project_name=project_name, |
| 2842 | http_config=http_config, |
| 2843 | file_config=file_config, |
| 2844 | git_repository=git_repository, |
| 2845 | git_commit=git_commit, |
| 2846 | monitor_flaky_tests=monitor_flaky_tests, |
| 2847 | use_but=use_but, |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 2848 | shards=shards, |
mai93 | b49bad7 | 2021-05-06 00:50:34 +0200 | [diff] [blame] | 2849 | soft_fail=soft_fail, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2850 | ) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 2851 | pipeline_steps.append(step) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2852 | |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2853 | if skipped_downstream_tasks: |
| 2854 | lines = ["\n- {}".format(s) for s in skipped_downstream_tasks] |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2855 | commands = [ |
Yun Peng | ee01087 | 2023-04-24 14:48:19 +0200 | [diff] [blame] | 2856 | "buildkite-agent meta-data exists 'has-skipped-annotation' || buildkite-agent annotate --style=info 'The following tasks were skipped:\n' --context 'ctx-skipped_downstream_tasks'", |
| 2857 | "buildkite-agent meta-data set 'has-skipped-annotation' 'true'", |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2858 | "buildkite-agent annotate --style=info '{}' --append --context 'ctx-skipped_downstream_tasks'".format( |
Xùdōng Yáng | 045c981 | 2021-08-18 01:42:35 +1000 | [diff] [blame] | 2859 | "".join(lines) |
| 2860 | ), |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2861 | ] |
| 2862 | pipeline_steps.append( |
| 2863 | create_step( |
Yun Peng | e6b0990 | 2023-03-31 17:15:58 +0200 | [diff] [blame] | 2864 | label=":pipeline: Print information about skipped tasks", |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2865 | commands=commands, |
| 2866 | platform=DEFAULT_PLATFORM, |
| 2867 | ) |
| 2868 | ) |
| 2869 | |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 2870 | pipeline_slug = os.getenv("BUILDKITE_PIPELINE_SLUG") |
| 2871 | all_downstream_pipeline_slugs = [] |
| 2872 | for _, config in DOWNSTREAM_PROJECTS.items(): |
| 2873 | all_downstream_pipeline_slugs.append(config["pipeline_slug"]) |
Ivo List | 23ce48d | 2020-11-18 13:15:34 +0100 | [diff] [blame] | 2874 | # We update last green commit in the following cases: |
| 2875 | # 1. This job runs on master, stable or main branch (could be a custom build launched manually) |
| 2876 | # 2. We intend to run the same job in downstream with Bazel@HEAD (eg. google-bazel-presubmit) |
| 2877 | # 3. This job is not: |
| 2878 | # - a GitHub pull request |
| 2879 | # - uses a custom built Bazel binary (in Bazel Downstream Projects pipeline) |
| 2880 | # - testing incompatible flags |
| 2881 | # - running `bazelisk --migrate` in a non-downstream pipeline |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2882 | if ( |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 2883 | current_branch_is_main_branch() |
Ivo List | 23ce48d | 2020-11-18 13:15:34 +0100 | [diff] [blame] | 2884 | and pipeline_slug in all_downstream_pipeline_slugs |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 2885 | and not (is_pull_request() or use_but or use_bazelisk_migrate()) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2886 | ): |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 2887 | # We need to call "Try Update Last Green Commit" even if there are failures, |
| 2888 | # since we don't want a failing Buildifier step to block the update of |
| 2889 | # the last green commit for this project. |
| 2890 | # try_update_last_green_commit() ensures that we don't update the commit |
| 2891 | # if any build or test steps fail. |
| 2892 | pipeline_steps.append({"wait": None, "continue_on_failure": True}) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2893 | pipeline_steps.append( |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 2894 | create_step( |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 2895 | label="Try Update Last Green Commit", |
| 2896 | commands=[ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2897 | fetch_bazelcipy_command(), |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 2898 | PLATFORMS[DEFAULT_PLATFORM]["python"] |
| 2899 | + " bazelci.py try_update_last_green_commit", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2900 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 2901 | platform=DEFAULT_PLATFORM, |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 2902 | ) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2903 | ) |
Yun Peng | 43239b0 | 2018-11-23 13:57:34 +0100 | [diff] [blame] | 2904 | |
Florian Weikert | 778251c | 2019-04-25 15:14:44 +0200 | [diff] [blame] | 2905 | if "validate_config" in configs: |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2906 | pipeline_steps += create_config_validation_steps() |
Florian Weikert | 778251c | 2019-04-25 15:14:44 +0200 | [diff] [blame] | 2907 | |
Florian Weikert | 09813a0 | 2019-10-26 19:34:33 +0200 | [diff] [blame] | 2908 | if use_bazelisk_migrate() and not is_downstream_project: |
| 2909 | # Print results of bazelisk --migrate in project pipelines that explicitly set |
| 2910 | # the USE_BAZELISK_MIGRATE env var, but that are not being run as part of a |
| 2911 | # downstream pipeline. |
| 2912 | number = os.getenv("BUILDKITE_BUILD_NUMBER") |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 2913 | pipeline_steps += get_steps_for_aggregating_migration_results(number, notify) |
Florian Weikert | 09813a0 | 2019-10-26 19:34:33 +0200 | [diff] [blame] | 2914 | |
Florian Weikert | d79dc50 | 2019-05-13 09:51:05 +0200 | [diff] [blame] | 2915 | print_pipeline_steps(pipeline_steps, handle_emergencies=not is_downstream_project) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 2916 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 2917 | |
mai93 | f2e116c | 2020-10-19 09:33:14 +0200 | [diff] [blame] | 2918 | def show_gerrit_review_link(git_repository, pipeline_steps): |
| 2919 | host = re.search(r"https://(.+?)\.googlesource", git_repository).group(1) |
| 2920 | if not host: |
| 2921 | raise BuildkiteException("Couldn't get host name from %s" % git_repository) |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 2922 | text = "The transformed code used in this pipeline can be found under https://{}-review.googlesource.com/q/{}".format( |
| 2923 | host, os.getenv("BUILDKITE_COMMIT") |
| 2924 | ) |
Florian Weikert | c6cc617 | 2023-05-04 20:20:55 +0200 | [diff] [blame] | 2925 | commands = ["buildkite-agent annotate --style=info --context 'gerrit' '{}'".format(text)] |
mai93 | f2e116c | 2020-10-19 09:33:14 +0200 | [diff] [blame] | 2926 | pipeline_steps.append( |
| 2927 | create_step( |
| 2928 | label=":pipeline: Print information about Gerrit Review Link", |
| 2929 | commands=commands, |
| 2930 | platform=DEFAULT_PLATFORM, |
| 2931 | ) |
| 2932 | ) |
| 2933 | |
| 2934 | |
| 2935 | def is_git_on_borg_repo(git_repository): |
| 2936 | return git_repository and "googlesource.com" in git_repository |
| 2937 | |
| 2938 | |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2939 | def hash_task_config(task_name, task_config): |
| 2940 | # Two task configs c1 and c2 have the same hash iff they lead to two functionally identical jobs |
| 2941 | # in the downstream pipeline. This function discards the "bazel" field (since it's being |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 2942 | # overridden) and the "name" field (since it has no effect on the actual work). |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2943 | # Moreover, it adds an explicit "platform" field if that's missing. |
| 2944 | cpy = task_config.copy() |
| 2945 | cpy.pop("bazel", None) |
| 2946 | cpy.pop("name", None) |
| 2947 | if "platform" not in cpy: |
| 2948 | cpy["platform"] = task_name |
| 2949 | |
| 2950 | m = hashlib.md5() |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 2951 | # Technically we should sort cpy[key] if it's a list of entries |
| 2952 | # whose order does not matter (e.g. targets). |
| 2953 | # However, this seems to be overkill for the current use cases. |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2954 | for key in sorted(cpy): |
Florian Weikert | 8186c39 | 2019-06-05 12:53:39 +0200 | [diff] [blame] | 2955 | value = "%s:%s;" % (key, cpy[key]) |
| 2956 | m.update(value.encode("utf-8")) |
Florian Weikert | 854fd85 | 2019-06-04 16:44:19 +0200 | [diff] [blame] | 2957 | |
| 2958 | return m.digest() |
| 2959 | |
| 2960 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 2961 | def get_platform_for_task(task, task_config): |
| 2962 | # Most pipeline configurations have exactly one task per platform, which makes it |
| 2963 | # convenient to use the platform name as task ID. Consequently, we use the |
| 2964 | # task ID as platform if there is no explicit "platform" field. |
| 2965 | return task_config.get("platform", task) |
| 2966 | |
| 2967 | |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2968 | def create_config_validation_steps(): |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2969 | config_files = [ |
Philipp Wollermann | 67225ec | 2021-08-11 11:12:51 +0200 | [diff] [blame] | 2970 | path |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2971 | for path in get_modified_files() |
Philipp Wollermann | 67225ec | 2021-08-11 11:12:51 +0200 | [diff] [blame] | 2972 | if path.startswith(".bazelci/") and os.path.splitext(path)[1] in CONFIG_FILE_EXTENSIONS |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2973 | ] |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2974 | return [ |
| 2975 | create_step( |
| 2976 | label=":cop: Validate {}".format(f), |
| 2977 | commands=[ |
| 2978 | fetch_bazelcipy_command(), |
| 2979 | "{} bazelci.py project_pipeline --file_config={}".format( |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 2980 | PLATFORMS[DEFAULT_PLATFORM]["python"], f |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2981 | ), |
| 2982 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 2983 | platform=DEFAULT_PLATFORM, |
Florian Weikert | f52f91a | 2019-05-08 15:19:30 +0200 | [diff] [blame] | 2984 | ) |
| 2985 | for f in config_files |
| 2986 | ] |
| 2987 | |
| 2988 | |
Florian Weikert | e417f9f | 2023-05-05 17:33:46 +0200 | [diff] [blame] | 2989 | def get_modified_files(): |
| 2990 | output = execute_command_and_get_output( |
| 2991 | ["git", "diff-tree", "--no-commit-id", "--name-only", "-r", os.getenv("BUILDKITE_COMMIT")] |
| 2992 | ) |
| 2993 | return output.split("\n") |
| 2994 | |
| 2995 | |
Florian Weikert | d79dc50 | 2019-05-13 09:51:05 +0200 | [diff] [blame] | 2996 | def print_pipeline_steps(pipeline_steps, handle_emergencies=True): |
| 2997 | if handle_emergencies: |
| 2998 | emergency_step = create_emergency_announcement_step_if_necessary() |
| 2999 | if emergency_step: |
| 3000 | pipeline_steps.insert(0, emergency_step) |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 3001 | |
| 3002 | print(yaml.dump({"steps": pipeline_steps})) |
| 3003 | |
| 3004 | |
| 3005 | def create_emergency_announcement_step_if_necessary(): |
| 3006 | style = "error" |
| 3007 | message, issue_url, last_good_bazel = None, None, None |
| 3008 | try: |
| 3009 | emergency_settings = load_remote_yaml_file(EMERGENCY_FILE_URL) |
| 3010 | message = emergency_settings.get("message") |
| 3011 | issue_url = emergency_settings.get("issue_url") |
| 3012 | last_good_bazel = emergency_settings.get("last_good_bazel") |
| 3013 | except urllib.error.HTTPError as ex: |
| 3014 | message = str(ex) |
| 3015 | style = "warning" |
| 3016 | |
| 3017 | if not any([message, issue_url, last_good_bazel]): |
| 3018 | return |
| 3019 | |
| 3020 | text = '<span class="h1">:rotating_light: Emergency :rotating_light:</span>\n' |
| 3021 | if message: |
| 3022 | text += "- {}\n".format(message) |
| 3023 | if issue_url: |
| 3024 | text += '- Please check this <a href="{}">issue</a> for more details.\n'.format(issue_url) |
| 3025 | if last_good_bazel: |
| 3026 | text += ( |
| 3027 | "- Default Bazel version is *{}*, " |
| 3028 | "unless the pipeline configuration specifies an explicit version." |
| 3029 | ).format(last_good_bazel) |
| 3030 | |
| 3031 | return create_step( |
| 3032 | label=":rotating_light: Emergency :rotating_light:", |
Philipp Wollermann | 7590b96 | 2019-05-16 11:35:03 +0200 | [diff] [blame] | 3033 | commands=[ |
| 3034 | 'buildkite-agent annotate --append --style={} --context "omg" "{}"'.format(style, text) |
| 3035 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3036 | platform=DEFAULT_PLATFORM, |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 3037 | ) |
| 3038 | |
| 3039 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3040 | def runner_step( |
| 3041 | platform, |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3042 | task, |
| 3043 | task_name=None, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3044 | project_name=None, |
| 3045 | http_config=None, |
| 3046 | file_config=None, |
| 3047 | git_repository=None, |
| 3048 | git_commit=None, |
| 3049 | monitor_flaky_tests=False, |
| 3050 | use_but=False, |
Florian Weikert | 736d06e | 2019-05-08 13:16:42 +0200 | [diff] [blame] | 3051 | shards=1, |
mai93 | b49bad7 | 2021-05-06 00:50:34 +0200 | [diff] [blame] | 3052 | soft_fail=None, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3053 | ): |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 3054 | command = PLATFORMS[platform]["python"] + " bazelci.py runner --task=" + task |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3055 | if http_config: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3056 | command += " --http_config=" + http_config |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3057 | if file_config: |
| 3058 | command += " --file_config=" + file_config |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3059 | if git_repository: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3060 | command += " --git_repository=" + git_repository |
Yun Peng | 376d2b3 | 2018-11-29 10:24:54 +0100 | [diff] [blame] | 3061 | if git_commit: |
| 3062 | command += " --git_commit=" + git_commit |
Jakob Buchgraber | c340f58 | 2018-06-22 13:48:33 +0200 | [diff] [blame] | 3063 | if monitor_flaky_tests: |
| 3064 | command += " --monitor_flaky_tests" |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3065 | if use_but: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3066 | command += " --use_but" |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3067 | label = create_label(platform, project_name, task_name=task_name) |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 3068 | return create_step( |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 3069 | label=label, |
| 3070 | commands=[fetch_bazelcipy_command(), command], |
| 3071 | platform=platform, |
| 3072 | shards=shards, |
| 3073 | soft_fail=soft_fail, |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 3074 | ) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3075 | |
| 3076 | |
| 3077 | def fetch_bazelcipy_command(): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3078 | return "curl -sS {0} -o bazelci.py".format(SCRIPT_URL) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3079 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3080 | |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 3081 | def fetch_aggregate_incompatible_flags_test_result_command(): |
| 3082 | return "curl -sS {0} -o aggregate_incompatible_flags_test_result.py".format( |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3083 | AGGREGATE_INCOMPATIBLE_TEST_RESULT_URL |
Yun Peng | 8975c6b | 2019-02-28 11:55:55 +0100 | [diff] [blame] | 3084 | ) |
| 3085 | |
| 3086 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 3087 | def upload_project_pipeline_step(project_name, git_repository, http_config, file_config): |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3088 | pipeline_command = ( |
| 3089 | '{0} bazelci.py project_pipeline --project_name="{1}" ' + "--git_repository={2}" |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 3090 | ).format(PLATFORMS[DEFAULT_PLATFORM]["python"], project_name, git_repository) |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3091 | pipeline_command += " --use_but" |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3092 | if http_config: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3093 | pipeline_command += " --http_config=" + http_config |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3094 | if file_config: |
| 3095 | pipeline_command += " --file_config=" + file_config |
Chi Wang | f1f2036 | 2022-02-01 13:44:45 +0100 | [diff] [blame] | 3096 | pipeline_command += " | tee /dev/tty | buildkite-agent pipeline upload" |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3097 | |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 3098 | return create_step( |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3099 | label="Setup {0}".format(project_name), |
| 3100 | commands=[fetch_bazelcipy_command(), pipeline_command], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3101 | platform=DEFAULT_PLATFORM, |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3102 | ) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3103 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3104 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3105 | def create_label(platform, project_name, build_only=False, test_only=False, task_name=None): |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3106 | if build_only and test_only: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3107 | raise BuildkiteException("build_only and test_only cannot be true at the same time") |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3108 | platform_display_name = PLATFORMS[platform]["emoji-name"] |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3109 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3110 | if build_only: |
| 3111 | label = "Build " |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3112 | elif test_only: |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3113 | label = "Test " |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3114 | else: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3115 | label = "" |
| 3116 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3117 | platform_label = ( |
| 3118 | "{0} on {1}".format(task_name, platform_display_name) |
| 3119 | if task_name |
| 3120 | else platform_display_name |
| 3121 | ) |
| 3122 | |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3123 | if project_name: |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3124 | label += "{0} ({1})".format(project_name, platform_label) |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3125 | else: |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3126 | label += platform_label |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3127 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3128 | return label |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3129 | |
| 3130 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3131 | def bazel_build_step( |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3132 | task, |
| 3133 | platform, |
| 3134 | project_name, |
| 3135 | http_config=None, |
| 3136 | file_config=None, |
| 3137 | build_only=False, |
| 3138 | test_only=False, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3139 | ): |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 3140 | pipeline_command = PLATFORMS[platform]["python"] + " bazelci.py runner" |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3141 | if build_only: |
Philipp Wollermann | c52e26a | 2019-05-18 22:10:47 +0200 | [diff] [blame] | 3142 | pipeline_command += " --build_only --save_but" |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3143 | if test_only: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3144 | pipeline_command += " --test_only" |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3145 | if http_config: |
Philipp Wollermann | f6be466 | 2018-02-21 14:48:28 +0100 | [diff] [blame] | 3146 | pipeline_command += " --http_config=" + http_config |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3147 | if file_config: |
| 3148 | pipeline_command += " --file_config=" + file_config |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3149 | pipeline_command += " --task=" + task |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3150 | |
Yun Peng | be4e2eb | 2022-09-16 11:42:50 +0200 | [diff] [blame] | 3151 | step = create_step( |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3152 | label=create_label(platform, project_name, build_only, test_only), |
| 3153 | commands=[fetch_bazelcipy_command(), pipeline_command], |
| 3154 | platform=platform, |
| 3155 | ) |
Yun Peng | be4e2eb | 2022-09-16 11:42:50 +0200 | [diff] [blame] | 3156 | # Always try to automatically retry the bazel build step, this will make |
| 3157 | # the publish bazel binaries pipeline more reliable. |
| 3158 | step["retry"] = { |
| 3159 | "automatic": [ |
| 3160 | {"exit_status": "*", "limit": 3}, |
| 3161 | ] |
| 3162 | } |
| 3163 | return step |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3164 | |
| 3165 | |
Florian Weikert | 5f5d3cb | 2019-04-15 15:36:27 +0200 | [diff] [blame] | 3166 | def filter_tasks_that_should_be_skipped(task_configs, pipeline_steps): |
| 3167 | skip_tasks = get_skip_tasks() |
| 3168 | if not skip_tasks: |
Florian Weikert | 5f5d3cb | 2019-04-15 15:36:27 +0200 | [diff] [blame] | 3169 | return task_configs |
| 3170 | |
| 3171 | actually_skipped = [] |
| 3172 | skip_tasks = set(skip_tasks) |
| 3173 | for task in list(task_configs.keys()): |
| 3174 | if task in skip_tasks: |
| 3175 | actually_skipped.append(task) |
| 3176 | del task_configs[task] |
| 3177 | skip_tasks.remove(task) |
| 3178 | |
| 3179 | if not task_configs: |
| 3180 | raise BuildkiteException( |
| 3181 | "Nothing to do since all tasks in the configuration should be skipped." |
| 3182 | ) |
| 3183 | |
| 3184 | annotations = [] |
| 3185 | if actually_skipped: |
| 3186 | annotations.append( |
| 3187 | ("info", "Skipping the following task(s): {}".format(", ".join(actually_skipped))) |
| 3188 | ) |
| 3189 | |
| 3190 | if skip_tasks: |
| 3191 | annotations.append( |
| 3192 | ( |
| 3193 | "warning", |
| 3194 | ( |
| 3195 | "The following tasks should have been skipped, " |
| 3196 | "but were not part of the configuration: {}" |
| 3197 | ).format(", ".join(skip_tasks)), |
| 3198 | ) |
| 3199 | ) |
| 3200 | |
| 3201 | if annotations: |
| 3202 | print_skip_task_annotations(annotations, pipeline_steps) |
| 3203 | |
| 3204 | return task_configs |
| 3205 | |
| 3206 | |
| 3207 | def get_skip_tasks(): |
| 3208 | value = os.getenv(SKIP_TASKS_ENV_VAR, "") |
| 3209 | return [v for v in value.split(",") if v] |
| 3210 | |
| 3211 | |
| 3212 | def print_skip_task_annotations(annotations, pipeline_steps): |
| 3213 | commands = [ |
| 3214 | "buildkite-agent annotate --style={} '{}' --context 'ctx-{}'".format(s, t, hash(t)) |
| 3215 | for s, t in annotations |
| 3216 | ] |
| 3217 | pipeline_steps.append( |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3218 | create_step( |
| 3219 | label=":pipeline: Print information about skipped tasks", |
| 3220 | commands=commands, |
| 3221 | platform=DEFAULT_PLATFORM, |
| 3222 | ) |
Florian Weikert | 5f5d3cb | 2019-04-15 15:36:27 +0200 | [diff] [blame] | 3223 | ) |
| 3224 | |
| 3225 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3226 | def print_bazel_publish_binaries_pipeline(task_configs, http_config, file_config): |
| 3227 | if not task_configs: |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3228 | raise BuildkiteException("Bazel publish binaries pipeline configuration is empty.") |
| 3229 | |
Florian Weikert | 5f5d3cb | 2019-04-15 15:36:27 +0200 | [diff] [blame] | 3230 | pipeline_steps = [] |
| 3231 | task_configs = filter_tasks_that_should_be_skipped(task_configs, pipeline_steps) |
| 3232 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3233 | platforms = [get_platform_for_task(t, tc) for t, tc in task_configs.items()] |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 3234 | |
| 3235 | # These are the platforms that the bazel_publish_binaries.yml config is actually building. |
| 3236 | configured_platforms = set(filter(should_publish_binaries_for_platform, platforms)) |
Philipp Wollermann | a2ea5d8 | 2018-08-27 14:12:10 +0200 | [diff] [blame] | 3237 | |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 3238 | # These are the platforms that we want to build and publish according to this script. |
| 3239 | expected_platforms = set(filter(should_publish_binaries_for_platform, PLATFORMS)) |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3240 | |
Philipp Wollermann | 30f314d | 2021-06-11 10:51:39 +0200 | [diff] [blame] | 3241 | # We can skip this check if we're not on the main branch, because then we're probably |
| 3242 | # building a one-off custom debugging binary anyway. |
Florian Weikert | 7f21ca4 | 2022-02-02 17:35:23 +0100 | [diff] [blame] | 3243 | if current_branch_is_main_branch(): |
| 3244 | missing = expected_platforms.difference(configured_platforms) |
| 3245 | if missing: |
| 3246 | raise BuildkiteException( |
| 3247 | ( |
| 3248 | "Bazel publish binaries pipeline needs to build Bazel for every commit on all publish_binary-enabled platforms. " |
| 3249 | "Please add jobs for the missing platform(s) to the pipeline config: {}".format( |
| 3250 | ", ".join(missing) |
| 3251 | ) |
| 3252 | ) |
| 3253 | ) |
Jakob Buchgraber | 08e8e40 | 2018-03-20 19:22:07 +0100 | [diff] [blame] | 3254 | |
Yun Peng | d352b6d | 2018-10-17 13:28:39 +0200 | [diff] [blame] | 3255 | # Build Bazel |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3256 | for task, task_config in task_configs.items(): |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3257 | pipeline_steps.append( |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3258 | bazel_build_step( |
| 3259 | task, |
| 3260 | get_platform_for_task(task, task_config), |
| 3261 | "Bazel", |
| 3262 | http_config, |
| 3263 | file_config, |
| 3264 | build_only=True, |
| 3265 | ) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3266 | ) |
Jakob Buchgraber | 4631a03 | 2018-03-22 17:12:46 +0100 | [diff] [blame] | 3267 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3268 | pipeline_steps.append("wait") |
Jakob Buchgraber | 9d6ca8a | 2018-03-22 17:30:09 +0100 | [diff] [blame] | 3269 | |
Yun Peng | c2dd652 | 2018-10-17 12:58:35 +0200 | [diff] [blame] | 3270 | # If all builds succeed, publish the Bazel binaries to GCS. |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3271 | pipeline_steps.append( |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 3272 | create_step( |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3273 | label="Publish Bazel Binaries", |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 3274 | commands=[ |
| 3275 | fetch_bazelcipy_command(), |
| 3276 | PLATFORMS[DEFAULT_PLATFORM]["python"] + " bazelci.py publish_binaries", |
| 3277 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3278 | platform=DEFAULT_PLATFORM, |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3279 | ) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3280 | ) |
Jakob Buchgraber | 08e8e40 | 2018-03-20 19:22:07 +0100 | [diff] [blame] | 3281 | |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 3282 | print_pipeline_steps(pipeline_steps) |
Jakob Buchgraber | 08e8e40 | 2018-03-20 19:22:07 +0100 | [diff] [blame] | 3283 | |
| 3284 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3285 | def should_publish_binaries_for_platform(platform): |
| 3286 | if platform not in PLATFORMS: |
| 3287 | raise BuildkiteException("Unknown platform '{}'".format(platform)) |
| 3288 | |
| 3289 | return PLATFORMS[platform]["publish_binary"] |
| 3290 | |
| 3291 | |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3292 | def print_disabled_projects_info_box_step(): |
| 3293 | info_text = ["Downstream testing is disabled for the following projects :sadpanda:"] |
| 3294 | for project, config in DOWNSTREAM_PROJECTS.items(): |
| 3295 | disabled_reason = config.get("disabled_reason", None) |
| 3296 | if disabled_reason: |
| 3297 | info_text.append("* **%s**: %s" % (project, disabled_reason)) |
| 3298 | |
| 3299 | if len(info_text) == 1: |
| 3300 | return None |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 3301 | return create_step( |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3302 | label=":sadpanda:", |
| 3303 | commands=[ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3304 | 'buildkite-agent annotate --append --style=info "\n' + "\n".join(info_text) + '\n"' |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3305 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3306 | platform=DEFAULT_PLATFORM, |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3307 | ) |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3308 | |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3309 | |
| 3310 | def print_incompatible_flags_info_box_step(incompatible_flags_map): |
| 3311 | info_text = ["Build and test with the following incompatible flags:"] |
| 3312 | |
| 3313 | for flag in incompatible_flags_map: |
| 3314 | info_text.append("* **%s**: %s" % (flag, incompatible_flags_map[flag])) |
| 3315 | |
| 3316 | if len(info_text) == 1: |
| 3317 | return None |
Philipp Wollermann | c43d3cf | 2019-01-10 13:24:15 +0100 | [diff] [blame] | 3318 | return create_step( |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3319 | label="Incompatible flags info", |
| 3320 | commands=[ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3321 | 'buildkite-agent annotate --append --style=info "\n' + "\n".join(info_text) + '\n"' |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3322 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3323 | platform=DEFAULT_PLATFORM, |
Philipp Wollermann | 1403d2c | 2019-01-10 13:15:51 +0100 | [diff] [blame] | 3324 | ) |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3325 | |
| 3326 | |
Yun Peng | 7d302f6 | 2019-01-10 16:56:15 +0100 | [diff] [blame] | 3327 | def fetch_incompatible_flags(): |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3328 | """ |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3329 | Return a list of incompatible flags to be tested. The key is the flag name and the value is its Github URL. |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3330 | """ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3331 | output = subprocess.check_output( |
| 3332 | [ |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3333 | # Query for open issues with "incompatible-change" and "migration-ready" label. |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3334 | "curl", |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3335 | "https://api.github.com/search/issues?per_page=100&q=repo:bazelbuild/bazel+label:incompatible-change+label:migration-ready+state:open", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3336 | ] |
| 3337 | ).decode("utf-8") |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3338 | issue_info = json.loads(output) |
| 3339 | |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3340 | FLAG_PATTERN = re.compile(r"^--[a-z][a-z0-9_]*$") |
| 3341 | incompatible_flags = {} |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3342 | for issue in issue_info["items"]: |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3343 | name = "--" + issue["title"].split(":")[0] |
| 3344 | url = issue["html_url"] |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3345 | if FLAG_PATTERN.match(name): |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3346 | incompatible_flags[name] = url |
| 3347 | else: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3348 | eprint( |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 3349 | f"{name} is not recognized as an incompatible flag, please modify the issue title " |
| 3350 | f'of {url} to "<incompatible flag name (without --)>:..."' |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3351 | ) |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3352 | |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3353 | # If INCOMPATIBLE_FLAGS is set manually, we test those flags, try to keep the URL info if possible. |
| 3354 | if "INCOMPATIBLE_FLAGS" in os.environ: |
| 3355 | given_incompatible_flags = {} |
| 3356 | for flag in os.environ["INCOMPATIBLE_FLAGS"].split(","): |
| 3357 | given_incompatible_flags[flag] = incompatible_flags.get(flag, "") |
| 3358 | return given_incompatible_flags |
| 3359 | |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3360 | return incompatible_flags |
| 3361 | |
| 3362 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3363 | def print_bazel_downstream_pipeline( |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3364 | task_configs, http_config, file_config, test_disabled_projects, notify |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3365 | ): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3366 | pipeline_steps = [] |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3367 | |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3368 | info_box_step = print_disabled_projects_info_box_step() |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3369 | if info_box_step is not None: |
| 3370 | pipeline_steps.append(info_box_step) |
| 3371 | |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3372 | if not use_bazelisk_migrate(): |
| 3373 | if not task_configs: |
| 3374 | raise BuildkiteException("Bazel downstream pipeline configuration is empty.") |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3375 | for task, task_config in task_configs.items(): |
Yun Peng | 5599ca2 | 2019-01-16 12:32:41 +0100 | [diff] [blame] | 3376 | pipeline_steps.append( |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3377 | bazel_build_step( |
| 3378 | task, |
| 3379 | get_platform_for_task(task, task_config), |
| 3380 | "Bazel", |
| 3381 | http_config, |
| 3382 | file_config, |
| 3383 | build_only=True, |
| 3384 | ) |
Yun Peng | 5599ca2 | 2019-01-16 12:32:41 +0100 | [diff] [blame] | 3385 | ) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3386 | |
Yun Peng | 5599ca2 | 2019-01-16 12:32:41 +0100 | [diff] [blame] | 3387 | pipeline_steps.append("wait") |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3388 | else: |
Yun Peng | 7d302f6 | 2019-01-10 16:56:15 +0100 | [diff] [blame] | 3389 | incompatible_flags_map = fetch_incompatible_flags() |
Yun Peng | 3c1d7d1 | 2020-06-30 14:58:34 +0200 | [diff] [blame] | 3390 | if not incompatible_flags_map: |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 3391 | step = create_step( |
| 3392 | label="No Incompatible flags info", |
| 3393 | commands=[ |
Florian Weikert | 42738ac | 2021-05-27 15:54:14 +0200 | [diff] [blame] | 3394 | 'buildkite-agent annotate --style=error "No incompatible flag issue is found on github for current version of Bazel." --context "noinc"' |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 3395 | ], |
| 3396 | platform=DEFAULT_PLATFORM, |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 3397 | ) |
Florian Weikert | 9d5e4c0 | 2021-05-27 15:10:20 +0200 | [diff] [blame] | 3398 | pipeline_steps.append(step) |
| 3399 | print_pipeline_steps(pipeline_steps) |
| 3400 | return |
| 3401 | |
Yun Peng | 6528e65 | 2019-01-02 14:41:07 +0100 | [diff] [blame] | 3402 | info_box_step = print_incompatible_flags_info_box_step(incompatible_flags_map) |
| 3403 | if info_box_step is not None: |
| 3404 | pipeline_steps.append(info_box_step) |
Yun Peng | 7a539ef | 2018-11-30 15:07:24 +0100 | [diff] [blame] | 3405 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3406 | for project, config in DOWNSTREAM_PROJECTS.items(): |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 3407 | disabled_reason = config.get("disabled_reason", None) |
Yun Peng | fb759fa | 2018-12-13 11:35:39 +0100 | [diff] [blame] | 3408 | # If test_disabled_projects is true, we add configs for disabled projects. |
Florian Weikert | 7b3f17e | 2019-03-14 13:52:42 +0100 | [diff] [blame] | 3409 | # If test_disabled_projects is false, we add configs for not disabled projects. |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3410 | if (test_disabled_projects and disabled_reason) or ( |
| 3411 | not test_disabled_projects and not disabled_reason |
| 3412 | ): |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 3413 | pipeline_steps.append( |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3414 | upload_project_pipeline_step( |
| 3415 | project_name=project, |
| 3416 | git_repository=config["git_repository"], |
| 3417 | http_config=config.get("http_config", None), |
| 3418 | file_config=config.get("file_config", None), |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3419 | ) |
| 3420 | ) |
Yun Peng | 71c2d9f | 2022-01-05 10:33:51 +0100 | [diff] [blame] | 3421 | |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3422 | if use_bazelisk_migrate(): |
Yun Peng | 002eab9 | 2018-12-17 18:28:14 +0100 | [diff] [blame] | 3423 | current_build_number = os.environ.get("BUILDKITE_BUILD_NUMBER", None) |
| 3424 | if not current_build_number: |
| 3425 | raise BuildkiteException("Not running inside Buildkite") |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3426 | |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 3427 | pipeline_steps += get_steps_for_aggregating_migration_results(current_build_number, notify) |
Yun Peng | 002eab9 | 2018-12-17 18:28:14 +0100 | [diff] [blame] | 3428 | |
Florian Weikert | 2896edb | 2019-04-04 16:12:47 +0200 | [diff] [blame] | 3429 | if ( |
| 3430 | not test_disabled_projects |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3431 | and not use_bazelisk_migrate() |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 3432 | and current_branch_is_main_branch() |
Florian Weikert | 2896edb | 2019-04-04 16:12:47 +0200 | [diff] [blame] | 3433 | ): |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3434 | # Only update the last green downstream commit in the regular Bazel@HEAD + Downstream pipeline. |
| 3435 | pipeline_steps.append("wait") |
| 3436 | pipeline_steps.append( |
| 3437 | create_step( |
| 3438 | label="Try Update Last Green Downstream Commit", |
| 3439 | commands=[ |
| 3440 | fetch_bazelcipy_command(), |
Philipp Wollermann | 57b3268 | 2019-05-18 22:09:27 +0200 | [diff] [blame] | 3441 | PLATFORMS[DEFAULT_PLATFORM]["python"] |
| 3442 | + " bazelci.py try_update_last_green_downstream_commit", |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3443 | ], |
Philipp Wollermann | 7a18532 | 2019-05-18 22:15:48 +0200 | [diff] [blame] | 3444 | platform=DEFAULT_PLATFORM, |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3445 | ) |
| 3446 | ) |
| 3447 | |
Florian Weikert | 13215a8 | 2019-05-10 12:42:21 +0200 | [diff] [blame] | 3448 | print_pipeline_steps(pipeline_steps) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3449 | |
| 3450 | |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 3451 | def get_steps_for_aggregating_migration_results(current_build_number, notify): |
Florian Weikert | 09813a0 | 2019-10-26 19:34:33 +0200 | [diff] [blame] | 3452 | parts = [ |
| 3453 | PLATFORMS[DEFAULT_PLATFORM]["python"], |
| 3454 | "aggregate_incompatible_flags_test_result.py", |
| 3455 | "--build_number=%s" % current_build_number, |
Florian Weikert | 09813a0 | 2019-10-26 19:34:33 +0200 | [diff] [blame] | 3456 | ] |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 3457 | if notify: |
| 3458 | parts.append("--notify") |
Florian Weikert | 09813a0 | 2019-10-26 19:34:33 +0200 | [diff] [blame] | 3459 | return [ |
| 3460 | {"wait": "~", "continue_on_failure": "true"}, |
| 3461 | create_step( |
| 3462 | label="Aggregate incompatible flags test result", |
| 3463 | commands=[ |
| 3464 | fetch_bazelcipy_command(), |
| 3465 | fetch_aggregate_incompatible_flags_test_result_command(), |
| 3466 | " ".join(parts), |
| 3467 | ], |
| 3468 | platform=DEFAULT_PLATFORM, |
| 3469 | ), |
| 3470 | ] |
| 3471 | |
| 3472 | |
Yun Peng | c2dd652 | 2018-10-17 12:58:35 +0200 | [diff] [blame] | 3473 | def bazelci_builds_download_url(platform, git_commit): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3474 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-builds" |
| 3475 | return "https://storage.googleapis.com/{}/artifacts/{}/{}/bazel".format( |
| 3476 | bucket_name, platform, git_commit |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3477 | ) |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3478 | |
| 3479 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3480 | def bazelci_builds_nojdk_download_url(platform, git_commit): |
| 3481 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-builds" |
| 3482 | return "https://storage.googleapis.com/{}/artifacts/{}/{}/bazel_nojdk".format( |
| 3483 | bucket_name, platform, git_commit |
| 3484 | ) |
| 3485 | |
| 3486 | |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 3487 | def bazelci_builds_gs_url(platform, git_commit): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3488 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-builds" |
| 3489 | return "gs://{}/artifacts/{}/{}/bazel".format(bucket_name, platform, git_commit) |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3490 | |
| 3491 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3492 | def bazelci_builds_nojdk_gs_url(platform, git_commit): |
| 3493 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-builds" |
| 3494 | return "gs://{}/artifacts/{}/{}/bazel_nojdk".format(bucket_name, platform, git_commit) |
| 3495 | |
| 3496 | |
mai93 | f04f948 | 2020-10-20 17:22:30 +0200 | [diff] [blame] | 3497 | def bazelci_latest_build_metadata_url(): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3498 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-builds" |
| 3499 | return "gs://{}/metadata/latest.json".format(bucket_name) |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3500 | |
| 3501 | |
mai93 | f04f948 | 2020-10-20 17:22:30 +0200 | [diff] [blame] | 3502 | def bazelci_builds_metadata_url(git_commit): |
| 3503 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-builds" |
| 3504 | return "gs://{}/metadata/{}.json".format(bucket_name, git_commit) |
| 3505 | |
| 3506 | |
Yun Peng | 996efad | 2018-11-27 17:19:44 +0100 | [diff] [blame] | 3507 | def bazelci_last_green_commit_url(git_repository, pipeline_slug): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3508 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-untrusted-builds" |
| 3509 | return "gs://{}/last_green_commit/{}/{}".format( |
| 3510 | bucket_name, git_repository[len("https://") :], pipeline_slug |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3511 | ) |
Yun Peng | afe67d4 | 2018-11-23 17:06:43 +0100 | [diff] [blame] | 3512 | |
| 3513 | |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3514 | def bazelci_last_green_downstream_commit_url(): |
Philipp Wollermann | e67eec4 | 2019-05-24 15:18:20 +0200 | [diff] [blame] | 3515 | bucket_name = "bazel-testing-builds" if THIS_IS_TESTING else "bazel-untrusted-builds" |
| 3516 | return "gs://{}/last_green_commit/downstream_pipeline".format(bucket_name) |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3517 | |
| 3518 | |
| 3519 | def get_last_green_commit(last_green_commit_url): |
Yun Peng | 61a448f | 2018-11-23 17:11:46 +0100 | [diff] [blame] | 3520 | try: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3521 | return ( |
| 3522 | subprocess.check_output( |
| 3523 | [gsutil_command(), "cat", last_green_commit_url], env=os.environ |
| 3524 | ) |
| 3525 | .decode("utf-8") |
| 3526 | .strip() |
| 3527 | ) |
Yun Peng | 61a448f | 2018-11-23 17:11:46 +0100 | [diff] [blame] | 3528 | except subprocess.CalledProcessError: |
| 3529 | return None |
Yun Peng | 43239b0 | 2018-11-23 13:57:34 +0100 | [diff] [blame] | 3530 | |
| 3531 | |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3532 | def try_update_last_green_commit(): |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 3533 | org_slug = os.getenv("BUILDKITE_ORGANIZATION_SLUG") |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3534 | pipeline_slug = os.getenv("BUILDKITE_PIPELINE_SLUG") |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 3535 | build_number = os.getenv("BUILDKITE_BUILD_NUMBER") |
| 3536 | current_job_id = os.getenv("BUILDKITE_JOB_ID") |
| 3537 | |
| 3538 | client = BuildkiteClient(org=org_slug, pipeline=pipeline_slug) |
| 3539 | build_info = client.get_build_info(build_number) |
| 3540 | |
mai93 | 02a609c | 2021-05-20 10:36:46 +0200 | [diff] [blame] | 3541 | # Find any failing steps other than Buildifier and steps with soft_fail enabled then "try update last green". |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3542 | def has_failed(job): |
Florian Weikert | bd40a27 | 2019-03-08 10:20:18 +0100 | [diff] [blame] | 3543 | state = job.get("state") |
| 3544 | # Ignore steps that don't have a state (like "wait"). |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 3545 | return ( |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3546 | state is not None |
| 3547 | and state != "passed" |
mai93 | 02a609c | 2021-05-20 10:36:46 +0200 | [diff] [blame] | 3548 | and not job.get("soft_failed") |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 3549 | and job["id"] != current_job_id |
| 3550 | and job["name"] != BUILDIFIER_STEP_NAME |
| 3551 | ) |
| 3552 | |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3553 | failing_jobs = [j["name"] for j in build_info["jobs"] if has_failed(j)] |
Florian Weikert | de96a6f | 2019-03-07 14:57:50 +0100 | [diff] [blame] | 3554 | if failing_jobs: |
| 3555 | raise BuildkiteException( |
| 3556 | "Cannot update last green commit due to {} failing step(s): {}".format( |
| 3557 | len(failing_jobs), ", ".join(failing_jobs) |
| 3558 | ) |
| 3559 | ) |
| 3560 | |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3561 | git_repository = os.getenv("BUILDKITE_REPO") |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3562 | last_green_commit_url = bazelci_last_green_commit_url(git_repository, pipeline_slug) |
| 3563 | update_last_green_commit_if_newer(last_green_commit_url) |
| 3564 | |
| 3565 | |
| 3566 | def update_last_green_commit_if_newer(last_green_commit_url): |
| 3567 | last_green_commit = get_last_green_commit(last_green_commit_url) |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 3568 | current_commit = resolve_revision("HEAD") |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3569 | if last_green_commit: |
Jakob Buchgraber | 7c7ceee | 2019-10-28 10:28:58 +0100 | [diff] [blame] | 3570 | success = False |
| 3571 | try: |
| 3572 | execute_command(["git", "fetch", "-v", "origin", last_green_commit]) |
| 3573 | success = True |
| 3574 | except subprocess.CalledProcessError: |
| 3575 | # If there was an error fetching the commit it typically means |
| 3576 | # that the commit does not exist anymore - due to a force push. In |
| 3577 | # order to recover from that assume that the current commit is the |
| 3578 | # newest commit. |
| 3579 | result = [current_commit] |
| 3580 | finally: |
| 3581 | if success: |
| 3582 | result = ( |
| 3583 | subprocess.check_output( |
| 3584 | ["git", "rev-list", "%s..%s" % (last_green_commit, current_commit)] |
| 3585 | ) |
| 3586 | .decode("utf-8") |
| 3587 | .strip() |
| 3588 | ) |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3589 | else: |
| 3590 | result = None |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3591 | |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 3592 | # If current_commit is newer that last_green_commit, `git rev-list A..B` will output a bunch of |
| 3593 | # commits, otherwise the output should be empty. |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3594 | if not last_green_commit or result: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3595 | execute_command( |
Philipp Wollermann | 76a7eac | 2020-02-17 18:29:52 +0100 | [diff] [blame] | 3596 | [ |
| 3597 | "echo %s | %s -h 'Cache-Control: no-store' cp - %s" |
| 3598 | % (current_commit, gsutil_command(), last_green_commit_url) |
| 3599 | ], |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3600 | shell=True, |
| 3601 | ) |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3602 | else: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3603 | eprint( |
| 3604 | "Updating abandoned: last green commit (%s) is not older than current commit (%s)." |
| 3605 | % (last_green_commit, current_commit) |
| 3606 | ) |
| 3607 | |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3608 | |
Florian Weikert | 5e70d9d | 2023-05-08 19:20:23 +0200 | [diff] [blame] | 3609 | def resolve_revision(rev): |
| 3610 | return subprocess.check_output(["git", "rev-parse", rev]).decode("utf-8").strip() |
| 3611 | |
| 3612 | |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3613 | def try_update_last_green_downstream_commit(): |
| 3614 | last_green_commit_url = bazelci_last_green_downstream_commit_url() |
| 3615 | update_last_green_commit_if_newer(last_green_commit_url) |
| 3616 | |
| 3617 | |
Jakob Buchgraber | 76381e0 | 2018-02-19 16:19:56 +0100 | [diff] [blame] | 3618 | def latest_generation_and_build_number(): |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3619 | generation = None |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3620 | output = None |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3621 | for attempt in range(5): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3622 | output = subprocess.check_output( |
mai93 | f04f948 | 2020-10-20 17:22:30 +0200 | [diff] [blame] | 3623 | [gsutil_command(), "stat", bazelci_latest_build_metadata_url()], env=os.environ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3624 | ) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3625 | match = re.search("Generation:[ ]*([0-9]+)", output.decode("utf-8")) |
| 3626 | if not match: |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3627 | raise BuildkiteException("Couldn't parse generation. gsutil output format changed?") |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3628 | generation = match.group(1) |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3629 | |
Philipp Wollermann | ff39ef5 | 2018-02-21 14:18:52 +0100 | [diff] [blame] | 3630 | match = re.search(r"Hash \(md5\):[ ]*([^\s]+)", output.decode("utf-8")) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3631 | if not match: |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3632 | raise BuildkiteException("Couldn't parse md5 hash. gsutil output format changed?") |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3633 | expected_md5hash = base64.b64decode(match.group(1)) |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3634 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3635 | output = subprocess.check_output( |
mai93 | f04f948 | 2020-10-20 17:22:30 +0200 | [diff] [blame] | 3636 | [gsutil_command(), "cat", bazelci_latest_build_metadata_url()], env=os.environ |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3637 | ) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3638 | hasher = hashlib.md5() |
| 3639 | hasher.update(output) |
| 3640 | actual_md5hash = hasher.digest() |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3641 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3642 | if expected_md5hash == actual_md5hash: |
| 3643 | break |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3644 | info = json.loads(output.decode("utf-8")) |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3645 | return generation, info["build_number"] |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3646 | |
Jakob Buchgraber | 699aece | 2018-02-19 12:49:30 +0100 | [diff] [blame] | 3647 | |
Jakob Buchgraber | 88083fd | 2018-02-18 17:23:35 +0100 | [diff] [blame] | 3648 | def sha256_hexdigest(filename): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3649 | sha256 = hashlib.sha256() |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3650 | with open(filename, "rb") as f: |
| 3651 | for block in iter(lambda: f.read(65536), b""): |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3652 | sha256.update(block) |
| 3653 | return sha256.hexdigest() |
Jakob Buchgraber | 699aece | 2018-02-19 12:49:30 +0100 | [diff] [blame] | 3654 | |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3655 | |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3656 | def upload_bazel_binaries(): |
| 3657 | """ |
| 3658 | Uploads all Bazel binaries to a deterministic URL based on the current Git commit. |
| 3659 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3660 | Returns maps of platform names to sha256 hashes of the corresponding bazel and bazel_nojdk binaries. |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3661 | """ |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3662 | bazel_hashes = {} |
| 3663 | bazel_nojdk_hashes = {} |
Philipp Wollermann | bdd4bf9 | 2019-06-06 14:43:50 +0200 | [diff] [blame] | 3664 | for platform_name, platform in PLATFORMS.items(): |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 3665 | if not should_publish_binaries_for_platform(platform_name): |
| 3666 | continue |
Jakob Buchgraber | b13a9a8 | 2018-03-27 18:37:09 +0200 | [diff] [blame] | 3667 | tmpdir = tempfile.mkdtemp() |
| 3668 | try: |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 3669 | bazel_binary_path = download_bazel_binary(tmpdir, platform_name) |
| 3670 | # One platform that we build on can generate binaries for multiple platforms, e.g. |
Philipp Wollermann | f4aabb7 | 2019-06-25 15:59:00 +0200 | [diff] [blame] | 3671 | # the centos7 platform generates binaries for the "centos7" platform, but also |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 3672 | # for the generic "linux" platform. |
| 3673 | for target_platform_name in platform["publish_binary"]: |
| 3674 | execute_command( |
| 3675 | [ |
| 3676 | gsutil_command(), |
| 3677 | "cp", |
| 3678 | bazel_binary_path, |
| 3679 | bazelci_builds_gs_url(target_platform_name, os.environ["BUILDKITE_COMMIT"]), |
| 3680 | ] |
| 3681 | ) |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3682 | bazel_hashes[target_platform_name] = sha256_hexdigest(bazel_binary_path) |
| 3683 | |
| 3684 | # Also publish bazel_nojdk binaries. |
| 3685 | bazel_nojdk_binary_path = download_bazel_nojdk_binary(tmpdir, platform_name) |
| 3686 | for target_platform_name in platform["publish_binary"]: |
| 3687 | execute_command( |
| 3688 | [ |
| 3689 | gsutil_command(), |
| 3690 | "cp", |
| 3691 | bazel_nojdk_binary_path, |
Florian Weikert | db832a0 | 2020-11-19 19:14:48 +0100 | [diff] [blame] | 3692 | bazelci_builds_nojdk_gs_url( |
| 3693 | target_platform_name, os.environ["BUILDKITE_COMMIT"] |
| 3694 | ), |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3695 | ] |
| 3696 | ) |
| 3697 | bazel_nojdk_hashes[target_platform_name] = sha256_hexdigest(bazel_nojdk_binary_path) |
Philipp Wollermann | 30f314d | 2021-06-11 10:51:39 +0200 | [diff] [blame] | 3698 | except subprocess.CalledProcessError as e: |
| 3699 | # If we're not on the main branch, we're probably building a custom one-off binary and |
| 3700 | # ignore failures for individual platforms (it's possible that we didn't build binaries |
| 3701 | # for all platforms). |
| 3702 | if not current_branch_is_main_branch(): |
| 3703 | eprint( |
| 3704 | "Ignoring failure to download and publish Bazel binary for platform {}: {}".format( |
| 3705 | platform_name, e |
| 3706 | ) |
| 3707 | ) |
| 3708 | else: |
| 3709 | raise e |
Jakob Buchgraber | b13a9a8 | 2018-03-27 18:37:09 +0200 | [diff] [blame] | 3710 | finally: |
| 3711 | shutil.rmtree(tmpdir) |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3712 | return bazel_hashes, bazel_nojdk_hashes |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3713 | |
| 3714 | |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3715 | def try_publish_binaries(bazel_hashes, bazel_nojdk_hashes, build_number, expected_generation): |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3716 | """ |
| 3717 | Uploads the info.json file that contains information about the latest Bazel commit that was |
| 3718 | successfully built on CI. |
| 3719 | """ |
| 3720 | now = datetime.datetime.now() |
| 3721 | git_commit = os.environ["BUILDKITE_COMMIT"] |
| 3722 | info = { |
| 3723 | "build_number": build_number, |
| 3724 | "build_time": now.strftime("%d-%m-%Y %H:%M"), |
| 3725 | "git_commit": git_commit, |
| 3726 | "platforms": {}, |
| 3727 | } |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3728 | for platform, sha256 in bazel_hashes.items(): |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3729 | info["platforms"][platform] = { |
| 3730 | "url": bazelci_builds_download_url(platform, git_commit), |
Philipp Wollermann | 783d167 | 2019-06-06 13:35:30 +0200 | [diff] [blame] | 3731 | "sha256": sha256, |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3732 | "nojdk_url": bazelci_builds_nojdk_download_url(platform, git_commit), |
| 3733 | "nojdk_sha256": bazel_nojdk_hashes[platform], |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3734 | } |
Jakob Buchgraber | b13a9a8 | 2018-03-27 18:37:09 +0200 | [diff] [blame] | 3735 | tmpdir = tempfile.mkdtemp() |
| 3736 | try: |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3737 | info_file = os.path.join(tmpdir, "info.json") |
| 3738 | with open(info_file, mode="w", encoding="utf-8") as fp: |
Jakob Buchgraber | 609a20e | 2018-02-25 17:06:51 +0100 | [diff] [blame] | 3739 | json.dump(info, fp, indent=2, sort_keys=True) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3740 | |
| 3741 | try: |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3742 | execute_command( |
| 3743 | [ |
| 3744 | gsutil_command(), |
| 3745 | "-h", |
| 3746 | "x-goog-if-generation-match:" + expected_generation, |
| 3747 | "-h", |
| 3748 | "Content-Type:application/json", |
| 3749 | "cp", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3750 | info_file, |
mai93 | f04f948 | 2020-10-20 17:22:30 +0200 | [diff] [blame] | 3751 | bazelci_latest_build_metadata_url(), |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3752 | ] |
| 3753 | ) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3754 | except subprocess.CalledProcessError: |
| 3755 | raise BinaryUploadRaceException() |
mai93 | f04f948 | 2020-10-20 17:22:30 +0200 | [diff] [blame] | 3756 | |
| 3757 | execute_command( |
| 3758 | [ |
| 3759 | gsutil_command(), |
| 3760 | "cp", |
| 3761 | bazelci_latest_build_metadata_url(), |
| 3762 | bazelci_builds_metadata_url(git_commit), |
| 3763 | ] |
| 3764 | ) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3765 | finally: |
Philipp Wollermann | 3e1a771 | 2018-02-19 17:34:24 +0100 | [diff] [blame] | 3766 | shutil.rmtree(tmpdir) |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3767 | |
| 3768 | |
Jakob Buchgraber | 76381e0 | 2018-02-19 16:19:56 +0100 | [diff] [blame] | 3769 | def publish_binaries(): |
Philipp Wollermann | db02486 | 2018-02-19 17:16:56 +0100 | [diff] [blame] | 3770 | """ |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3771 | Publish Bazel binaries to GCS. |
Philipp Wollermann | db02486 | 2018-02-19 17:16:56 +0100 | [diff] [blame] | 3772 | """ |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3773 | current_build_number = os.environ.get("BUILDKITE_BUILD_NUMBER", None) |
| 3774 | if not current_build_number: |
| 3775 | raise BuildkiteException("Not running inside Buildkite") |
| 3776 | current_build_number = int(current_build_number) |
| 3777 | |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3778 | # Upload the Bazel binaries for this commit. |
Rupert Shuttleworth | 7f3a91e | 2020-08-22 07:31:47 -0400 | [diff] [blame] | 3779 | bazel_hashes, bazel_nojdk_hashes = upload_bazel_binaries() |
Philipp Wollermann | 0295527 | 2019-04-18 18:00:48 +0200 | [diff] [blame] | 3780 | |
| 3781 | # Try to update the info.json with data about our build. This will fail (expectedly) if we're |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 3782 | # not the latest build. Only do this if we're building binaries from the main branch to avoid |
| 3783 | # accidentally publishing a custom debug build as the "latest" Bazel binary. |
| 3784 | if current_branch_is_main_branch(): |
| 3785 | for _ in range(5): |
| 3786 | latest_generation, latest_build_number = latest_generation_and_build_number() |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3787 | |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 3788 | if current_build_number <= latest_build_number: |
| 3789 | eprint( |
| 3790 | ( |
| 3791 | "Current build '{0}' is not newer than latest published '{1}'. " |
| 3792 | + "Skipping publishing of binaries." |
| 3793 | ).format(current_build_number, latest_build_number) |
| 3794 | ) |
| 3795 | break |
| 3796 | |
| 3797 | try: |
| 3798 | try_publish_binaries( |
| 3799 | bazel_hashes, bazel_nojdk_hashes, current_build_number, latest_generation |
| 3800 | ) |
| 3801 | except BinaryUploadRaceException: |
| 3802 | # Retry. |
| 3803 | continue |
| 3804 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3805 | eprint( |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 3806 | "Successfully updated '{0}' to binaries from build {1}.".format( |
| 3807 | bazelci_latest_build_metadata_url(), current_build_number |
| 3808 | ) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3809 | ) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3810 | break |
Philipp Wollermann | 1b5ecdc | 2021-06-10 21:52:55 +0200 | [diff] [blame] | 3811 | else: |
| 3812 | raise BuildkiteException("Could not publish binaries, ran out of attempts.") |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3813 | |
Philipp Wollermann | 3c8b851 | 2019-07-16 15:28:03 +0200 | [diff] [blame] | 3814 | |
Philipp Wollermann | 639c045 | 2019-01-03 11:23:54 +0100 | [diff] [blame] | 3815 | # This is so that multiline python strings are represented as YAML |
| 3816 | # block strings. |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3817 | def str_presenter(dumper, data): |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3818 | if len(data.splitlines()) > 1: # check for multiline string |
| 3819 | return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|") |
| 3820 | return dumper.represent_scalar("tag:yaml.org,2002:str", data) |
| 3821 | |
Jakob Buchgraber | d20ffeb | 2018-02-18 03:16:43 +0100 | [diff] [blame] | 3822 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3823 | def main(argv=None): |
| 3824 | if argv is None: |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 3825 | argv = sys.argv[1:] |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3826 | |
Jakob Buchgraber | 9952a3b | 2018-12-06 15:38:51 +0100 | [diff] [blame] | 3827 | yaml.add_representer(str, str_presenter) |
| 3828 | |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3829 | parser = argparse.ArgumentParser(description="Bazel Continuous Integration Script") |
Florian Weikert | 944209b | 2019-05-10 12:41:48 +0200 | [diff] [blame] | 3830 | parser.add_argument("--script", type=str) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3831 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3832 | subparsers = parser.add_subparsers(dest="subparsers_name") |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3833 | |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3834 | bazel_publish_binaries_pipeline = subparsers.add_parser("bazel_publish_binaries_pipeline") |
| 3835 | bazel_publish_binaries_pipeline.add_argument("--file_config", type=str) |
Jakob Buchgraber | 08e8e40 | 2018-03-20 19:22:07 +0100 | [diff] [blame] | 3836 | bazel_publish_binaries_pipeline.add_argument("--http_config", type=str) |
| 3837 | bazel_publish_binaries_pipeline.add_argument("--git_repository", type=str) |
| 3838 | |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3839 | bazel_downstream_pipeline = subparsers.add_parser("bazel_downstream_pipeline") |
| 3840 | bazel_downstream_pipeline.add_argument("--file_config", type=str) |
| 3841 | bazel_downstream_pipeline.add_argument("--http_config", type=str) |
| 3842 | bazel_downstream_pipeline.add_argument("--git_repository", type=str) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3843 | bazel_downstream_pipeline.add_argument( |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3844 | "--test_disabled_projects", type=bool, nargs="?", const=True |
| 3845 | ) |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 3846 | bazel_downstream_pipeline.add_argument("--notify", type=bool, nargs="?", const=True) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3847 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3848 | project_pipeline = subparsers.add_parser("project_pipeline") |
| 3849 | project_pipeline.add_argument("--project_name", type=str) |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3850 | project_pipeline.add_argument("--file_config", type=str) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3851 | project_pipeline.add_argument("--http_config", type=str) |
| 3852 | project_pipeline.add_argument("--git_repository", type=str) |
Jakob Buchgraber | 66ba4fe | 2018-06-22 15:04:14 +0200 | [diff] [blame] | 3853 | project_pipeline.add_argument("--monitor_flaky_tests", type=bool, nargs="?", const=True) |
Philipp Wollermann | 2409c6e | 2018-08-07 07:37:54 +0200 | [diff] [blame] | 3854 | project_pipeline.add_argument("--use_but", type=bool, nargs="?", const=True) |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 3855 | project_pipeline.add_argument("--notify", type=bool, nargs="?", const=True) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3856 | |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3857 | runner = subparsers.add_parser("runner") |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3858 | runner.add_argument("--task", action="store", type=str, default="") |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3859 | runner.add_argument("--file_config", type=str) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3860 | runner.add_argument("--http_config", type=str) |
| 3861 | runner.add_argument("--git_repository", type=str) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3862 | runner.add_argument( |
| 3863 | "--git_commit", type=str, help="Reset the git repository to this commit after cloning it" |
| 3864 | ) |
| 3865 | runner.add_argument( |
Yun Peng | 5012a86 | 2021-09-16 16:35:43 +0200 | [diff] [blame] | 3866 | "--repo_location", |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3867 | type=str, |
| 3868 | help="Use an existing repository instead of cloning from github", |
| 3869 | ) |
| 3870 | runner.add_argument( |
Dan Halperin | efda119 | 2019-01-16 00:34:09 -0800 | [diff] [blame] | 3871 | "--use_bazel_at_commit", type=str, help="Use Bazel binary built at a specific commit" |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3872 | ) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3873 | runner.add_argument("--use_but", type=bool, nargs="?", const=True) |
| 3874 | runner.add_argument("--save_but", type=bool, nargs="?", const=True) |
Yun Peng | 4d1d654 | 2019-01-17 18:30:33 +0100 | [diff] [blame] | 3875 | runner.add_argument("--needs_clean", type=bool, nargs="?", const=True) |
Philipp Wollermann | 598b4a4 | 2018-02-19 17:03:36 +0100 | [diff] [blame] | 3876 | runner.add_argument("--build_only", type=bool, nargs="?", const=True) |
| 3877 | runner.add_argument("--test_only", type=bool, nargs="?", const=True) |
Jakob Buchgraber | 66ba4fe | 2018-06-22 15:04:14 +0200 | [diff] [blame] | 3878 | runner.add_argument("--monitor_flaky_tests", type=bool, nargs="?", const=True) |
Jakob Buchgraber | c340f58 | 2018-06-22 13:48:33 +0200 | [diff] [blame] | 3879 | |
Philipp Wollermann | ce986af | 2019-07-18 14:46:05 +0200 | [diff] [blame] | 3880 | subparsers.add_parser("publish_binaries") |
| 3881 | subparsers.add_parser("try_update_last_green_commit") |
| 3882 | subparsers.add_parser("try_update_last_green_downstream_commit") |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3883 | |
Yun Peng | 20d4560 | 2018-10-18 13:27:05 +0200 | [diff] [blame] | 3884 | args = parser.parse_args(argv) |
Jakob Buchgraber | 0b6a39d | 2018-02-17 00:45:14 +0100 | [diff] [blame] | 3885 | |
Florian Weikert | 944209b | 2019-05-10 12:41:48 +0200 | [diff] [blame] | 3886 | if args.script: |
| 3887 | global SCRIPT_URL |
| 3888 | SCRIPT_URL = args.script |
| 3889 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3890 | try: |
Jakob Buchgraber | 08e8e40 | 2018-03-20 19:22:07 +0100 | [diff] [blame] | 3891 | if args.subparsers_name == "bazel_publish_binaries_pipeline": |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3892 | configs = fetch_configs(args.http_config, args.file_config) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3893 | print_bazel_publish_binaries_pipeline( |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3894 | task_configs=configs.get("tasks", None), |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3895 | http_config=args.http_config, |
| 3896 | file_config=args.file_config, |
| 3897 | ) |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3898 | elif args.subparsers_name == "bazel_downstream_pipeline": |
Yun Peng | c85cd0e | 2022-09-02 10:44:29 +0200 | [diff] [blame] | 3899 | # If USE_BAZELISK_MIGRATE is true, we don't need to fetch task configs for Bazel |
| 3900 | # since we use Bazelisk to fetch Bazel binaries. |
Florian Weikert | b3439b3 | 2022-11-09 11:05:16 +0100 | [diff] [blame] | 3901 | configs = ( |
| 3902 | {} if use_bazelisk_migrate() else fetch_configs(args.http_config, args.file_config) |
| 3903 | ) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3904 | print_bazel_downstream_pipeline( |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3905 | task_configs=configs.get("tasks", None), |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3906 | http_config=args.http_config, |
| 3907 | file_config=args.file_config, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3908 | test_disabled_projects=args.test_disabled_projects, |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 3909 | notify=args.notify, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3910 | ) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3911 | elif args.subparsers_name == "project_pipeline": |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3912 | configs = fetch_configs(args.http_config, args.file_config) |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3913 | print_project_pipeline( |
Florian Weikert | f20ae6f | 2019-01-16 14:32:09 +0100 | [diff] [blame] | 3914 | configs=configs, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3915 | project_name=args.project_name, |
| 3916 | http_config=args.http_config, |
| 3917 | file_config=args.file_config, |
| 3918 | git_repository=args.git_repository, |
| 3919 | monitor_flaky_tests=args.monitor_flaky_tests, |
| 3920 | use_but=args.use_but, |
Florian Weikert | 6066191 | 2019-12-18 15:17:10 +0100 | [diff] [blame] | 3921 | notify=args.notify, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3922 | ) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3923 | elif args.subparsers_name == "runner": |
Jakob Buchgraber | c57d4ad | 2018-03-22 12:33:17 +0100 | [diff] [blame] | 3924 | configs = fetch_configs(args.http_config, args.file_config) |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3925 | tasks = configs.get("tasks", {}) |
| 3926 | task_config = tasks.get(args.task) |
| 3927 | if not task_config: |
| 3928 | raise BuildkiteException( |
| 3929 | "No such task '{}' in configuration. Available: {}".format( |
| 3930 | args.task, ", ".join(tasks) |
| 3931 | ) |
| 3932 | ) |
| 3933 | |
Chi Wang | db96541 | 2023-05-10 09:00:46 +0000 | [diff] [blame] | 3934 | os.environ["BAZELCI_TASK"] = args.task |
| 3935 | |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3936 | platform = get_platform_for_task(args.task, task_config) |
| 3937 | |
Yun Peng | db76f84 | 2021-08-30 18:39:38 +0200 | [diff] [blame] | 3938 | # The value of `BUILDKITE_MESSAGE` defaults to the commit message, which can be too large |
| 3939 | # on Windows, therefore we truncate the value to 1000 characters. |
| 3940 | # See https://github.com/bazelbuild/continuous-integration/issues/1218 |
| 3941 | if "BUILDKITE_MESSAGE" in os.environ: |
| 3942 | os.environ["BUILDKITE_MESSAGE"] = os.environ["BUILDKITE_MESSAGE"][:1000] |
| 3943 | |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3944 | execute_commands( |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 3945 | task_config=task_config, |
Florian Weikert | 843d7a0 | 2019-02-03 17:24:50 +0100 | [diff] [blame] | 3946 | platform=platform, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3947 | git_repository=args.git_repository, |
| 3948 | git_commit=args.git_commit, |
Yun Peng | 5012a86 | 2021-09-16 16:35:43 +0200 | [diff] [blame] | 3949 | repo_location=args.repo_location, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3950 | use_bazel_at_commit=args.use_bazel_at_commit, |
| 3951 | use_but=args.use_but, |
| 3952 | save_but=args.save_but, |
Yun Peng | 4d1d654 | 2019-01-17 18:30:33 +0100 | [diff] [blame] | 3953 | needs_clean=args.needs_clean, |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3954 | build_only=args.build_only, |
| 3955 | test_only=args.test_only, |
| 3956 | monitor_flaky_tests=args.monitor_flaky_tests, |
Florian Weikert | c8642af | 2019-02-03 23:58:51 +0100 | [diff] [blame] | 3957 | bazel_version=task_config.get("bazel") or configs.get("bazel"), |
Philipp Wollermann | cd5694c | 2019-01-03 14:53:04 +0100 | [diff] [blame] | 3958 | ) |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3959 | elif args.subparsers_name == "publish_binaries": |
| 3960 | publish_binaries() |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3961 | elif args.subparsers_name == "try_update_last_green_commit": |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3962 | # Update the last green commit of a project pipeline |
Yun Peng | 358cd88 | 2018-11-29 10:25:18 +0100 | [diff] [blame] | 3963 | try_update_last_green_commit() |
Florian Weikert | 3590654 | 2019-04-01 11:53:53 +0200 | [diff] [blame] | 3964 | elif args.subparsers_name == "try_update_last_green_downstream_commit": |
| 3965 | # Update the last green commit of the downstream pipeline |
| 3966 | try_update_last_green_downstream_commit() |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3967 | else: |
| 3968 | parser.print_help() |
| 3969 | return 2 |
| 3970 | except BuildkiteException as e: |
| 3971 | eprint(str(e)) |
| 3972 | return 1 |
| 3973 | return 0 |
| 3974 | |
Jakob Buchgraber | 95e3d57 | 2018-02-21 18:48:49 +0100 | [diff] [blame] | 3975 | |
Philipp Wollermann | dcaddd9 | 2018-02-21 14:13:43 +0100 | [diff] [blame] | 3976 | if __name__ == "__main__": |
| 3977 | sys.exit(main()) |