From 226fb39a46ba41c70d82a0210b743678581aaff2 Mon Sep 17 00:00:00 2001 From: Hiroto Funakoshi Date: Tue, 30 Jul 2024 11:39:41 +0900 Subject: [PATCH] Add workflow to check git conflict for backport PR (#2548) * feat: add workflow to check conflict Signed-off-by: hlts2 * Apply suggestions from code review Signed-off-by: Yusuke Kato * feat: send conflict warning comment Signed-off-by: hlts2 * fix: verify for sending comment Signed-off-by: hlts2 * style: format code with Gofumpt and Prettier This commit fixes the style issues introduced in aee3f32 according to the output from Gofumpt and Prettier. Details: https://github.com/vdaas/vald/pull/2548 * fix: verify for sending comment Signed-off-by: hlts2 * fix: debug body Signed-off-by: hlts2 * fix: add log Signed-off-by: hlts2 * feat: add debug code Signed-off-by: hlts2 * fix: add debug Signed-off-by: hlts2 * fix: deleted unnecessary debug code Signed-off-by: hlts2 * fix: fails comment for sending comment Signed-off-by: hlts2 * fix: deleted unnecessary changes Signed-off-by: hlts2 * feat: fix grep condition Signed-off-by: hlts2 * fix: add changes for verify Signed-off-by: hlts2 * Revert "fix: add changes for verify" This reverts commit 98f4c442acd2769d375edcbf568d0675f4a5f094. * fix: add changes for verify Signed-off-by: hlts2 * Revert "fix: add changes for verify" This reverts commit 31ed2a80435c3ca4bd07e9d6892386a30776ed2a. --------- Signed-off-by: hlts2 Signed-off-by: Yusuke Kato Co-authored-by: Yusuke Kato Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- .github/workflows/check-conflict.yml | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/check-conflict.yml diff --git a/.github/workflows/check-conflict.yml b/.github/workflows/check-conflict.yml new file mode 100644 index 0000000000..d2eda8436f --- /dev/null +++ b/.github/workflows/check-conflict.yml @@ -0,0 +1,58 @@ +# +# Copyright (C) 2019-2024 vdaas.org vald team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +name: Check conflict +on: + pull_request: +jobs: + dump-contexts-to-log: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/dump-context + check-conflict: + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.DISPATCH_TOKEN }} + - name: Set Git config + run: | + git config --global --add safe.directory ${GITHUB_WORKSPACE} + - name: Check conflict + run: | + if grep -r "<<<< HEAD" . --exclude-dir=.git --exclude=check-conflict.yml; then + PR_COMMENTS=`curl ${API_URL}?per_page=10000` + BODY=`echo -E "${PR_COMMENTS}" | jq 'last(.[] | select(.user.login == "vdaas-ci") | select(.body | test("^\\\\*\\\\*\\\\[WARNING:CONFLICT")) | .body)' -r` + + if [ "${BODY}" = "null" ]; then + curl --include --verbose --fail \ + -H "Accept: application/json" \ + -H "Content-Type:application/json" \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + --request POST \ + --data "{\"body\": \"**[WARNING:CONFLICT]** You may require to fix the conflict. Please check.\"}" \ + ${API_URL} + fi + echo "Please fix conflict locally." + exit 1 + else + echo "Nothing conflict" + fi + env: + GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }} + API_URL: ${{ github.event.pull_request.comments_url }}