Skip to content

Commit

Permalink
Merge pull request #4 from trunk-io/tyler/support-dogfooding
Browse files Browse the repository at this point in the history
Support dogfooding
  • Loading branch information
TylerJang27 authored Oct 20, 2023
2 parents 846f7a7 + 483addc commit 5a309c2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
17 changes: 14 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,16 +46,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

Expand Down Expand Up @@ -158,8 +167,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"
5 changes: 4 additions & 1 deletion src/scripts/test_impacted_targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 3 additions & 7 deletions src/scripts/test_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

# TODO: TYLER CONSIDER BEHAVIOR WITH FORKS
# TODO(TYLER): Support forks

##################################################
##### Handle Command Line Flags and Defaults #####
Expand Down Expand Up @@ -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}")
Expand All @@ -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

0 comments on commit 5a309c2

Please sign in to comment.