|
| 1 | +name: Check for unresolved conflicts |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - 'v**' |
| 7 | + |
| 8 | +jobs: |
| 9 | + conflict-check: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + name: Check for conflict markers |
| 12 | + permissions: |
| 13 | + pull-requests: write |
| 14 | + contents: read |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Find conflict markers |
| 19 | + id: conflicts |
| 20 | + run: | |
| 21 | + # Look for git conflict markers: <<<<<<< followed by branch name |
| 22 | + # Exclude vendor, node_modules, and common non-source directories |
| 23 | + CONFLICTS=$(grep -rn "^<<<<<<< " \ |
| 24 | + --include="*.go" --include="*.yaml" --include="*.yml" --include="*.json" \ |
| 25 | + --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" \ |
| 26 | + --include="*.py" --include="*.rb" --include="*.rs" --include="*.sh" \ |
| 27 | + --include="*.md" --include="*.txt" \ |
| 28 | + --exclude-dir=vendor --exclude-dir=node_modules --exclude-dir=.git \ |
| 29 | + . 2>/dev/null || true) |
| 30 | +
|
| 31 | + if [ -n "$CONFLICTS" ]; then |
| 32 | + echo "found=true" >> "$GITHUB_OUTPUT" |
| 33 | + echo "### Conflict markers found:" |
| 34 | + echo "$CONFLICTS" |
| 35 | +
|
| 36 | + # Save to file for PR comment |
| 37 | + { |
| 38 | + echo "## Unresolved Merge Conflicts Detected" |
| 39 | + echo "" |
| 40 | + echo "This PR contains unresolved merge conflict markers. Please resolve them before merging." |
| 41 | + echo "" |
| 42 | + echo "### Conflicted Files" |
| 43 | + echo "" |
| 44 | + echo '```' |
| 45 | + echo "$CONFLICTS" |
| 46 | + echo '```' |
| 47 | + } > /tmp/conflict-report.md |
| 48 | + else |
| 49 | + echo "found=false" >> "$GITHUB_OUTPUT" |
| 50 | + echo "No conflict markers found" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Comment on PR |
| 54 | + if: steps.conflicts.outputs.found == 'true' && github.event_name == 'pull_request' |
| 55 | + env: |
| 56 | + GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} |
| 57 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 58 | + run: | |
| 59 | + # Update existing comment or create new one |
| 60 | + gh pr comment "$PR_NUMBER" --body-file /tmp/conflict-report.md --edit-last --create-if-none 2>/dev/null || \ |
| 61 | + gh pr comment "$PR_NUMBER" --body-file /tmp/conflict-report.md |
| 62 | +
|
| 63 | + - name: Fail if conflicts found |
| 64 | + if: steps.conflicts.outputs.found == 'true' |
| 65 | + run: | |
| 66 | + echo "::error::Unresolved merge conflict markers found" |
| 67 | + exit 1 |
0 commit comments