Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Summary

This PR adds automated detection of Git merge conflict markers in pull requests to prevent accidentally merging unresolved conflicts into the PowerShell repository.

What This PR Does

  1. Adds Merge Conflict Marker Detection

    • New composite action at .github/actions/infrastructure/merge-conflict-checker
    • Integrated into linux-ci.yml workflow as a new merge_conflict_check job
    • Only runs on pull requests in authorized repositories (azure/* or PowerShell)
    • Blocks merging if any conflict markers are found (added to ready_to_merge dependencies)
  2. Implements Detection Logic in PowerShell Module

    • Added Test-MergeConflictMarker function in tools/ci.psm1
    • Uses PowerShell's Select-String cmdlet for efficient pattern matching with automatic line numbering
    • Detects all three Git conflict marker types: <<<<<<<, =======, >>>>>>>
    • Provides detailed GitHub Actions job summary with:
      • Total files checked and conflicts found
      • Relative file paths (repo-relative, not full agent paths)
      • Precise line numbers for each conflict marker
      • Formatted markdown tables for easy reading
  3. Adds Developer Documentation

    • .github/instructions/powershell-module-organization.instructions.md - Guidelines for organizing PowerShell code across ci.psm1, build.psm1, and packaging.psm1 modules
    • .github/instructions/powershell-automatic-variables.instructions.md - Comprehensive guide on avoiding PowerShell automatic variables like $matches, $_, $args, and $input
    • Action-specific README documentation

Technical Implementation

Detection Logic:

  • Regex pattern: ^(<{7}|={7}|>{7})(\s|$) - matches 7 consecutive markers at line start, followed by whitespace or end-of-line
  • Properly matches real Git conflict markers with trailing content (e.g., <<<<<<< HEAD)
  • Skips binary files, deleted files, and directories
  • Uses relative paths in output for better readability

Code Quality:

  • Follows PowerShell best practices (capital Function keyword, singular parameter names)
  • Avoids PowerShell automatic variable conflicts (uses $matchedLines instead of $matches)
  • Minimal YAML - complex logic moved to reusable module function
  • Secure file handling using environment variables

Security:

  • Repository owner check prevents execution in unauthorized forks
  • Only processes changed files (retrieved via GitHub API)
  • Proper error handling with ErrorAction Stop

Files Changed

New Files:

  • .github/workflows/linux-ci.yml - Added merge_conflict_check job
  • .github/actions/infrastructure/merge-conflict-checker/action.yml - Composite action
  • .github/actions/infrastructure/merge-conflict-checker/README.md - Action documentation
  • .github/instructions/powershell-module-organization.instructions.md - Module organization guidelines
  • .github/instructions/powershell-automatic-variables.instructions.md - Automatic variables guide

Modified Files:

  • tools/ci.psm1 - Added Test-MergeConflictMarker function

Next Steps (Not Included in This PR)

  1. Unit Tests: Add Pester tests for Test-MergeConflictMarker function in test/infrastructure/ (per reviewer request)
  2. Integration Testing: Verify the workflow works correctly in live PR scenarios

Benefits

  1. Prevents Merge Conflicts: Automatically detects and blocks PRs with unresolved conflict markers
  2. Clear Feedback: Provides developers with exact file paths and line numbers to fix
  3. Maintainable Code: Well-organized PowerShell in modules with comprehensive documentation
  4. Future-Proof: Instructions help prevent common PowerShell pitfalls for future contributors

Fixes #26349


💡 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.

@TravisEz13 TravisEz13 added the CL-Tools Indicates that a PR should be marked as a tools change in the Change Log label Oct 29, 2025
Copilot AI changed the title [WIP] Add GitHub workflow to check for merge conflict markers Add merge conflict marker detection to linux-ci workflow Oct 29, 2025
Copilot AI requested a review from TravisEz13 October 29, 2025 22:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds automated detection of Git merge conflict markers in pull requests to prevent accidentally merging unresolved conflicts into the codebase. The implementation creates a new composite GitHub Action that scans changed files for conflict markers (<<<<<<<, =======, >>>>>>>) and fails the workflow if any are found.

Key changes:

  • New composite action for detecting merge conflict markers in PR files
  • Integration into the Linux CI workflow with a dedicated job
  • Test files demonstrating different conflict marker scenarios

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

File Description
.github/actions/infrastructure/merge-conflict-checker/action.yml Main composite action implementing the conflict detection logic using GitHub API and PowerShell
.github/actions/infrastructure/merge-conflict-checker/README.md Documentation explaining usage, behavior, and integration of the action
.github/workflows/linux-ci.yml Adds the merge conflict check job to the Linux CI workflow and includes it in the ready-to-merge dependencies
test/merge-conflict-markers/test-*.txt Test files containing various conflict marker patterns for validation purposes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TravisEz13 TravisEz13 requested a review from Copilot October 30, 2025 23:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TravisEz13 TravisEz13 marked this pull request as ready for review October 30, 2025 23:21
@TravisEz13 TravisEz13 requested review from a team and jshigetomi as code owners October 30, 2025 23:21
@TravisEz13 TravisEz13 enabled auto-merge (squash) October 31, 2025 18:00
@TravisEz13 TravisEz13 merged commit 0c40a84 into master Oct 31, 2025
43 checks passed
@TravisEz13 TravisEz13 deleted the copilot/add-github-workflow-merge-conflict-check branch October 31, 2025 18:01
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented Oct 31, 2025

📣 Hey @@Copilot, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

pwshBot pushed a commit to pwshBot/PowerShell that referenced this pull request Oct 31, 2025
TravisEz13 added a commit to TravisEz13/PowerShell that referenced this pull request Nov 25, 2025
… existing actions to use reusable get-changed-files action (PowerShell#26350)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Travis Plunk (HE/HIM) <tplunk@ntdev.microsoft.com>
SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request Dec 12, 2025
… existing actions to use reusable get-changed-files action (PowerShell#26350)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Travis Plunk (HE/HIM) <tplunk@ntdev.microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.4.x-Migrated BackPort-7.5.x-Consider Backport-7.6.x-Migrated CL-Tools Indicates that a PR should be marked as a tools change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a github workflow that looks for merge conflict markers

3 participants