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