Skip to content

Commit

Permalink
feat: Additional Verbose Logging (#21)
Browse files Browse the repository at this point in the history
Additional verbose logging when computing impacted targets.
 - bazel version
 - bazel-diff version
 - verbose bazel-diff logging
  • Loading branch information
nikhilbirmiwal authored Aug 29, 2023
1 parent db398cb commit 42a6391
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/scripts/compute_impacted_targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ logIfVerbose() {
ifVerbose echo "$(date -u)" "$@"
}

bazelDiff() {
if [[ -n ${VERBOSE} ]]; then
java -jar bazel-diff.jar "$@" --verbose
else
java -jar bazel-diff.jar "$@"
fi
}

# NOTE: We cannot assume that the checked out Git repo (e.g. via actions-checkout)
# was a shallow vs a complete clone. The `--depth` options deepens the commit history
# in both clone modes: https://git-scm.com/docs/fetch-options#Documentation/fetch-options.txt---depthltdepthgt
Expand All @@ -37,6 +45,8 @@ fetchRemoteGitHistory "${PR_BRANCH}"

# Install the bazel-diff JAR. Avoid cloning the repo, as there will be conflicting WORKSPACES.
curl --retry 5 -Lo bazel-diff.jar https://github.com/Tinder/bazel-diff/releases/latest/download/bazel-diff_deploy.jar
java -jar bazel-diff.jar -V
bazel --version

git switch "${MERGE_INSTANCE_BRANCH}"
merge_instance_branch_head_sha=$(git rev-parse "${MERGE_INSTANCE_BRANCH}")
Expand Down Expand Up @@ -71,14 +81,14 @@ impacted_targets_out=./impacted_targets_${pr_branch_head_sha}

# Generate Hashes for the Merge Instance Branch
git switch "${MERGE_INSTANCE_BRANCH}"
java -jar bazel-diff.jar generate-hashes --workspacePath="${WORKSPACE_PATH}" "${merge_instance_branch_out}"
bazelDiff generate-hashes --workspacePath="${WORKSPACE_PATH}" "${merge_instance_branch_out}"

# Generate Hashes for the Merge Instance Branch + PR Branch
git -c "user.name=Trunk Actions" -c "[email protected]" merge --squash "${PR_BRANCH}"
java -jar bazel-diff.jar generate-hashes --workspacePath="${WORKSPACE_PATH}" "${merge_instance_with_pr_branch_out}"
bazelDiff generate-hashes --workspacePath="${WORKSPACE_PATH}" "${merge_instance_with_pr_branch_out}"

# Compute impacted targets
java -jar bazel-diff.jar get-impacted-targets --startingHashes="${merge_instance_branch_out}" --finalHashes="${merge_instance_with_pr_branch_out}" --output="${impacted_targets_out}"
bazelDiff get-impacted-targets --startingHashes="${merge_instance_branch_out}" --finalHashes="${merge_instance_with_pr_branch_out}" --output="${impacted_targets_out}"

num_impacted_targets=$(wc -l <"${impacted_targets_out}")
echo "Computed ${num_impacted_targets} targets for sha ${pr_branch_head_sha}"
Expand Down

0 comments on commit 42a6391

Please sign in to comment.