Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favor using PR SHA instead of PR Branch for impacted target calculations #46

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ runs:
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
TARGET_BRANCH: ${{ inputs.target-branch }}
PR_BRANCH: ${{ github.head_ref }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
WORKSPACE_PATH: ${{ inputs.bazel-workspace-path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
IMPACTS_FILTERS_CHANGES: ${{ steps.detect-changed-paths.outputs.changes }}
Expand All @@ -80,8 +80,7 @@ runs:
MERGE_INSTANCE_BRANCH: ${{ steps.prerequisites.outputs.merge_instance_branch }}
MERGE_INSTANCE_BRANCH_HEAD_SHA:
${{ steps.prerequisites.outputs.merge_instance_branch_head_sha }}
PR_BRANCH: ${{ steps.prerequisites.outputs.pr_branch }}
PR_BRANCH_HEAD_SHA: ${{ steps.prerequisites.outputs.pr_branch_head_sha }}
PR_BRANCH_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
VERBOSE: ${{ inputs.verbose }}
WORKSPACE_PATH: ${{ steps.prerequisites.outputs.workspace_path }}
BAZEL_PATH: ${{ inputs.bazel-path }}
Expand All @@ -98,6 +97,6 @@ runs:
IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
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: ${{ github.event.pull_request.head.sha }}
IMPACTED_TARGETS_FILE: ${{ steps.compute-impacted-targets.outputs.impacted_targets_out }}
IMPACTS_ALL_DETECTED: ${{ steps.prerequisites.outputs.impacts_all_detected }}
8 changes: 4 additions & 4 deletions src/scripts/compute_impacted_targets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
set -euo pipefail
shopt -s expand_aliases

if [[ (-z ${MERGE_INSTANCE_BRANCH}) || (-z ${PR_BRANCH}) ]]; then
echo "Missing branch"
if [[ -z ${MERGE_INSTANCE_BRANCH} ]]; then
echo "Missing merge instance branch"
exit 2
fi

Expand Down Expand Up @@ -78,7 +78,7 @@ if [[ -n ${VERBOSE} ]]; then
pr_depth=$(git rev-list "${merge_base_sha}".."${PR_BRANCH_HEAD_SHA}" | wc -l)
echo "PR Depth= ${pr_depth}"

git switch "${PR_BRANCH}"
git switch "${PR_BRANCH_HEAD_SHA}"
git log -n "${pr_depth}" --oneline
fi

Expand All @@ -97,7 +97,7 @@ git switch "${MERGE_INSTANCE_BRANCH}"
bazelDiff generate-hashes --bazelPath="${BAZEL_PATH}" --workspacePath="${WORKSPACE_PATH}" "-so=${bazel_startup_options}" "${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}"
git -c "user.name=Trunk Actions" -c "[email protected]" merge --squash "${PR_BRANCH_HEAD_SHA}"
bazelDiff generate-hashes --bazelPath="${BAZEL_PATH}" --workspacePath="${WORKSPACE_PATH}" "-so=${bazel_startup_options}" "${merge_instance_with_pr_branch_out}"

# Compute impacted targets
Expand Down
12 changes: 3 additions & 9 deletions src/scripts/prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
git fetch --quiet --depth=2147483647 origin "$@"
}

# trunk-ignore(shellcheck)

Check warning on line 12 in src/scripts/prerequisites.sh

View check run for this annotation

Trunk-Staging.io / Trunk Check

trunk(ignore-does-nothing)

[new] trunk-ignore(shellcheck) is not suppressing a lint issue
pr_branch="${PR_BRANCH}"
pr_head_sha="${PR_SHA}"
merge_instance_branch="${TARGET_BRANCH}"
if [[ -z ${merge_instance_branch} ]]; then
merge_instance_branch="${DEFAULT_BRANCH}"
Expand Down Expand Up @@ -45,22 +45,16 @@
fi

fetchRemoteGitHistory "${merge_instance_branch}"
fetchRemoteGitHistory "${pr_branch}"
fetchRemoteGitHistory "${pr_head_sha}"

git switch "${merge_instance_branch}"
merge_instance_branch_head_sha=$(git rev-parse "${merge_instance_branch}")

git switch "${pr_branch}"
pr_branch_head_sha=$(git rev-parse "${pr_branch}")
merge_instance_branch_head_sha=$(git rev-parse "origin/${merge_instance_branch}")

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

# Outputs
# trunk-ignore(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 "pr_branch=${pr_branch}" >>"${GITHUB_OUTPUT}"
echo "pr_branch_head_sha=${pr_branch_head_sha}" >>"${GITHUB_OUTPUT}"
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}"
Loading