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