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