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