Skip to content

Commit

Permalink
fixes for the distinction
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJang27 committed Nov 14, 2023
1 parent 3e5de07 commit cc13a64
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ runs:
env:
MERGE_INSTANCE_BRANCH_HEAD_SHA:
${{ steps.prerequisites.outputs.merge_instance_branch_head_sha }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_head_sha }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_upload_head_sha }}
VERBOSE: ${{ inputs.verbose }}
WORKSPACE_PATH: ${{ steps.prerequisites.outputs.workspace_path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
Expand All @@ -132,7 +132,7 @@ runs:
REPOSITORY: ${{ github.repository }}
TARGET_BRANCH: ${{ steps.prerequisites.outputs.merge_instance_branch }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_SHA: ${{ steps.prerequisites.outputs.pr_branch_head_sha }}
PR_SHA: ${{ steps.prerequisites.outputs.pr_branch_upload_head_sha }}
IMPACTED_TARGETS_FILE:
${{ steps.compute-impacted-targets-upload.outputs.impacted_targets_out }}
IMPACTS_ALL_DETECTED: ${{ steps.prerequisites.outputs.impacts_all_detected }}
Expand All @@ -148,7 +148,7 @@ runs:
env:
# Use base sha instead of merge instance branch head sha for testing
MERGE_INSTANCE_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.merge_base_sha }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_head_sha }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_testing_head_sha }}
VERBOSE: ${{ inputs.verbose }}
WORKSPACE_PATH: ${{ steps.prerequisites.outputs.workspace_path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
Expand Down
21 changes: 13 additions & 8 deletions src/scripts/prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ else
merge_instance_branch_head_sha=$(git rev-parse "origin/${merge_instance_branch}")
fi

if ! pr_branch_head_sha=$(git rev-parse "${pr_branch}"); then
pr_branch_head_sha=$(git rev-parse "origin/${pr_branch}")
if ! pr_branch_upload_head_sha=$(git rev-parse "${pr_branch}"); then
pr_branch_upload_head_sha=$(git rev-parse "origin/${pr_branch}")
fi
# Testing head SHA varies because we want to use HEAD rather than github.head_ref to accurately detect targets that are actually present to be queryable/testable
pr_branch_testing_head_sha=$(git rev-parse "HEAD")

# When testing, we use the merge-base rather than the HEAD of the target branch
echo "Checking merge-base of PR Branch (${pr_branch_head_sha}) and merge branch (${merge_instance_branch_head_sha})"
echo "Checking testing merge-base of PR Branch (${pr_branch_testing_head_sha}) and merge branch (${merge_instance_branch_head_sha})"
merge_base_sha=$(git merge-base HEAD "${merge_instance_branch_head_sha}")
echo "Got merge-base: ${merge_base_sha}"

echo "Identified changes: " "${impacts_all_detected}"

Expand All @@ -86,10 +89,11 @@ fi
# Outputs
if [[ -v GITHUB_OUTPUT && -f ${GITHUB_OUTPUT} ]]; then
# trunk-ignore-begin(shellcheck/SC2129)
echo "merge_instance_branch=${merge_instance_branch}" >>"${GITHUB_OUTPUT}"
echo "merge_instance_branch_head_sha=${merge_instance_branch_head_sha}" >>"${GITHUB_OUTPUT}"
echo "merge_base_sha=${merge_base_sha}" >>"${GITHUB_OUTPUT}"
echo "pr_branch_head_sha=${pr_branch_head_sha}" >>"${GITHUB_OUTPUT}"
echo "merge_instance_branch=${merge_instance_branch}" >>"${GITHUB_OUTPUT}" # NOTE(TYLER): USED BY UPLOAD
echo "merge_instance_branch_head_sha=${merge_instance_branch_head_sha}" >>"${GITHUB_OUTPUT}" # NOTE(TYLER): USED BY BOTH COMPUTE
echo "merge_base_sha=${merge_base_sha}" >>"${GITHUB_OUTPUT}" # NOTE(TYLER): USED BY TESTING COMPUTE
echo "pr_branch_upload_head_sha=${pr_branch_upload_head_sha}" >>"${GITHUB_OUTPUT}" # NOTE(TYLER): USED BY BOTH COMPUTE AND UPLOAD -> upload and upload compute
echo "pr_branch_testing_head_sha=${pr_branch_testing_head_sha}" >>"${GITHUB_OUTPUT}" # NOTE(TYLER): USED BY TESTING COMPUTE
echo "impacts_all_detected=${impacts_all_detected}" >>"${GITHUB_OUTPUT}"
echo "workspace_path=${workspace_path}" >>"${GITHUB_OUTPUT}"
echo "requires_default_bazel_installation=${requires_default_bazel_installation}" >>"${GITHUB_OUTPUT}"
Expand All @@ -99,7 +103,8 @@ else
echo "::set-output name=merge_instance_branch::${merge_instance_branch}"
echo "::set-output name=merge_instance_branch_head_sha::${merge_instance_branch_head_sha}"
echo "::set-output name=merge_base_sha::${merge_base_sha}"
echo "::set-output name=pr_branch_head_sha::${pr_branch_head_sha}"
echo "::set-output name=pr_branch_upload_head_sha::${pr_branch_upload_head_sha}"
echo "::set-output name=pr_branch_testing_head_sha::${pr_branch_testing_head_sha}"
echo "::set-output name=impacts_all_detected::${impacts_all_detected}"
echo "::set-output name=workspace_path::${workspace_path}"
echo "::set-output name=requires_default_bazel_installation::${requires_default_bazel_installation}"
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/test_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ touch "${GITHUB_OUTPUT}"

# 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}")
PR_BRANCH_HEAD_SHA=$(awk -F "=" '$1=="pr_branch_head_sha" {print $2}' "${GITHUB_OUTPUT}")
PR_BRANCH_HEAD_SHA=$(awk -F "=" '$1=="pr_branch_testing_head_sha" {print $2}' "${GITHUB_OUTPUT}")
WORKSPACE_PATH=$(awk -F "=" '$1=="workspace_path" {print $2}' "${GITHUB_OUTPUT}")
BAZEL_DIFF_CMD=$(awk -F "=" '$1=="bazel_diff_cmd" {print $2}' "${GITHUB_OUTPUT}")

Expand Down

0 comments on commit cc13a64

Please sign in to comment.