-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add merge conflict github PR check (#10930)
- Loading branch information
1 parent
1eabecd
commit 5db0430
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
name: Github Merge Conflict Check | ||
|
||
on: | ||
push: | ||
branches: [main, dev, 1.0*, 2.0*, 3.0*, fasttrack/*] | ||
pull_request: | ||
branches: [main, dev, 1.0*, 2.0*, 3.0*, fasttrack/*] | ||
|
||
jobs: | ||
spec-check: | ||
name: Github Merge Conflict Check | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the branch of our repo that triggered this action | ||
- name: Workflow trigger checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get base commit for PRs | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: | | ||
git fetch origin ${{ github.base_ref }} | ||
echo "base_sha=$(git rev-parse origin/${{ github.base_ref }})" >> $GITHUB_ENV | ||
echo "Merging ${{ github.sha }} into ${{ github.base_ref }}" | ||
- name: Get base commit for Pushes | ||
if: ${{ github.event_name == 'push' }} | ||
run: | | ||
git fetch origin ${{ github.event.before }} | ||
echo "base_sha=${{ github.event.before }}" >> $GITHUB_ENV | ||
echo "Merging ${{ github.sha }} into ${{ github.event.before }}" | ||
- name: Check for merge conflicts | ||
run: | | ||
echo "Files changed: '$(git diff-tree --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }})'" | ||
changed_files=$(git diff-tree --diff-filter=d --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }}) | ||
merge_conflict_found=false | ||
for file in $changed_files ; do | ||
if [ -f $file ]; then | ||
echo "Checking for merge conflicts in $file" | ||
if grep -H -r "^<<<<<<< HEAD$" $file; then | ||
echo "Merge conflict found in $file" | ||
merge_conflict_found=true | ||
fi | ||
if grep -H -r "^>>>>>>>$" $file; then | ||
echo "Merge conflict found in $file" | ||
merge_conflict_found=true | ||
fi | ||
if grep -H -r "^=======$" $file; then | ||
echo "Merge conflict found in $file" | ||
merge_conflict_found=true | ||
fi | ||
fi | ||
done | ||
if [[ $merge_conflict_found =~ [Tt]rue ]]; then | ||
echo "Merge conflict found in one or more files" | ||
exit 1 | ||
fi |