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