Skip to content

Commit b0da5cb

Browse files
added some suggested troubleshooting checks and logging
1 parent 507f15e commit b0da5cb

File tree

1 file changed

+105
-48
lines changed

1 file changed

+105
-48
lines changed

.github/workflows/pr.yml

Lines changed: 105 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,75 +24,132 @@ jobs:
2424
- name: Check Commit Origin Against Upstream
2525
id: commit_origin_check
2626
run: |
27-
UPSTREAM_REPO_URL="${{ steps.upstream_config.outputs.upstream_repo_url }}"
28-
UPSTREAM_BRANCH_NAME="${{ steps.upstream_config.outputs.upstream_branch_name }}"
29-
PR_BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
30-
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"
31-
27+
# --- Initial Git State & Configuration ---
28+
echo "Current directory: $(pwd)"
29+
echo "GitHub Repository: ${{ github.repository }}"
30+
echo "GitHub Workflow: ${{ github.workflow }}"
31+
echo "GitHub Run ID: ${{ github.run_id }}"
32+
echo "GitHub Event Name: ${{ github.event_name }}"
33+
echo "PR Base Ref from event: ${{ github.event.pull_request.base.ref }}"
34+
echo "PR Head Ref from event: ${{ github.event.pull_request.head.ref }}"
35+
echo "PR Head SHA from event: ${{ github.event.pull_request.head.sha }}"
36+
echo "-----------------------------------------"
37+
echo "--- Initial Git Setup by Checkout Action ---"
38+
echo "Current branch (HEAD): $(git rev-parse --abbrev-ref HEAD)"
39+
echo "Current commit (HEAD): $(git rev-parse HEAD)"
40+
echo "Remotes:"
41+
git remote -v
42+
echo "Local branches:"
43+
git branch
44+
echo "All refs (local and remote-tracking):"
45+
git show-ref
46+
echo "-----------------------------------------"
47+
48+
UPSTREAM_REPO_URL="${{ steps.upstream_config.outputs.upstream_repo_url }}"
49+
UPSTREAM_BRANCH_NAME="${{ steps.upstream_config.outputs.upstream_branch_name }}"
50+
# Define PR base branch name and the full ref for it
51+
PR_BASE_BRANCH_NAME="${{ github.event.pull_request.base.ref }}"
52+
PR_ACTUAL_BASE_REF="refs/remotes/origin/$PR_BASE_BRANCH_NAME" # This is the ref we need to ensure exists
53+
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"
54+
3255
echo "Upstream Repository URL: $UPSTREAM_REPO_URL"
33-
echo "Target Upstream Branch for Comparison: $UPSTREAM_BRANCH_NAME" # Clarified purpose
34-
echo "PR Base Ref: $PR_BASE_REF"
56+
echo "Target Upstream Branch for Comparison: $UPSTREAM_BRANCH_NAME"
57+
echo "PR Base Branch Name (in fork): $PR_BASE_BRANCH_NAME"
58+
echo "PR Actual Base Ref to use: $PR_ACTUAL_BASE_REF"
3559
echo "PR Head SHA: $PR_HEAD_SHA"
36-
37-
# Add upstream remote if it doesn't exist
38-
if ! git remote | grep -q '^upstream$'; then
60+
61+
# --- Details for 'origin' remote before fetching PR base ---
62+
echo "Showing details for 'origin' remote:"
63+
git remote show origin
64+
echo "Checking if '$PR_ACTUAL_BASE_REF' exists before explicit fetch:"
65+
git rev-parse --verify "$PR_ACTUAL_BASE_REF" || echo "Info: Ref '$PR_ACTUAL_BASE_REF' does NOT exist or is not valid yet."
66+
echo "-------------------------------------------------------"
67+
68+
# CRUCIAL STEP: Explicitly fetch the PR's base branch from origin to ensure its remote-tracking ref is available
69+
echo "Fetching PR base branch '$PR_BASE_BRANCH_NAME' from origin (refspec: $PR_BASE_BRANCH_NAME:$PR_ACTUAL_BASE_REF)..."
70+
git fetch origin "$PR_BASE_BRANCH_NAME:$PR_ACTUAL_BASE_REF"
71+
echo "Fetch of PR base branch from origin complete."
72+
73+
# --- Git State After Explicitly Fetching PR Base Branch from origin ---
74+
echo "Remote-tracking branches (git branch -r) after origin fetch:"
75+
git branch -r
76+
echo "All refs (git show-ref) again after origin fetch:"
77+
git show-ref
78+
echo "Verifying ref '$PR_ACTUAL_BASE_REF' (SHA) after origin fetch:"
79+
git rev-parse "$PR_ACTUAL_BASE_REF" || echo "Error: rev-parse failed for '$PR_ACTUAL_BASE_REF' even after explicit origin fetch!"
80+
echo "Verifying ref type '$PR_ACTUAL_BASE_REF' (type) after origin fetch:"
81+
git cat-file -t "$PR_ACTUAL_BASE_REF" || echo "Error: cat-file -t failed for '$PR_ACTUAL_BASE_REF' even after explicit origin fetch!"
82+
echo "---------------------------------------------"
83+
84+
# Add upstream remote if it doesn't exist
85+
if ! git remote | grep -q '^upstream$'; then
3986
echo "Adding remote 'upstream' for $UPSTREAM_REPO_URL"
4087
git remote add upstream "$UPSTREAM_REPO_URL"
41-
else
88+
else
4289
echo "Remote 'upstream' already exists. Setting URL."
4390
git remote set-url upstream "$UPSTREAM_REPO_URL"
44-
fi
45-
91+
fi
92+
4693
echo "Fetching from upstream remote (target branch: $UPSTREAM_BRANCH_NAME)..."
4794
# Fetch only the specific target branch from upstream
48-
git fetch upstream "$UPSTREAM_BRANCH_NAME" --no-tags --depth=1000 # Adjust depth as needed
49-
UPSTREAM_BRANCH_HEAD_REF="upstream/$UPSTREAM_BRANCH_NAME" # Reference to the fetched upstream branch head
50-
echo "Successfully fetched $UPSTREAM_BRANCH_HEAD_REF"
51-
52-
# Determine the merge base between the PR's base in your fork and the PR's head
53-
# This defines the starting point for commits introduced by this PR in your fork.
54-
MERGE_BASE=$(git merge-base "$PR_BASE_REF" "$PR_HEAD_SHA")
55-
if [ -z "$MERGE_BASE" ]; then
56-
echo "Error: Could not determine merge base between $PR_BASE_REF and $PR_HEAD_SHA."
95+
git fetch upstream "$UPSTREAM_BRANCH_NAME:refs/remotes/upstream/$UPSTREAM_BRANCH_NAME" --no-tags --depth=5000 # Adjust depth as needed
96+
UPSTREAM_BRANCH_HEAD_REF="refs/remotes/upstream/$UPSTREAM_BRANCH_NAME" # Reference to the fetched upstream branch head
97+
echo "Successfully fetched $UPSTREAM_BRANCH_HEAD_REF"
98+
git rev-parse --verify "$UPSTREAM_BRANCH_HEAD_REF" || echo "Error: rev-parse failed for '$UPSTREAM_BRANCH_HEAD_REF' after upstream fetch!"
99+
100+
101+
# --- Pre-Merge-Base Check ---
102+
echo "Refs being passed to merge-base:"
103+
echo " Ref 1 (PR Base): $PR_ACTUAL_BASE_REF"
104+
echo " Ref 2 (PR Head): $PR_HEAD_SHA"
105+
echo "Checking validity of Ref 1 ($PR_ACTUAL_BASE_REF):"
106+
git rev-parse --verify "$PR_ACTUAL_BASE_REF" || echo "CRITICAL: '$PR_ACTUAL_BASE_REF' is not a valid object name just before merge-base!"
107+
echo "Checking validity of Ref 2 ($PR_HEAD_SHA):"
108+
git rev-parse --verify "$PR_HEAD_SHA" || echo "CRITICAL: '$PR_HEAD_SHA' is not a valid object name just before merge-base!"
109+
echo "---------------------------"
110+
111+
# Determine the merge base between the PR's base in your fork and the PR's head
112+
MERGE_BASE=$(git merge-base "$PR_ACTUAL_BASE_REF" "$PR_HEAD_SHA")
113+
if [ -z "$MERGE_BASE" ]; then
114+
echo "Error: Could not determine merge base between '$PR_ACTUAL_BASE_REF' and '$PR_HEAD_SHA'."
57115
echo "This could indicate unrelated histories or issues fetching. For safety, requiring review."
58-
echo "::set-output name=require_review::true"
116+
core.setOutput('is_purely_upstream', 'false') # Corrected output name
59117
exit 0
60-
fi
118+
fi
61119
echo "Merge Base for PR commits (relative to fork's base): $MERGE_BASE"
62-
120+
63121
# Get the list of commit SHAs introduced by this PR in your fork
64-
PR_COMMIT_SHAS=$(git log "$MERGE_BASE".."$PR_HEAD_SHA" --pretty=format:"%H" --no-merges)
65-
66-
if [ -z "$PR_COMMIT_SHAS" ]; then
122+
PR_COMMIT_SHAS=$(git log "$MERGE_BASE".."$PR_HEAD_SHA" --pretty=format:"%H" --no-merges)
123+
124+
if [ -z "$PR_COMMIT_SHAS" ]; then
67125
echo "No new authored commits found in PR range."
68-
echo "PR is an empty sync or just a merge from upstream chromium repo. No review required."
69-
echo "::set-output name=require_review::false"
126+
echo "PR is an empty sync or just a merge. No review required by this check."
127+
core.setOutput('is_purely_upstream', 'true') # Corrected output name
70128
exit 0
71-
fi
72-
echo "Commit SHAs in PR to verify against upstream ($UPSTREAM_BRANCH_HEAD_REF):"
73-
echo "$PR_COMMIT_SHAS"
74-
75-
ALL_COMMITS_ARE_UPSTREAM=true
76-
for commit_sha in $PR_COMMIT_SHAS; do
129+
fi
130+
echo "Commit SHAs in PR to verify against upstream ($UPSTREAM_BRANCH_HEAD_REF):"
131+
echo "$PR_COMMIT_SHAS"
132+
133+
ALL_COMMITS_ARE_UPSTREAM=true
134+
for commit_sha in $PR_COMMIT_SHAS; do
77135
echo "Verifying commit $commit_sha against $UPSTREAM_BRANCH_HEAD_REF..."
78136
# Check if the commit_sha is an ancestor of the fetched upstream branch's head
79137
if git merge-base --is-ancestor "$commit_sha" "$UPSTREAM_BRANCH_HEAD_REF"; then
80-
echo "Commit $commit_sha FOUND in $UPSTREAM_BRANCH_HEAD_REF."
138+
echo "Commit $commit_sha FOUND in $UPSTREAM_BRANCH_HEAD_REF."
81139
else
82-
echo "Commit $commit_sha NOT FOUND in $UPSTREAM_BRANCH_HEAD_REF. This PR contains local/modified changes."
83-
ALL_COMMITS_ARE_UPSTREAM=false
84-
break # No need to check further, one local commit is enough
140+
echo "Commit $commit_sha NOT FOUND in $UPSTREAM_BRANCH_HEAD_REF. This PR contains local/modified changes."
141+
ALL_COMMITS_ARE_UPSTREAM=false
142+
break # No need to check further, one local commit is enough
85143
fi
86-
done
87-
88-
if [[ "$ALL_COMMITS_ARE_UPSTREAM" == "true" ]]; then
144+
done
145+
146+
if [[ "$ALL_COMMITS_ARE_UPSTREAM" == "true" ]]; then
89147
echo "All commits in this PR originate from the upstream branch ($UPSTREAM_BRANCH_NAME)."
90-
echo "::set-output name=require_review::false"
91-
else
148+
core.setOutput('is_purely_upstream', 'true') # Corrected output name
149+
else
92150
echo "This PR contains commits not found on the upstream branch ($UPSTREAM_BRANCH_NAME). Internal review required."
93-
echo "::set-output name=require_review::true"
94-
fi
95-
shell: bash
151+
core.setOutput('is_purely_upstream', 'false') # Corrected output name
152+
fi
96153
97154
- name: Determine Review Requirement and Add Labels
98155
id: review_decision_and_labeling

0 commit comments

Comments
 (0)