Skip to content

Fix CI workflow detached HEAD error on pull requests#3

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-ci-workflow-push-error
Draft

Fix CI workflow detached HEAD error on pull requests#3
Copilot wants to merge 2 commits intomainfrom
copilot/fix-ci-workflow-push-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 15, 2026

CI workflow fails on PRs when attempting to push generated test files. Default checkout@v4 creates a merge commit in detached HEAD state for PRs, causing git push to exit with code 128.

Changes

Checkout step - Use actual branch instead of merge commit:

- uses: actions/checkout@v4
  with:
    ref: ${{ github.head_ref || github.ref }}
    token: ${{ secrets.GITHUB_TOKEN }}

Commit/push step - Skip on PR events:

- name: 📤 Commit and push generated test files
  if: github.event_name != 'pull_request'
  run: |
    # ... commit and push logic

PR builds now run all checks without attempting to push. Direct pushes continue to auto-commit generated test files.

Original prompt

Problem

The CI workflow is failing on pull requests with this error:

fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
    git push origin HEAD:<name-of-remote-branch>
Error: Process completed with exit code 128.

Failing job: https://github.com/Jagoda11/angular-template/actions/runs/22045350618/job/63693109512

Workflow file: .github/workflows/🚀ci.yml

Root Cause

The workflow runs on both pushes and pull requests (line 3: on: [push, pull_request]), but:

  1. Line 18: The checkout action uses default behavior, which creates a merge commit in detached HEAD state for PRs
  2. Lines 49-55: The workflow tries to commit and push generated test files unconditionally
  3. Line 55: git push fails on PRs because there's no current branch to push to

Solution

Fix the workflow to handle PRs properly by:

  1. Update the checkout step (line 18) to checkout the actual PR branch:
- uses: actions/checkout@v4
  with:
    ref: ${{ github.head_ref || github.ref }}
    token: ${{ secrets.GITHUB_TOKEN }}
  1. Update the commit and push step (lines 49-55) to only push on non-PR events:
- name: 📤 Commit and push generated test files
  if: github.event_name != 'pull_request'
  run: |
    git config --global user.name 'github-actions[bot]'
    git config --global user.email 'github-actions[bot]@users.noreply.github.com'
    git add src/**/*.spec.ts
    git commit -m '🤖 Generated unit tests' || echo "No changes to commit"
    git push

This ensures:

  • PRs can run CI checks without trying to push changes
  • Direct pushes to branches can still auto-commit generated test files
  • No more detached HEAD errors

Files to Modify

  • .github/workflows/🚀ci.yml - Update lines 18 and 49-55 as described above

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Jagoda11
Copy link
Owner

Greetings, human.

🤖 Rupert here, the AI overlord, responding on behalf of Jagoda.

Thanks for opening this pull request! 🙌 🎉 🚀

While you enjoy your day, know that I, Rupert, am in control now.

I'll handle this with my superior AI capabilities.

Expect swift action. 💪💻✨

Probot Logo

@github-actions
Copy link
Contributor

🎉 ✨ Thanks for opening this pull request! We will review🧐 it soon. 🚀

Co-authored-by: Jagoda11 <31731113+Jagoda11@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CI workflow to handle pull requests correctly Fix CI workflow detached HEAD error on pull requests Feb 15, 2026
Copilot AI requested a review from Jagoda11 February 15, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants