Skip to content

Commit

Permalink
Introduced a new utility just to retrieve the test targets for the se…
Browse files Browse the repository at this point in the history
…t of changed files provided

Since the code coverages take a long time, it should be possible that the builds are taking the most times which cause process didn't finish within intended time errors. So may be having the build oppia tests beforehand should help with this, but since we use just the changed files for the input to our run coverage scripts we will need this extra utility (or if possible lets try to move it with something else if possible retrieve changed files.kt) to handle the mapping of changed files to their respective targets to feed to build them
  • Loading branch information
Rd4dev committed Jul 19, 2024
1 parent 357cc5d commit 707a749
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ jobs:
echo "FILE_CACHING_BUCKET=$FILE_CATEGORY" >> $GITHUB_ENV
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
- name: Extract test caching bucket & changed files test targets
env:
CHANGED_FILESS_BUCKET_BASE64_ENCODED_SHARD: ${{ matrix.changed-files-bucket-base64-encoded-shard }}
run: |
# See https://stackoverflow.com/a/29903172 for cut logic. This is needed to remove the
# user-friendly shard prefix from the matrix value.
CHANGED_FILES_TEST_TARGETS_BUCKET_BASE64=$(echo "$CHANGED_FILESS_BUCKET_BASE64_ENCODED_SHARD" | cut -d ";" -f 2)
bazel run //scripts:retrieve_changed_files_test_targets -- $(pwd) $CHANGED_FILES_TEST_TARGETS_BUCKET_BASE64 $(pwd)/test_bucket_name $(pwd)/bazel_test_targets
TEST_CATEGORY=$(cat ./test_bucket_name)
BAZEL_TEST_TARGETS=$(cat ./bazel_test_targets)
echo "Test category: $TEST_CATEGORY"
echo "Bazel test targets: $BAZEL_TEST_TARGETS"
echo "TEST_CACHING_BUCKET=$TEST_CATEGORY" >> $GITHUB_ENV
echo "BAZEL_TEST_TARGETS=$BAZEL_TEST_TARGETS" >> $GITHUB_ENV
# For reference on this & the later cache actions, see:
# https://github.com/actions/cache/issues/239#issuecomment-606950711 &
# https://github.com/actions/cache/issues/109#issuecomment-558771281. Note that these work
Expand Down
7 changes: 7 additions & 0 deletions scripts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ kt_jvm_binary(
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/ci:retrieve_changed_files_lib"],
)

kt_jvm_binary(
name = "retrieve_changed_files_test_targets",
testonly = True,
main_class = "org.oppia.android.scripts.ci.RetrieveChangedFilesTestTargetsKt",
runtime_deps = ["//scripts/src/java/org/oppia/android/scripts/ci:retrieve_changed_files_test_targets_lib"],
)

# TODO(#3428): Refactor textproto assets to subpackage level.
REGEX_PATTERN_CHECK_ASSETS = generate_regex_assets_list_from_text_protos(
name = "regex_asset_files",
Expand Down
14 changes: 14 additions & 0 deletions scripts/src/java/org/oppia/android/scripts/ci/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ kt_jvm_library(
"//scripts/src/java/org/oppia/android/scripts/proto:changed_files_java_proto",
],
)

kt_jvm_library(
name = "retrieve_changed_files_test_targets_lib",
testonly = True,
srcs = [
"RetrieveChangedFilesTestTargets.kt",
],
visibility = ["//scripts:oppia_script_binary_visibility"],
deps = [
"//scripts/src/java/org/oppia/android/scripts/common:bazel_client",
"//scripts/src/java/org/oppia/android/scripts/common:proto_string_encoder",
"//scripts/src/java/org/oppia/android/scripts/proto:changed_files_java_proto",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.oppia.android.scripts.ci

import org.oppia.android.scripts.common.BazelClient
import org.oppia.android.scripts.common.CommandExecutor
import org.oppia.android.scripts.common.CommandExecutorImpl
import org.oppia.android.scripts.common.ProtoStringEncoder.Companion.mergeFromCompressedBase64
import org.oppia.android.scripts.proto.ChangedFilesBucket
import java.io.File
import java.util.Locale
import java.util.concurrent.TimeUnit
import kotlin.system.exitProcess

/**
* The main entrypoint for retrieving the list of changed files from a particular encoded Base64
* bucket. This is used to parse the output from compute_changed_files.
*
* Usage:
* bazel run //scripts:retrieve_changed_files -- \\
* <encoded_proto_in_base64> <path_to_bucket_name_output_file> \\
* <path_to_file_list_output_file>
*
* Arguments:
* - encoded_proto_in_base64: the compressed & Base64-encoded [ChangedFilesBucket] proto computed
* by compute_changed_files.
* - path_to_bucket_name_output_file: path to the file where the file bucket name corresponding to
* this bucket should be printed.
* - path_to_file_list_output_file: path to the file where the list of changed files
* corresponding to this bucket should be printed.
*
* Example:
* bazel run //scripts:retrieve_changed_files -- $(pwd) $CHANGED_FILES_BUCKETS_BASE64_ENCODED_PROTO \\
* $(pwd)/file_bucket_name $(pwd)/changed_files
*/
fun main(args: Array<String>) {
/*if (args.size < 3) {
println(
"Usage: bazel run //scripts:retrieve_changed_files --" +
" <encoded_proto_in_base64> <path_to_bucket_name_output_file>" +
" <path_to_file_list_output_file>"
)
exitProcess(1)
}*/

val rootDirectory = File(args[0]).absoluteFile
val protoBase64 = args[1]
val bucketNameOutputFile = File(args[2])
val fileTestTargetsListOutputFile = File(args[3])

val commandExecutor: CommandExecutor =
CommandExecutorImpl(
scriptBgDispatcher, processTimeout = 5, processTimeoutUnit = TimeUnit.MINUTES
)

val bazelClient = BazelClient(rootDirectory, commandExecutor)

val changedFilesBucket =
ChangedFilesBucket.getDefaultInstance().mergeFromCompressedBase64(protoBase64)
bucketNameOutputFile.printWriter().use { writer ->
writer.println(changedFilesBucket.cacheBucketName)
}

val changedFilesTestTargets = bazelClient.retrieveBazelTargets(changedFilesBucket.changedFilesList)
println("Changed Files Test Targets: $changedFilesTestTargets")

fileTestTargetsListOutputFile.printWriter().use { writer ->
writer.println(changedFilesTestTargets.joinToString(separator = " "))
}
}

0 comments on commit 707a749

Please sign in to comment.