Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update GitHub Actions Workflow for Merge Conflict #269

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/pr-merge-conflict.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# This action is centrally managed in https://github.com/asyncapi/.github/
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo

# This action handles merge conflicts and provides auto-rebase functionality for pull requests
name: Merge Conflict and Auto-Rebase

on:
pull_request_target:
types: [opened, reopened, synchronize, edited, ready_for_review]
issue_comment:
types: [created]

jobs:
check-merge-conflicts:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
outputs:
conflicts: ${{ steps.conflicts.outputs.conflicts }}
steps:
- name: Checkout
uses: actions/checkout@v2
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
- name: Check for merge conflicts
id: conflicts
run: |
git fetch origin ${{ github.base_ref }}
git merge origin/${{ github.base_ref }} --no-commit --no-ff
if [[ $(git ls-files -u | wc -l) -gt 0 ]]; then
echo "Merge conflicts detected."
echo "::set-output name=conflicts::true"
git merge --abort
else
echo "No merge conflicts."
echo "::set-output name=conflicts::false"
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
fi
- name: Post Merge Conflict Notification
if: steps.conflicts.outputs.conflicts == 'true'
uses: marocchino/[email protected]
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
header: merge-conflict-warning
message: |
⚠️ Merge conflicts detected. Please resolve them.
**Options to Resolve Conflicts:**
- **Manually:** Resolve the conflicts in your local environment and push the changes.
- **Automated Commands:** Use `/rebase`, `/solve_conflict`, or `/sf` to automatically rebase this PR.
**Good Practices:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean good practice for manual resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to cover this part -

Bonus:
Maybe some tips on what is the best way to solve the merge conflict 🤔 good and bad practices.

- Fetch and merge the latest changes from the base branch into your branch.
- Consider using a visual diff tool to clearly see and resolve conflicts.
- Test your changes after resolving to ensure nothing is broken.
For more detailed guidance, refer to your project's contributing guidelines or documentation.

auto-rebase:
if: github.event_name == 'issue_comment' && github.event.issue.pull_request && (startsWith(github.event.comment.body, '/rebase') || startsWith(github.event.comment.body, '/solve_conflict') || startsWith(github.event.comment.body, '/sf'))
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout@v3
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
with:
token: ${{ secrets.GITHUB_TOKEN }}
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
fetch-depth: 0
- name: Automatic Rebase
run: |
git fetch origin ${{ github.base_ref }}
git rebase origin/${{ github.base_ref }}
if [[ $? -ne 0 ]]; then
echo "::error::Automatic rebase failed. Manual resolution required."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
mhmohona marked this conversation as resolved.
Show resolved Hide resolved
- name: Post Success Message
if: success()
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Congratulations! 🎉 The automatic rebase was successful.'
});
- name: Post Failure Message
if: failure()
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'The automatic rebase encountered issues and was not successful. Please manually resolve these conflicts and push your changes.'
});
Loading