[infra] Run presubmit like a normal bot

Bug: skia:
Change-Id: If01c10c21477bd61c4ec1d4f59921745eb3bf494
Reviewed-on: https://skia-review.googlesource.com/123622
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Commit-Queue: Eric Boren <borenet@google.com>
diff --git a/infra/bots/gen_tasks.go b/infra/bots/gen_tasks.go
index cbbe336..67e551a 100644
--- a/infra/bots/gen_tasks.go
+++ b/infra/bots/gen_tasks.go
@@ -1051,6 +1051,38 @@
 	return name
 }
 
+// Run the presubmit.
+func presubmit(b *specs.TasksCfgBuilder, name string) string {
+	extraProps := map[string]string{
+		"category":         "cq",
+		"patch_gerrit_url": "https://skia-review.googlesource.com",
+		"patch_project":    "skia",
+		"patch_ref":        fmt.Sprintf("refs/changes/%s/%s/%s", specs.PLACEHOLDER_ISSUE_SHORT, specs.PLACEHOLDER_ISSUE, specs.PLACEHOLDER_PATCHSET),
+		"reason":           "CQ",
+		"repo_name":        "skia",
+	}
+	task := kitchenTask(name, "run_presubmit", "empty.isolate", SERVICE_ACCOUNT_COMPILE, linuxGceDimensions(), extraProps, OUTPUT_NONE)
+
+	replaceArg := func(key, value string) {
+		found := false
+		for idx, arg := range task.Command {
+			if arg == key {
+				task.Command[idx+1] = value
+				found = true
+			}
+		}
+		if !found {
+			task.Command = append(task.Command, key, value)
+		}
+	}
+	replaceArg("-repository", "https://chromium.googlesource.com/chromium/tools/build")
+	replaceArg("-revision", "HEAD")
+	task.CipdPackages = append(task.CipdPackages, CIPD_PKGS_GIT...)
+	task.Dependencies = []string{} // No bundled recipes for this one.
+	b.MustAddTask(name, task)
+	return name
+}
+
 // process generates tasks and jobs for the given job name.
 func process(b *specs.TasksCfgBuilder, name string) {
 	deps := []string{}
@@ -1112,6 +1144,7 @@
 		name != "Housekeeper-PerCommit-BundleRecipes" &&
 		name != "Housekeeper-PerCommit-InfraTests" &&
 		name != "Housekeeper-PerCommit-CheckGeneratedFiles" &&
+		name != "Housekeeper-OnDemand-Presubmit" &&
 		!strings.Contains(name, "Android_Framework") &&
 		!strings.Contains(name, "RecreateSKPs") &&
 		!strings.Contains(name, "-CT_") &&
@@ -1129,6 +1162,9 @@
 	if name == "Housekeeper-PerCommit-CheckGeneratedFiles" {
 		deps = append(deps, checkGeneratedFiles(b, name))
 	}
+	if name == "Housekeeper-OnDemand-Presubmit" {
+		deps = append(deps, presubmit(b, name))
+	}
 	if strings.Contains(name, "Bookmaker") {
 		deps = append(deps, bookmaker(b, name, compileTaskName))
 	}
@@ -1196,6 +1232,8 @@
 		j.Trigger = specs.TRIGGER_WEEKLY
 	} else if strings.Contains(name, "Flutter") || strings.Contains(name, "PDFium") || strings.Contains(name, "CommandBuffer") {
 		j.Trigger = specs.TRIGGER_MASTER_ONLY
+	} else if strings.Contains(name, "-OnDemand-") {
+		j.Trigger = specs.TRIGGER_ON_DEMAND
 	}
 	b.MustAddJob(name, j)
 }
diff --git a/infra/bots/jobs.json b/infra/bots/jobs.json
index 25786d9..d840bdf 100644
--- a/infra/bots/jobs.json
+++ b/infra/bots/jobs.json
@@ -105,6 +105,7 @@
   "Calmbench-Ubuntu17-Clang-Golo-GPU-QuadroP400-x86_64-Release-All",
   "Housekeeper-Nightly-Bookmaker",
   "Housekeeper-Nightly-RecreateSKPs_Canary",
+  "Housekeeper-OnDemand-Presubmit",
   "Housekeeper-PerCommit",
   "Housekeeper-PerCommit-Bookmaker",
   "Housekeeper-PerCommit-BundleRecipes",
diff --git a/infra/bots/tasks.json b/infra/bots/tasks.json
index 27286c1..d9a1556 100644
--- a/infra/bots/tasks.json
+++ b/infra/bots/tasks.json
@@ -643,6 +643,13 @@
       ],
       "trigger": "nightly"
     },
+    "Housekeeper-OnDemand-Presubmit": {
+      "priority": 0.8,
+      "tasks": [
+        "Housekeeper-OnDemand-Presubmit"
+      ],
+      "trigger": "on demand"
+    },
     "Housekeeper-PerCommit": {
       "priority": 0.8,
       "tasks": [
@@ -15042,6 +15049,109 @@
       "priority": 0.8,
       "service_account": "skia-recreate-skps@skia-swarming-bots.iam.gserviceaccount.com"
     },
+    "Housekeeper-OnDemand-Presubmit": {
+      "cipd_packages": [
+        {
+          "name": "infra/tools/luci/kitchen/${platform}",
+          "path": ".",
+          "version": "git_revision:206b4474cb712bdad8b7b3f213880cfbf03f120c"
+        },
+        {
+          "name": "infra/tools/authutil/${platform}",
+          "path": "cipd_bin_packages",
+          "version": "git_revision:9c63809842a277ce10a86afd51b61c639a665d11"
+        },
+        {
+          "name": "infra/tools/luci/vpython/${platform}",
+          "path": "cipd_bin_packages",
+          "version": "git_revision:d0130097bd6364a8d834cb9efd4554c1f6192c82"
+        },
+        {
+          "name": "infra/git/${platform}",
+          "path": "cipd_bin_packages",
+          "version": "version:2.15.0.chromium12"
+        },
+        {
+          "name": "infra/tools/git/${platform}",
+          "path": "cipd_bin_packages",
+          "version": "git_revision:fa7a52f4741f5e04bba0dfccc9b8456dc572c60b"
+        },
+        {
+          "name": "infra/tools/luci/git-credential-luci/${platform}",
+          "path": "cipd_bin_packages",
+          "version": "git_revision:d0130097bd6364a8d834cb9efd4554c1f6192c82"
+        }
+      ],
+      "command": [
+        "./kitchen${EXECUTABLE_SUFFIX}",
+        "cook",
+        "-checkout-dir",
+        "recipe_bundle",
+        "-mode",
+        "swarming",
+        "-luci-system-account",
+        "system",
+        "-cache-dir",
+        "cache",
+        "-temp-dir",
+        "tmp",
+        "-known-gerrit-host",
+        "android.googlesource.com",
+        "-known-gerrit-host",
+        "boringssl.googlesource.com",
+        "-known-gerrit-host",
+        "chromium.googlesource.com",
+        "-known-gerrit-host",
+        "dart.googlesource.com",
+        "-known-gerrit-host",
+        "fuchsia.googlesource.com",
+        "-known-gerrit-host",
+        "go.googlesource.com",
+        "-known-gerrit-host",
+        "llvm.googlesource.com",
+        "-known-gerrit-host",
+        "pdfium.googlesource.com",
+        "-known-gerrit-host",
+        "skia.googlesource.com",
+        "-known-gerrit-host",
+        "webrtc.googlesource.com",
+        "-output-result-json",
+        "${ISOLATED_OUTDIR}/build_result_filename",
+        "-workdir",
+        ".",
+        "-recipe",
+        "run_presubmit",
+        "-properties",
+        "{\"$kitchen\":{\"devshell\":true,\"git_auth\":true},\"buildbucket_build_id\":\"<(BUILDBUCKET_BUILD_ID)\",\"buildername\":\"Housekeeper-OnDemand-Presubmit\",\"category\":\"cq\",\"patch_gerrit_url\":\"https://skia-review.googlesource.com\",\"patch_issue\":\"<(ISSUE)\",\"patch_project\":\"skia\",\"patch_ref\":\"refs/changes/<(ISSUE_SHORT)/<(ISSUE)/<(PATCHSET)\",\"patch_repo\":\"<(PATCH_REPO)\",\"patch_set\":\"<(PATCHSET)\",\"patch_storage\":\"<(PATCH_STORAGE)\",\"reason\":\"CQ\",\"repo_name\":\"skia\",\"repository\":\"<(REPO)\",\"revision\":\"<(REVISION)\",\"swarm_out_dir\":\"output_ignored\"}",
+        "-logdog-annotation-url",
+        "logdog://logs.chromium.org/skia/<(TASK_ID)/+/annotations",
+        "-repository",
+        "https://chromium.googlesource.com/chromium/tools/build",
+        "-revision",
+        "HEAD"
+      ],
+      "dimensions": [
+        "cpu:x86-64-Haswell_GCE",
+        "gpu:none",
+        "os:Debian-9.4",
+        "pool:Skia"
+      ],
+      "env_prefixes": {
+        "PATH": [
+          "cipd_bin_packages",
+          "cipd_bin_packages/bin"
+        ],
+        "VPYTHON_VIRTUALENV_ROOT": [
+          "${cache_dir}/vpython"
+        ]
+      },
+      "extra_tags": {
+        "log_location": "logdog://logs.chromium.org/skia/<(TASK_ID)/+/annotations"
+      },
+      "isolate": "empty.isolate",
+      "priority": 0.8,
+      "service_account": "skia-external-compile-tasks@skia-swarming-bots.iam.gserviceaccount.com"
+    },
     "Housekeeper-PerCommit": {
       "cipd_packages": [
         {
diff --git a/infra/branch-config/cq.cfg b/infra/branch-config/cq.cfg
index ffb121f..9c5ce84 100644
--- a/infra/branch-config/cq.cfg
+++ b/infra/branch-config/cq.cfg
@@ -27,10 +27,6 @@
       builders { name: "mac_chromium_compile_dbg_ng" }
     }
     buckets {
-      name: "skia.swarmbucket"
-      builders { name: "Skia Presubmit" }
-    }
-    buckets {
       name: "skia.primary"
       builders { name: "Build-Debian9-Clang-arm-Debug-Android" }
       builders { name: "Build-Debian9-Clang-arm-Release-Android_API26" }
@@ -44,6 +40,7 @@
       builders { name: "Build-Win-Clang-x86-Debug" }
       builders { name: "Build-Win-Clang-x86_64-Release-Vulkan" }
       builders { name: "Build-Win-MSVC-x86_64-Release-Vulkan" }
+      builders { name: "Housekeeper-OnDemand-Presubmit" }
       builders { name: "Housekeeper-PerCommit-Bookmaker" }
       builders { name: "Housekeeper-PerCommit-InfraTests" }
       builders { name: "Perf-Debian9-Clang-GCE-CPU-AVX2-x86-Debug-All" }