mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
[release/v7.6] Fix merge conflict checker for empty file lists and filter *.cs files (#26556)
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
# Merge Conflict Checker
|
||||
|
||||
This composite GitHub Action checks for Git merge conflict markers in files changed in pull requests.
|
||||
|
||||
## Purpose
|
||||
|
||||
Automatically detects leftover merge conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) in pull request files to prevent them from being merged into the codebase.
|
||||
|
||||
## Usage
|
||||
|
||||
### In a Workflow
|
||||
|
||||
```yaml
|
||||
- name: Check for merge conflict markers
|
||||
uses: "./.github/actions/infrastructure/merge-conflict-checker"
|
||||
```
|
||||
|
||||
### Complete Example
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
merge_conflict_check:
|
||||
name: Check for Merge Conflict Markers
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'pull_request'
|
||||
permissions:
|
||||
pull-requests: read
|
||||
contents: read
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Check for merge conflict markers
|
||||
uses: "./.github/actions/infrastructure/merge-conflict-checker"
|
||||
```
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **File Detection**: Uses GitHub's API to get the list of files changed in the pull request
|
||||
2. **Marker Scanning**: Reads each changed file and searches for the following markers:
|
||||
- `<<<<<<<` (conflict start marker)
|
||||
- `=======` (conflict separator)
|
||||
- `>>>>>>>` (conflict end marker)
|
||||
3. **Result Reporting**:
|
||||
- If markers are found, the action fails and lists all affected files
|
||||
- If no markers are found, the action succeeds
|
||||
|
||||
## Outputs
|
||||
|
||||
- `files-checked`: Number of files that were checked
|
||||
- `conflicts-found`: Number of files containing merge conflict markers
|
||||
|
||||
## Behavior
|
||||
|
||||
- **Event Support**: Only works with `pull_request` events
|
||||
- **File Handling**:
|
||||
- Checks only files that were added, modified, or renamed
|
||||
- Skips deleted files
|
||||
- **Filters out `*.cs` files** (C# files are excluded from merge conflict checking)
|
||||
- Skips binary/unreadable files
|
||||
- Skips directories
|
||||
- **Empty File List**: Gracefully handles cases where no files need checking (e.g., PRs that only delete files)
|
||||
|
||||
## Example Output
|
||||
|
||||
When conflict markers are detected:
|
||||
|
||||
```
|
||||
❌ Merge conflict markers detected in the following files:
|
||||
- src/example.cs
|
||||
Markers found: <<<<<<<, =======, >>>>>>>
|
||||
- README.md
|
||||
Markers found: <<<<<<<, =======, >>>>>>>
|
||||
|
||||
Please resolve these conflicts before merging.
|
||||
```
|
||||
|
||||
When no markers are found:
|
||||
|
||||
```
|
||||
✅ No merge conflict markers found
|
||||
```
|
||||
|
||||
## Integration
|
||||
|
||||
This action is integrated into the `linux-ci.yml` workflow and runs automatically on all pull requests to ensure code quality before merging.
|
||||
@@ -0,0 +1,37 @@
|
||||
name: 'Check for Merge Conflict Markers'
|
||||
description: 'Checks for Git merge conflict markers in changed files for pull requests'
|
||||
author: 'PowerShell Team'
|
||||
|
||||
outputs:
|
||||
files-checked:
|
||||
description: 'Number of files checked for merge conflict markers'
|
||||
value: ${{ steps.check.outputs.files-checked }}
|
||||
conflicts-found:
|
||||
description: 'Number of files with merge conflict markers'
|
||||
value: ${{ steps.check.outputs.conflicts-found }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
uses: "./.github/actions/infrastructure/get-changed-files"
|
||||
|
||||
- name: Check for merge conflict markers
|
||||
id: check
|
||||
shell: pwsh
|
||||
env:
|
||||
CHANGED_FILES_JSON: ${{ steps.changed-files.outputs.files }}
|
||||
run: |
|
||||
# Get changed files from environment variable (secure against injection)
|
||||
$changedFilesJson = $env:CHANGED_FILES_JSON
|
||||
# Ensure we always have an array (ConvertFrom-Json returns null for empty JSON arrays)
|
||||
$changedFiles = @($changedFilesJson | ConvertFrom-Json)
|
||||
|
||||
# Import ci.psm1 and run the check
|
||||
Import-Module "$env:GITHUB_WORKSPACE/tools/ci.psm1" -Force
|
||||
Test-MergeConflictMarker -File $changedFiles -WorkspacePath $env:GITHUB_WORKSPACE
|
||||
|
||||
branding:
|
||||
icon: 'alert-triangle'
|
||||
color: 'red'
|
||||
Reference in New Issue
Block a user