From 023196df5fd70480bd5b1ccfb5c6d28bbdf821cf Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Wed, 18 Oct 2023 16:42:38 -0700 Subject: [PATCH 1/3] additional inputs --- action.yaml | 11 ++++++++++- src/scripts/test_impacted_targets.sh | 5 ++++- src/scripts/test_wrapper.sh | 10 +++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/action.yaml b/action.yaml index 670aa0f..e8c724d 100644 --- a/action.yaml +++ b/action.yaml @@ -44,16 +44,23 @@ inputs: description: Run bazel test on the computed targets. Recommended if running on PRs. required: false default: "true" + bazel-test-command: + description: The command to run against bazel when running tests. + required: false + default: test test-kind-filter: description: Kind filter to apply to impacted targets required: false default: .+_library|.+_binary|.+_test + test-scope-filter: + description: Scope filter to apply to impacted targets + required: false test-negative-kind-filter: description: Negative kind filter to apply to impacted targets required: false default: generated file test-negative-scope-filter: - description: Scope filter to apply to impacted targets + description: Negative scope filter to apply to impacted targets required: false default: //external @@ -158,8 +165,10 @@ runs: IMPACTED_TARGETS_FILE: ${{ steps.compute-impacted-targets-test.outputs.impacted_targets_out }} BAZEL_PATH: ${{ inputs.bazel-path }} + BAZEL_TEST_COMMAND: ${{ inputs.bazel-test-command }} BAZEL_STARTUP_OPTIONS: ${{ inputs.bazel-startup-options }} BAZEL_KIND_FILTER: ${{ inputs.test-kind-filter }} + BAZEL_SCOPE_FILTER: ${{ inputs.test-scope-filter }} BAZEL_NEGATIVE_KIND_FILTER: ${{ inputs.test-negative-kind-filter }} BAZEL_NEGATIVE_SCOPE_FILTER: ${{ inputs.test-negative-scope-filter }} CI: "true" diff --git a/src/scripts/test_impacted_targets.sh b/src/scripts/test_impacted_targets.sh index 11c93f1..44363f8 100755 --- a/src/scripts/test_impacted_targets.sh +++ b/src/scripts/test_impacted_targets.sh @@ -33,6 +33,9 @@ exec 3>"${tempdir}/query.txt" echo "let targets = set(" >&3 sed -e "s/^/'/g" -e "s/\$/'/g" <"${IMPACTED_TARGETS_FILE}" >&3 echo ") in" >&3 +if [[ -n ${BAZEL_SCOPE_FILTER} ]]; then + echo "let targets = filter('${BAZEL_SCOPE_FILTER}', \$targets) in" >&3 +fi echo "let targets = kind('${BAZEL_KIND_FILTER}', \$targets) in" >&3 # trunk-ignore(shellcheck/SC2016) echo '$targets' >&3 @@ -71,7 +74,7 @@ echo -e "${info_color}Running bazel test on ${target_count} targets...${reset}" echo ret=0 -_bazel "test" --test_tag_filters=-manual --target_pattern_file="${tempdir}/filtered_targets.txt" "$@" || ret=$? +_bazel "${BAZEL_TEST_COMMAND}" --target_pattern_file="${tempdir}/filtered_targets.txt" || ret=$? # Exit code 4 from bazel test means: Build successful but no tests were found even though testing was requested. # This is ok since this change may legitimately cause no test targets to run. diff --git a/src/scripts/test_wrapper.sh b/src/scripts/test_wrapper.sh index 3e718b1..86ba708 100755 --- a/src/scripts/test_wrapper.sh +++ b/src/scripts/test_wrapper.sh @@ -2,7 +2,7 @@ set -euo pipefail -# TODO: TYLER CONSIDER BEHAVIOR WITH FORKS +# TODO(TYLER): Support forks ################################################## ##### Handle Command Line Flags and Defaults ##### @@ -77,9 +77,7 @@ GITHUB_OUTPUT="${tempdir}/bazel_action_prerequisites.txt" rm -f "${GITHUB_OUTPUT}" touch "${GITHUB_OUTPUT}" -echo "RUNNING PREREQS" # TODO: REMOVE . "${scripts_dir}/prerequisites.sh" -echo "DONE WITH PREREQS" # TODO: REMOVE # Use merge base sha instead of merge head sha to calculate the correct diff for testing. MERGE_INSTANCE_BRANCH_HEAD_SHA=$(awk -F "=" '$1=="merge_base_sha" {print $2}' "${GITHUB_OUTPUT}") @@ -95,18 +93,16 @@ GITHUB_OUTPUT="${tempdir}/bazel_action_compute.txt" rm -f "${GITHUB_OUTPUT}" touch "${GITHUB_OUTPUT}" -echo "RUNNING COMPUTE TARGETS" # TODO: REMOVE . "${scripts_dir}/compute_impacted_targets.sh" -echo "DONE WITH COMPUTE TARGETS" # TODO: REMOVE IMPACTED_TARGETS_FILE=$(awk -F "=" '$1=="impacted_targets_out" {print $2}' "${GITHUB_OUTPUT}") +BAZEL_TEST_COMMAND="test" BAZEL_KIND_FILTER=".+_library|.+_binary|.+_test" +BAZEL_SCOPE_FILTER="" BAZEL_NEGATIVE_KIND_FILTER="generated file" BAZEL_NEGATIVE_SCOPE_FILTER="//external" ################################### ##### Filter and Test targets ##### ################################### -echo "RUNNING TESTING TARGETS" # TODO: REMOVE . "${scripts_dir}/test_impacted_targets.sh" -echo "DONE WITH TESTING TARGETS" # TODO: REMOVE From 08789541591732d856ccc95d7a800d3f5feb8a12 Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Wed, 18 Oct 2023 16:43:44 -0700 Subject: [PATCH 2/3] add disclaimer --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index dd03801..5b36c10 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # bazel-action +** Note: This repository is currently in a Work In Progress state. We will publicize information +about its proper usage when it is ready. ** + Provides a GitHub Action for computing, uploading, and testing bazel targets. Functions as an extension to the [Trunk Merge GitHub Action](https://github.com/trunk-io/merge-action). To get beta access to the Merge Graph, contact us on [Slack](https://slack.trunk.io). From 483addc32dd985b15fbd83c679d4dc93b0447c8a Mon Sep 17 00:00:00 2001 From: Tyler Jang Date: Wed, 18 Oct 2023 17:11:55 -0700 Subject: [PATCH 3/3] update required --- action.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index e8c724d..a211fae 100644 --- a/action.yaml +++ b/action.yaml @@ -4,8 +4,10 @@ description: Trunk.io Github Action to Compute, Upload, and Test Impacted Target inputs: trunk-token: - description: Repo API token used for authentication. Can be found at app.trunk.io. - required: true + description: + Repo API token used for authentication. Can be found at app.trunk.io. Required if + upload-targets + required: false target-branch: description: The Merge Instance's target branch. If unspecified, defaults to the repository's default