I want to be able to determine if a Pull Request has merge conflicts in a GitHub Action's pipeline, and if they do run echo this PR has merge conflicts
.
Asked
Active
Viewed 923 times
3

steve238
- 831
- 1
- 10
- 19
-
Please show your own effort and how that didn't work – rethab Mar 31 '22 at 11:13
2 Answers
1
You could try the olivernybroe/action-conflict-finder, as example:
on: [push]
jobs:
merge_conflict_job:
runs-on: ubuntu-latest
name: Find merge conflicts
steps:
# Checkout the source code so we have some files to look at.
- uses: actions/checkout@v2
# Run the actual merge conflict finder
- name: Merge Conflict finder
uses: olivernybroe/action-conflict-finder@v2.0

Matteo
- 37,680
- 11
- 100
- 115
-
I don't think this does what the asker was looking for. This action seems to check whether you have accidentally committed files with unresolved merge conflicts to your repo, not whether there are any active PR merge conflicts. – ipetrik Dec 02 '22 at 19:48
0
This is a CI job that fails when a PR includes merge conflicts:
name: No unresolved conflicts
on:
pull_request:
branches: [ main ]
jobs:
detect-unresolved-conflicts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: List files with merge conflict markers
run: git --no-pager grep "<<<<<<<" ":(exclude).github/" || true
- name: Fail or succeed job if any files with merge conflict markers have been checked in
# Find lines containing "<<<<<<<", then count the number of lines.
# 0 matching lines results in exit code 0, i.e. success.
run: exit $(git grep "<<<<<<<" ":(exclude).github/" | wc --lines)
That's probably what you want, but I'm sure with some searching, you can convert it to only echo your error message rather than fail the build.

Vincent
- 4,876
- 3
- 44
- 55