go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/lucicfg/examples/02-ci-and-try/main.star (about) 1 #!/usr/bin/env lucicfg 2 3 """A fully functional config example. 4 5 This example shows a fully functional config that defines several post-submit 6 (aka CI) and pre-submit (aka Try) builders. It also includes Milo console and 7 CQ build group definitions. 8 9 It is a good template for small projects that want to start using lucicfg. 10 """ 11 12 # Constants shared by multiple definitions below. 13 REPO_URL = "https://my-awesome-host.googlesource.com/my/awesome/repo" 14 RECIPE_BUNDLE = "infra/recipe_bundles/<your-recipe-bundle>" 15 16 # Definition of what LUCI micro-services to use and global ACLs that apply to 17 # all buckets. 18 luci.project( 19 name = "my-awesome-project", 20 buildbucket = "cr-buildbucket.appspot.com", 21 logdog = "luci-logdog.appspot.com", 22 milo = "luci-milo.appspot.com", 23 scheduler = "luci-scheduler.appspot.com", 24 swarming = "chromium-swarm.appspot.com", 25 acls = [ 26 # This project is publicly readable. 27 acl.entry( 28 roles = [ 29 acl.BUILDBUCKET_READER, 30 acl.LOGDOG_READER, 31 acl.PROJECT_CONFIGS_READER, 32 acl.SCHEDULER_READER, 33 ], 34 groups = "all", 35 ), 36 # Allow committers to use CQ and to force-trigger and stop CI builds. 37 acl.entry( 38 roles = [ 39 acl.SCHEDULER_OWNER, 40 acl.CQ_COMMITTER, 41 ], 42 groups = "my-awesome-project-committers", 43 ), 44 # Ability to launch CQ dry runs. 45 acl.entry( 46 roles = acl.CQ_DRY_RUNNER, 47 groups = "my-awesome-project-tryjob-access", 48 ), 49 # Group with robots that have write access to the Logdog prefix. 50 acl.entry( 51 roles = acl.LOGDOG_WRITER, 52 groups = "my-awesome-project-log-writers", 53 ), 54 ], 55 ) 56 57 # Required Logdog configuration. 58 luci.logdog(gs_bucket = "my-awesome-project-logs-bucket") 59 60 # Optional tweaks. 61 luci.milo( 62 logo = "https://storage.googleapis.com/my-awesome-project-resources/logo-200x200.png", 63 favicon = "https://storage.googleapis.com/my-awesome-project-resources/favicon.icon", 64 ) 65 luci.cq(status_host = "chromium-cq-status.appspot.com") 66 67 # Bucket with post-submit builders. 68 luci.bucket(name = "ci") 69 70 # Bucket with pre-submit builders. 71 luci.bucket( 72 name = "try", 73 acls = [ 74 # Allow launching tryjobs directly (in addition to doing it through CQ). 75 acl.entry( 76 roles = acl.BUILDBUCKET_TRIGGERER, 77 groups = "my-awesome-project-tryjob-access", 78 ), 79 ], 80 ) 81 82 # The Milo console with all post-submit builders, referenced below. 83 luci.console_view( 84 name = "Main Console", 85 repo = REPO_URL, 86 ) 87 88 # The Milo builder list with all pre-submit builders, referenced below. 89 luci.list_view( 90 name = "Try Builders", 91 ) 92 93 # The CQ group with all pre-submit builders, referenced below. 94 luci.cq_group( 95 name = "Main CQ", 96 watch = cq.refset(REPO_URL), 97 user_limits = [ 98 cq.user_limit( 99 name = "user_limits_for_foo_and_bar", 100 users = ["foo@example.com"], 101 groups = ["bar"], 102 run = cq.run_limits(max_active = 60, reach_limit_msg = "foobar"), 103 ), 104 cq.user_limit( 105 name = "user_limits_for_committers", 106 groups = ["committers"], 107 run = cq.run_limits(max_active = 20), 108 ), 109 cq.user_limit( 110 name = "user_limits_for_third_party_devs", 111 users = [ 112 "partner_1@example.com", 113 "partner_2@example.com", 114 ], 115 groups = ["third_party_devs_all"], 116 ), 117 ], 118 user_limit_default = cq.user_limit( 119 name = "default_user_quota", 120 ), 121 post_actions = [ 122 cq.post_action_gerrit_label_votes( 123 name = "dry-run_verification_label", 124 conditions = [ 125 cq.post_action_triggering_condition( 126 mode = cq.MODE_DRY_RUN, 127 statuses = [cq.STATUS_SUCCEEDED], 128 ), 129 ], 130 labels = { 131 "CQ-Verified": 1, 132 }, 133 ), 134 cq.post_action_gerrit_label_votes( 135 name = "any-run-failures-and-cancellations", 136 conditions = [ 137 cq.post_action_triggering_condition( 138 mode = m, 139 statuses = [cq.STATUS_FAILED, cq.STATUS_CANCELLED], 140 ) 141 for m in [ 142 cq.MODE_DRY_RUN, 143 cq.MODE_FULL_RUN, 144 cq.MODE_NEW_PATCHSET_RUN, 145 ] 146 ], 147 labels = { 148 "Code-Review": -1, 149 "CQ-Verified": 0, 150 }, 151 ), 152 ], 153 tryjob_experiments = [ 154 cq.tryjob_experiment( 155 name = "infra.experiment.internal", 156 owner_group_allowlist = ["googler", "bot-accounts"], 157 ), 158 cq.tryjob_experiment( 159 name = "infra.experiment.public", 160 ), 161 ], 162 ) 163 164 # The gitiles poller: a source of commits that trigger CI builders. 165 luci.gitiles_poller( 166 name = "my-awesome-project-poller", 167 bucket = "ci", 168 repo = REPO_URL, 169 ) 170 171 def ci_builder(name, *, os, category, cpu = "x86-64"): 172 """Defines a post-submit builder. 173 174 Args: 175 name: name of the builder to define. 176 os: the target OS. 177 category: the category to put it under in the console. 178 cpu: the target CPU. 179 """ 180 recipe_id = "ci_builder" 181 182 luci.builder( 183 name = name, 184 bucket = "ci", 185 executable = luci.recipe( 186 name = recipe_id, 187 recipe = "ci_builder", 188 cipd_package = RECIPE_BUNDLE, 189 use_python3 = True, 190 ), 191 dimensions = { 192 "pool": "luci.my-awesome-project.ci", 193 "os": os, 194 "cpu": cpu, 195 }, 196 service_account = "my-ci-builder@chops-service-accounts.iam.gserviceaccount.com", 197 execution_timeout = 45 * time.minute, 198 # Run this builder on commits to REPO_URL. 199 triggered_by = ["my-awesome-project-poller"], 200 ) 201 202 # Add it to the console as well. 203 luci.console_view_entry( 204 builder = "ci/" + name, # disambiguate by prefixing the bucket name 205 console_view = "Main Console", 206 category = category, 207 ) 208 209 # Actually define a bunch of CI builders. 210 ci_builder("xenial", os = "Ubuntu-16.04", category = "Linux|16.04") 211 ci_builder("bionic", os = "Ubuntu-18.04", category = "Linux|18.04") 212 ci_builder("mac-10.13", os = "Mac-10.13", category = "Mac|10.13") 213 ci_builder( 214 "win-32", 215 os = "Windows", 216 cpu = "x86-32", 217 category = "Win|32", 218 ) 219 ci_builder("win-64", os = "Windows", cpu = "x86-64", category = "Win|64") 220 221 def try_builder(name, *, os, cpu = "x86-64"): 222 """Defines a pre-submit builder. 223 224 Args: 225 name: name of the builder to define. 226 os: the target OS. 227 cpu: the target CPU. 228 """ 229 recipe_id = "try_builder" 230 231 luci.builder( 232 name = name, 233 bucket = "try", 234 executable = luci.recipe( 235 name = recipe_id, 236 recipe = "try_builder", 237 cipd_package = RECIPE_BUNDLE, 238 use_python3 = True, 239 ), 240 dimensions = { 241 "pool": "luci.my-awesome-project.try", 242 "os": os, 243 "cpu": cpu, 244 }, 245 service_account = "my-try-builder@chops-service-accounts.iam.gserviceaccount.com", 246 execution_timeout = 45 * time.minute, 247 ) 248 249 # Add to the CQ. 250 luci.cq_tryjob_verifier( 251 builder = "try/" + name, 252 cq_group = "Main CQ", 253 ) 254 255 # And also to the pre-submit builders list. 256 luci.list_view_entry( 257 builder = "try/" + name, 258 list_view = "Try Builders", 259 ) 260 261 # Actually define a bunch of Try builders. 262 try_builder("xenial", os = "Ubuntu-16.04") 263 try_builder("bionic", os = "Ubuntu-18.04") 264 try_builder("mac-10.13", os = "Mac-10.13") 265 try_builder("win-32", os = "Windows", cpu = "x86-32") 266 try_builder("win-64", os = "Windows", cpu = "x86-64")