steve238
steve238

Reputation: 1259

How to check if a Pull Request has merge conflicts in Github Actions

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.

Upvotes: 4

Views: 1728

Answers (2)

Matteo
Matteo

Reputation: 39390

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/[email protected]

Upvotes: 2

Vincent
Vincent

Reputation: 5425

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.

Upvotes: 0

Related Questions