diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fe89f94 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:latest + +RUN apt update +RUN apt install -y git + +COPY conflicts /conflicts + +ENTRYPOINT ["/conflicts"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dd1760c --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# integration-branch-merge-conflicts action + +This action checks if the current branch would produce merge conflicts when merged to a given integration branch. + +## Inputs + +### `branch` + +**Required** The name of the integration branch. Default `"main"`. + +## How to use it? +This is a Github action, so it has to be added to a github workflow. +A simple example of running this action on all pushes to the repository would be +add a `main.yml` file under `.github/workflows` with the following content +```yaml +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 + with: + fetch-depth: 0 #Required : Since we need to read the history + # Run the actual merge conflict detection + - name: Merge Conflict detection + uses: siscodeorg/integration-branch-merge-conflicts@v1.0 +``` +For this example, each push would trigger the merge conflict detection. \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..a1f3c0f --- /dev/null +++ b/action.yml @@ -0,0 +1,12 @@ +name: 'siscodeorg/integration-branch-merge-conflicts' +description: 'This action checks if the current branch would produce merge conflicts when merged to a given integration branch.' +inputs: + branch: + description: 'The name of the integration branch.' + required: true + default: 'main' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.branch }} \ No newline at end of file diff --git a/conflicts b/conflicts new file mode 100644 index 0000000..e76b9ac --- /dev/null +++ b/conflicts @@ -0,0 +1,10 @@ +#!/bin/bash -l +if + git merge-tree $(git merge-base origin/$1 HEAD) origin/$1 HEAD | grep -F -q "<<<<<<<" +then + echo "Found conflict marker" + exit 1 +fi + +echo "No conflicts found" +exit 0