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