[release/v7.5] Add merge conflict marker detection to linux-ci workflow and refactor existing actions to use reusable get-changed-files action#26812
Conversation
… existing actions to use reusable get-changed-files action (PowerShell#26350) Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: TravisEz13 <[email protected]> Co-authored-by: Travis Plunk <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Travis Plunk (HE/HIM) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This is a backport of PR #26350 to the release/v7.5 branch, which adds automated detection of Git merge conflict markers to prevent them from being accidentally merged. The PR also introduces a new Install-CIPester function to standardize Pester installation across CI workflows and adds comprehensive infrastructure tests and developer documentation.
Changes:
- Adds
Test-MergeConflictMarkerfunction to detect Git conflict markers in changed files - Introduces
Install-CIPesterfunction to standardize Pester module installation with version validation - Adds infrastructure tests for the new CI module functions with comprehensive test coverage
- Integrates merge conflict checking and infrastructure testing into the linux-ci workflow
- Includes developer documentation on PowerShell module organization and automatic variable naming conventions
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/ci.psm1 | Adds Install-CIPester and Test-MergeConflictMarker functions; refactors existing Pester installation to use the new Install-CIPester function |
| test/infrastructure/ciModule.Tests.ps1 | New test file with comprehensive Pester tests for Test-MergeConflictMarker and Install-CIPester functions |
| .github/workflows/linux-ci.yml | Adds merge_conflict_check job, infrastructure_tests job, and comments out analyze job; updates ready_to_merge dependencies |
| .github/workflows/macos-ci.yml | Adds Install-CIPester step before package content testing |
| .github/actions/infrastructure/merge-conflict-checker/action.yml | New composite action that calls Test-MergeConflictMarker via get-changed-files action |
| .github/actions/infrastructure/merge-conflict-checker/README.md | Documentation for the merge conflict checker action |
| .github/actions/test/linux-packaging/action.yml | Adds Install-CIPester step before package validation tests |
| .github/instructions/powershell-module-organization.instructions.md | New developer guidance on organizing PowerShell code across ci.psm1, build.psm1, and packaging.psm1 |
| .github/instructions/powershell-automatic-variables.instructions.md | New developer guidance on avoiding PowerShell automatic variable conflicts |
| .vsts-ci/templates/nanoserver.yml | Removed (deprecated nanoserver test template) |
| @@ -178,6 +235,9 @@ jobs: | |||
| - linux_test_unelevated_others | |||
| - analyze | |||
There was a problem hiding this comment.
The analyze job is referenced in the needs list but the job itself is commented out (lines 216-226). This will cause a workflow validation error because the job doesn't exist. Since the analyze job is disabled, this dependency reference should also be commented out to match line 240 where it appears as a comment.
| - analyze | |
| # - analyze |
| $filesChecked++ | ||
|
|
||
| # Get relative path for display | ||
| $relativePath = if ($WorkspacePath -and $filePath.StartsWith($WorkspacePath)) { |
There was a problem hiding this comment.
Path comparison should use case-insensitive comparison for cross-platform compatibility. The current code uses $filePath.StartsWith($WorkspacePath) which is case-sensitive and may fail on case-insensitive file systems like Windows.
Change to: $filePath.StartsWith($WorkspacePath, [System.StringComparison]::OrdinalIgnoreCase)
| $relativePath = if ($WorkspacePath -and $filePath.StartsWith($WorkspacePath)) { | |
| $relativePath = if ($WorkspacePath -and $filePath.StartsWith($WorkspacePath, [System.StringComparison]::OrdinalIgnoreCase)) { |
| 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 }} |
There was a problem hiding this comment.
The action references a non-existent action ./.github/actions/infrastructure/get-changed-files on line 18. This action does not exist in the repository and will cause the merge-conflict-checker action to fail.
According to the PR description, this is a backport from PR #26350. The original PR likely included the get-changed-files action, but it appears to have been omitted from this backport. You need to either:
- Include the get-changed-files action in this backport, or
- Modify this action to get changed files using a different method (such as using the GitHub API directly or a third-party action like tj-actions/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 }} | |
| uses: tj-actions/changed-files@v45 | |
| - name: Prepare changed files JSON | |
| id: prepare-files | |
| shell: pwsh | |
| env: | |
| CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | |
| run: | | |
| # Convert newline-separated list of changed files to JSON array | |
| $changedFiles = $env:CHANGED_FILES -split "`n" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | |
| $filesJson = $changedFiles | ConvertTo-Json -Compress | |
| "files=$filesJson" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| - name: Check for merge conflict markers | |
| id: check | |
| shell: pwsh | |
| env: | |
| CHANGED_FILES_JSON: ${{ steps.prepare-files.outputs.files }} |
| Set-ItResult -Skipped -Because "Test requires CI environment to safely install Pester" | ||
| } |
There was a problem hiding this comment.
Missing return statement after Set-ItResult -Skipped. According to the codebase convention (see test/powershell/engine/Module/NewModuleManifest.Tests.ps1:137-138, 148-149), when using Set-ItResult in Pester tests, you must always follow it with a return statement to prevent further test execution. Without the return, the test continues and may fail with unrelated errors.
Add return on the line following the Set-ItResult call.
| Set-ItResult -Skipped -Because "Test requires CI environment to safely install Pester" | ||
| } |
There was a problem hiding this comment.
Missing return statement after Set-ItResult -Skipped. According to the codebase convention (see test/powershell/engine/Module/NewModuleManifest.Tests.ps1:137-138, 148-149), when using Set-ItResult in Pester tests, you must always follow it with a return statement to prevent further test execution. Without the return, the test continues and may fail with unrelated errors.
Add return on the line following the Set-ItResult call.
Backport of #26350 to release/v7.5
Triggered by @daxian-dbw on behalf of @app/copilot-swe-agent
Original CL Label: CL-Tools
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Adds merge conflict marker detection to prevent accidentally merging unresolved conflicts
Customer Impact
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
New infrastructure tests verify Test-MergeConflictMarker function. Successfully tested in 7.4 and 7.6 releases. Action runs on PR events only.
Risk
REQUIRED: Check exactly one box.
Adds automated merge conflict detection to CI workflow. New job runs independently and doesn't affect existing build/test logic. Successfully backported to 7.4 and 7.6 branches.
Merge Conflicts
Conflicts in linux-ci.yml resolved - differences in job definitions and dependencies