Skip to content

Commit

Permalink
Adding workflow_run to trigger coverage workflow only when unit tests…
Browse files Browse the repository at this point in the history
… are completed
  • Loading branch information
Rd4dev committed Jul 22, 2024
1 parent b266e48 commit 15061ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ name: Code Coverage
# Controls when the action will run. Triggers the workflow on pull request
# events or push events in the develop branch.
on:
workflow_run:
workflows: ["Unit Tests (Robolectric - Bazel)"]
types:
- completed
workflow_dispatch:
pull_request:
push:
branches:
# Push events on develop branch
- develop
# pull_request:
# push:
# branches:
# # Push events on develop branch
# - develop

jobs:
compute_changed_files:
Expand Down
46 changes: 12 additions & 34 deletions scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ class BazelClient(private val rootDirectory: File, private val commandExecutor:
"attr(name, $targetName, $targetPath)",
"--output=build",
)
println("BUILD: $buildRule")
println("BUILD has shard count: ${buildRule.any { "shard_count" in it }}")
// println("BUILD: $buildRule")
// println("BUILD has shard count: ${buildRule.any { "shard_count" in it }}")

println("Printing for the bazel test target: $bazelTestTarget")
// println("Printing for the bazel test target: $bazelTestTarget")
// println(File(rootDirectory,"/bazel-out/_coverage/_coverage_report.dat").exists())
// println(File(rootDirectory,"/bazel-out/_coverage/_coverage_report.dat").readText())
/*return parseCoverageDataFilePath(coverageCommandOutputLines)?.let { path ->
Expand All @@ -174,47 +174,25 @@ class BazelClient(private val rootDirectory: File, private val commandExecutor:

val hasShardCount = buildRule.any { "shard_count" in it }
if (hasShardCount) {
println("In has Shard count")
val coverageCommandOutputLines = executeBazelCommand(
// executeBazelCommand(
// println("In has Shard count")
// val coverageCommandOutputLines = executeBazelCommand(
executeBazelCommand(
"test",
"--collect_code_coverage",
"--combined_report=lcov",
bazelTestTarget,
"--instrumentation_filter=$computeInstrumentation"
)
println(
/*println(
"Coverage command output lines " +
"with bazel tests --collect coverage: $coverageCommandOutputLines"
)

val regex = """(.*/shard_\d+_of_\d+/coverage\.dat)""".toRegex()
val shardCoveragePaths = coverageCommandOutputLines
.flatMap { regex.findAll(it).map { matchResult ->
matchResult.value.trim()
}
}

println("Shard coverage path: $shardCoveragePaths")

val lcovCommand = buildString {
append("lcov ")
shardCoveragePaths.forEach { path ->
append("--add-tracefile $path ")
}
append("--output-file ${rootDirectory}/coverage_reports/lcov_combined.dat")
}

val process = ProcessBuilder(*lcovCommand.split(" ").toTypedArray())
.redirectErrorStream(true)
.start()

val output = process.inputStream.bufferedReader().readText()
println("Output: $output")
)*/

return File(rootDirectory, "/bazel-out/_coverage/_coverage_report.dat").readLines()
return File(rootDirectory, "/bazel-out/_coverage/_coverage_report.dat")
.takeIf { it.exists() && it.isFile }
?.readLines()
} else {
println("In does not have Shard count")
// println("In does not have Shard count")
val coverageCommandOutputLines = executeBazelCommand(
// executeBazelCommand(
"coverage",
Expand Down

0 comments on commit 15061ba

Please sign in to comment.