Skip to content

Commit

Permalink
Fix running ./gradlew tasks (#11692)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Jun 28, 2024
1 parent 3cf1a90 commit 01210df
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,56 +49,56 @@ if (project.findProperty("skipTests") as String? == "true") {
}
}

tasks {
val listTestsInPartition by registering {
group = "Help"
description = "List test tasks in given partition"

// total of 4 partitions (see modulo 4 below)
var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
if (testPartition == null) {
throw GradleException("Test partition must be specified")
} else if (testPartition < 0 || testPartition >= 4) {
throw GradleException("Invalid test partition")
}
if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
tasks {
val listTestsInPartition by registering {
group = "Help"
description = "List test tasks in given partition"

// total of 4 partitions (see modulo 4 below)
var testPartition = (project.findProperty("testPartition") as String?)?.toInt()
if (testPartition == null) {
throw GradleException("Test partition must be specified")
} else if (testPartition < 0 || testPartition >= 4) {
throw GradleException("Invalid test partition")
}

val partitionTasks = ArrayList<Test>()
var testPartitionCounter = 0
subprojects {
// relying on predictable ordering of subprojects
// (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
// since we are splitting these tasks across different github action jobs
val enabled = testPartitionCounter++ % 4 == testPartition
if (enabled) {
tasks.withType<Test>().configureEach {
partitionTasks.add(this)
val partitionTasks = ArrayList<Test>()
var testPartitionCounter = 0
subprojects {
// relying on predictable ordering of subprojects
// (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4)
// since we are splitting these tasks across different github action jobs
val enabled = testPartitionCounter++ % 4 == testPartition
if (enabled) {
tasks.withType<Test>().configureEach {
partitionTasks.add(this)
}
}
}
}

doLast {
File("test-tasks.txt").printWriter().use { writer ->
partitionTasks.forEach { task ->
var taskPath = task.project.path + ":" + task.name
// smoke tests are run separately
// :instrumentation:test runs all instrumentation tests
if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
writer.println(taskPath)
doLast {
File("test-tasks.txt").printWriter().use { writer ->
partitionTasks.forEach { task ->
var taskPath = task.project.path + ":" + task.name
// smoke tests are run separately
// :instrumentation:test runs all instrumentation tests
if (taskPath != ":smoke-tests:test" && taskPath != ":instrumentation:test") {
writer.println(taskPath)
}
}
}
}
}

// disable all tasks to stop build
subprojects {
tasks.configureEach {
enabled = false
// disable all tasks to stop build
subprojects {
tasks.configureEach {
enabled = false
}
}
}
}
}

if (gradle.startParameter.taskNames.any { it.equals("listTestsInPartition") }) {
// disable all tasks to stop build
project.tasks.configureEach {
if (this.name != "listTestsInPartition") {
Expand Down

0 comments on commit 01210df

Please sign in to comment.