-
Notifications
You must be signed in to change notification settings - Fork 112
use delegating shard tasks for connectedCheck
#1025
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
Conversation
9ff304a to
037e21d
Compare
037e21d to
ebb3533
Compare
build-logic/src/main/java/com/squareup/workflow1/buildsrc/shardConnectedChecks.kt
Outdated
Show resolved
Hide resolved
| sortedProjects.groupBy { (shardIndex++ % shardCount) + 1 } | ||
| } | ||
|
|
||
| (1..shardCount).map { shardIndex -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have an off by one error and some boundary tests fall between the cracks, how will we notice that shard1 + shard2 + shard3 < allShards? Wondering if there's an invariant check we can put somewhere. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extract a core of this routine so that you can unit test it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't (and still don't) want to introduce unit tests to build-logic, since the tasks for an included build are not hooked into Gradle's implicit task delegation by default.
For example, if we invoke ./gradlew test today, it'll invoke all unit tests in kotlin-jvm modules. We just expect that to work. But that hook (implicit task delegation) only applies to sub-projects. The build-logic build is not affected by this, so its test task would never be invoked.
We can manually stitch things together, such as with this in the root build.gradle.kts:
tasks.named("test") {
dependsOn(gradle.includedBuild("build-logic").task(":test"))
}...but if anything were to happen to that, then the sharding could break in the way you described and no one would be the wiser.
So, instead I refactored it to be as off-by-one-proof as I could. As the tasks are configuring, they assert that the shard allocations total up to the exact number of Android projects and there are no duplicates. So they test themselves every time they're used.
ce5cb0e to
416bd38
Compare
c8a4831 to
3cd2645
Compare
3078059 to
2f28d16
Compare
These shard tasks collectively depend upon all Android `connectedCheck` tasks in the entire project. Each shard depends upon the `connectedCheck` tasks of some subset of Android projects. Projects are assigned to a shard by counting the number of `@Test` annotations within their `androidTest` directory, then associating those projects to a shard in a round-robin fashion. These shards are invoked in CI using a GitHub Actions matrix. If the number of shards changes, the `connectedCheckShardMatrixYamlUpdate` task can automatically update the workflow file so that they're all invoked. The shard tasks are invoked as: ```shell # roughly 1/3 of the tests ./gradlew connectedCheckShard1 # the second third ./gradlew connectedCheckShard2 # the last third ./gradlew connectedCheckShard3 ``` The task filtering we currently use in CI (`./gradlew fooShard1 -x :my-project:foo`) will still work here, however the "cost" of the excluded task's tests is still accounted for when the sharding is performed.
… keys when there's a miss
2f28d16 to
0c0cbb3
Compare
These shard tasks collectively depend upon all Android
connectedChecktasks in the entire project.Each shard depends upon the
connectedChecktasks of some subset of Android projects. Projects are assigned to a shard by counting the number of@Testannotations within theirandroidTestdirectory, then associating those projects to a shard in a round-robin fashion.These shards are invoked in CI using a matrix. If the number of shards changes, the
connectedCheckShardMatrixYamlUpdatetask can automatically update the workflow file so that they're all invoked.The shard tasks are invoked as:
The task filtering we currently use in CI (
./gradlew fooShard1 -x :my-project:foo) will still work here, however the "cost" of the excluded task's tests is still accounted for when the sharding is performed.