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