From 47981798e2fba2604a3ca5aa91d25ec7abdd1352 Mon Sep 17 00:00:00 2001 From: Aaditya Agarwal Date: Sun, 5 Jan 2025 17:34:19 +0530 Subject: [PATCH] Merge Conflict Job added in merge-conflict-check.yml file (#3147) * added merge conflict check * changed checkout repo * added max tries feature * added needs condition * added pr target synchronize to trigger workflow * added mergeconflictchecker.yml * switched to gh api * fixed indentation --- .github/workflows/merge-conflict-check.yml | 65 ++++++++++++++++++++++ .github/workflows/pull-request.yml | 54 ------------------ 2 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/merge-conflict-check.yml diff --git a/.github/workflows/merge-conflict-check.yml b/.github/workflows/merge-conflict-check.yml new file mode 100644 index 0000000000..5b7d939ae6 --- /dev/null +++ b/.github/workflows/merge-conflict-check.yml @@ -0,0 +1,65 @@ +name: Merge Conflict Check Workflow + +on: + pull_request: + branches: + - '**' + types: + - opened + - reopened + - synchronize + - ready_for_review + +jobs: + Merge-Conflict-Check: + name: Check for Merge Conflicts + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Check Mergeable Status via Github API + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + max_retries=3 + retry_delay=5 + + for ((i=1; i<=max_retries; i++)); do + echo "Attempt $i of $max_retries" + + if ! response=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" --jq '.mergeable'); then + if [[ $response == *"rate limit exceeded"* ]]; then + echo "Rate limit exceeded. Waiting before retry..." + sleep 60 # Wait longer for rate limit + else + echo "Failed to call GitHub API: $response" + if [ $i -eq $max_retries ]; then + echo "Maximum retries reached. Exiting." + exit 1 + fi + sleep $retry_delay + fi + continue + fi + + case "$response" in + "true") + echo "No conflicts detected." + exit 0 + ;; + "false") + echo "Merge conflicts detected." + exit 1 + ;; + *) + echo "Mergeable status unknown: $response" + if [ $i -eq $max_retries ]; then + echo "Maximum retries reached. Exiting." + exit 1 + fi + sleep $retry_delay + ;; + esac + done diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c42b0d19f6..f387698bce 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -15,14 +15,6 @@ on: pull_request: branches: - '**' - types: - - opened - - reopened - - synchronize - - ready_for_review - pull_request_target: - types: - - synchronize env: CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }} @@ -457,49 +449,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} GITHUB_REPOSITORY: ${{ github.repository }} - - Merge-Conflict-Check: - name: Check for Merge Conflicts - runs-on: ubuntu-latest - if: github.actor != 'dependabot[bot]' - needs: [Code-Quality-Checks] - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Check Mergeable Status via API - run: | - PR_NUMBER=${{ github.event.pull_request.number }} - max_retries=3 - retry_delay=5 - - for ((i=1; i<=max_retries; i++)); do - echo "Attempt $i of $max_retries" - - response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER") - - if [ $? -ne 0 ]; then - echo "Failed to call GitHub API" - if [ $i -eq $max_retries ]; then - exit 1 - fi - sleep $retry_delay - continue - fi - - mergeable=$(echo "$response" | jq -r '.mergeable') - if [ "$mergeable" == "true" ]; then - echo "No conflicts detected." - exit 0 - elif [ "$mergeable" == "false" ]; then - echo "Merge conflicts detected." - exit 1 - else - echo "Mergeable status unknown." - if [ $i -eq $max_retries ]; then - exit 1 - fi - sleep $retry_delay - fi - done \ No newline at end of file