Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running ./gradlew tasks #11692

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading