Skip to content

fix: use commit SHA for autofix checkout to survive deleted PR branches#741

Merged
Bryan-Roe merged 4 commits into
mainfrom
copilot/fix-failing-github-actions-job-another-one
Jul 6, 2026
Merged

fix: use commit SHA for autofix checkout to survive deleted PR branches#741
Bryan-Roe merged 4 commits into
mainfrom
copilot/fix-failing-github-actions-job-another-one

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The Auto-fix (lint / format) job in codeql.yml hard-fails when the PR branch is deleted (e.g. auto-deleted after merge) before actions/checkout runs — it tries to resolve the branch name, which no longer exists.

Changes

  • Checkout by SHA, not branch name — added PR_HEAD_SHA env var to the "Determine checkout ref" step; for pull_request events ref now outputs the commit SHA. Commit objects are immutable and persist after branch deletion.
  • Separate push_ref output — branch name is preserved in a new push_ref output used exclusively by the push step, so the autofix commit still lands on the correct branch when it exists.
  • Branch existence guard before pushgit ls-remote --exit-code checks the remote ref before pushing; if the branch was deleted between checkout and push, the step skips with a clear message instead of erroring.
  • Regression testtest_codeql_autofix_uses_sha_for_checkout_and_branch_for_push added to test_codeql_workflow_paths_ignore.py to pin the contract.
# Before — fails if branch deleted before checkout
echo "ref=$PR_HEAD_REF"

# After — commit SHA always resolvable; branch name kept for push only
echo "ref=$PR_HEAD_SHA"
echo "push_ref=$PR_HEAD_REF"
# Push step — skip gracefully if branch was auto-deleted
if git ls-remote --exit-code origin "refs/heads/$PUSH_REF" >/dev/null 2>&1; then
  git push origin "HEAD:$PUSH_REF"
else
  echo "PR branch '$PUSH_REF' no longer exists on the remote; skipping push."
fi

Copilot AI requested review from Copilot and removed request for Copilot July 6, 2026 19:18

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@Bryan-Roe Unfortunately, I hit an error while trying to use the custom Copilot setup steps configured for this repository and had to close this PR. The error I am seeing is:

no `copilot-setup-steps` job found in your `copilot-setup-steps.yml` workflow file. Please ensure you have a single job named `copilot-setup-steps`. For more details, see https://gh.io/copilot/actions-setup-steps

Once you or someone with the necessary access fixes the problem, please unassign and then reassign issue #0 to me and I'll retry. Thanks!

The "Auto-fix (lint / format)" job in codeql.yml failed when the PR
branch (chunk/add-docstrings-key-functions) was deleted before the
workflow's checkout step ran. The job used the branch name as the
checkout ref, which fails if the branch no longer exists.

Fix: use PR_HEAD_SHA (commit SHA) for the checkout ref — the commit
object persists even after branch deletion. Add a separate push_ref
output (branch name) used only by the git push step, so the push still
targets the correct branch when it exists.

Also add a test to guard the new contract.
Copilot AI requested review from Copilot and removed request for Copilot July 6, 2026 19:28
If the PR branch is deleted between checkout and push (e.g. auto-deleted
after merge), ls-remote now detects the missing ref and skips the push
with a clear message instead of failing the step.

Also update test to match new PUSH_REF env var pattern.
Copilot AI requested review from Copilot and removed request for Copilot July 6, 2026 19:29
Copilot AI changed the title [WIP] Fix the failing GitHub Actions job auto-fix (lint / format) fix: use commit SHA for autofix checkout to survive deleted PR branches Jul 6, 2026
Copilot AI requested a review from Bryan-Roe July 6, 2026 19:30
@Bryan-Roe Bryan-Roe marked this pull request as ready for review July 6, 2026 19:30

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Bryan-Roe, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

…er-one

Signed-off-by: Bryan <74067792+Bryan-Roe@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 6, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Bryan-Roe Bryan-Roe merged commit 8eda4b6 into main Jul 6, 2026
4 of 6 checks passed
@Bryan-Roe Bryan-Roe deleted the copilot/fix-failing-github-actions-job-another-one branch July 6, 2026 19:30
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants