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