From 67c4492adce09accda88137612da71fa42f958cc Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Fri, 4 Aug 2023 16:01:30 +0100 Subject: [PATCH 1/7] add github workflow to check for apache license in prs --- .github/scripts/pr-issue-info/apache-check.md | 5 +++ .github/workflows/check-apache-license.yaml | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 .github/scripts/pr-issue-info/apache-check.md create mode 100644 .github/workflows/check-apache-license.yaml diff --git a/.github/scripts/pr-issue-info/apache-check.md b/.github/scripts/pr-issue-info/apache-check.md new file mode 100644 index 00000000000..fde9f5a287c --- /dev/null +++ b/.github/scripts/pr-issue-info/apache-check.md @@ -0,0 +1,5 @@ +Your pull request **can't** be merged due to missing the **Apache license** statement. + +Please add the following statement at the end of the pr description: + +`I submit this contribution under the Apache-2.0 license.` \ No newline at end of file diff --git a/.github/workflows/check-apache-license.yaml b/.github/workflows/check-apache-license.yaml new file mode 100644 index 00000000000..f40d1aab54c --- /dev/null +++ b/.github/workflows/check-apache-license.yaml @@ -0,0 +1,31 @@ +name: check-apache-license +on: + pull_request_target: + types: [opened, synchronize, edited, reopened] + branches: + - master + - apache_workflow +jobs: + check-license: + runs-on: ubuntu-latest + env: + BODY: ${{ github.event.pull_request.body }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + persist-credentials: false + sparse-checkout: | + .github/scripts/pr-issue-info/apache-check.md + - name: Check for Apache License + run: | + echo "$BODY" | grep -iPq "I submit this contribution under the Apache-2.0 license." || echo "CHECK_FAILED=true" >> $GITHUB_ENV + - name: Add comment if no license + if: env.CHECK_FAILED == 'true' + uses: thollander/actions-comment-pull-request@v2 + with: + filePath: .github/scripts/pr-issue-info/apache-check.md + GITHUB_TOKEN: ${{ secrets.KICS_BOT_PAT }} + - name: Fail the workflow if no license + if: env.CHECK_FAILED == 'true' + run: exit 1 \ No newline at end of file From 62ba29cf5ea9aaf0e5f45e8f033746dc6ff04ca9 Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Fri, 4 Aug 2023 16:13:04 +0100 Subject: [PATCH 2/7] changed apache comment message --- .github/scripts/pr-issue-info/apache-check.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/scripts/pr-issue-info/apache-check.md b/.github/scripts/pr-issue-info/apache-check.md index fde9f5a287c..278d2624ee1 100644 --- a/.github/scripts/pr-issue-info/apache-check.md +++ b/.github/scripts/pr-issue-info/apache-check.md @@ -2,4 +2,8 @@ Your pull request **can't** be merged due to missing the **Apache license** stat Please add the following statement at the end of the pr description: -`I submit this contribution under the Apache-2.0 license.` \ No newline at end of file +`I submit this contribution under the Apache-2.0 license.` + +Thank you! +
+*KICS Team* \ No newline at end of file From 9a531201eb689a274287e5a88207243783775526 Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Fri, 4 Aug 2023 16:15:06 +0100 Subject: [PATCH 3/7] changed apache comment message --- .github/scripts/pr-issue-info/apache-check.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/pr-issue-info/apache-check.md b/.github/scripts/pr-issue-info/apache-check.md index 278d2624ee1..b0a5f1a8727 100644 --- a/.github/scripts/pr-issue-info/apache-check.md +++ b/.github/scripts/pr-issue-info/apache-check.md @@ -5,5 +5,4 @@ Please add the following statement at the end of the pr description: `I submit this contribution under the Apache-2.0 license.` Thank you! -
*KICS Team* \ No newline at end of file From 0d3d4fed9432c0521e74a76df29696b35f095e1f Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Mon, 7 Aug 2023 16:35:56 +0100 Subject: [PATCH 4/7] only one most up to date comment and delete comment after fixing license --- .github/workflows/check-apache-license.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/check-apache-license.yaml b/.github/workflows/check-apache-license.yaml index f40d1aab54c..c3edc252315 100644 --- a/.github/workflows/check-apache-license.yaml +++ b/.github/workflows/check-apache-license.yaml @@ -20,11 +20,23 @@ jobs: - name: Check for Apache License run: | echo "$BODY" | grep -iPq "I submit this contribution under the Apache-2.0 license." || echo "CHECK_FAILED=true" >> $GITHUB_ENV + - name: Delete comment if license is fixed + if: env.CHECK_FAILED != 'true' + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + Deleting comment... + comment_tag: apache_license + mode: delete + GITHUB_TOKEN: ${{ secrets.KICS_BOT_PAT }} - name: Add comment if no license if: env.CHECK_FAILED == 'true' uses: thollander/actions-comment-pull-request@v2 with: filePath: .github/scripts/pr-issue-info/apache-check.md + comment_tag: apache_license + mode: recreate + create_if_not_exists: true GITHUB_TOKEN: ${{ secrets.KICS_BOT_PAT }} - name: Fail the workflow if no license if: env.CHECK_FAILED == 'true' From 568ac2179366745c07eb2c820772bb93a1148168 Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Tue, 8 Aug 2023 12:00:31 +0100 Subject: [PATCH 5/7] fixed step name --- .github/workflows/check-apache-license.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/check-apache-license.yaml b/.github/workflows/check-apache-license.yaml index c3edc252315..be1bda73e14 100644 --- a/.github/workflows/check-apache-license.yaml +++ b/.github/workflows/check-apache-license.yaml @@ -4,7 +4,6 @@ on: types: [opened, synchronize, edited, reopened] branches: - master - - apache_workflow jobs: check-license: runs-on: ubuntu-latest @@ -38,6 +37,6 @@ jobs: mode: recreate create_if_not_exists: true GITHUB_TOKEN: ${{ secrets.KICS_BOT_PAT }} - - name: Fail the workflow if no license + - name: Workflow failed if: env.CHECK_FAILED == 'true' run: exit 1 \ No newline at end of file From d3bb64c4e6ca297fa307e165103108dd51e2768f Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Fri, 11 Aug 2023 16:32:25 +0100 Subject: [PATCH 6/7] fixed regex of apache license sentence --- .github/scripts/pr-issue-info/apache-check.md | 2 ++ .github/workflows/check-apache-license.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/pr-issue-info/apache-check.md b/.github/scripts/pr-issue-info/apache-check.md index b0a5f1a8727..817d06b3686 100644 --- a/.github/scripts/pr-issue-info/apache-check.md +++ b/.github/scripts/pr-issue-info/apache-check.md @@ -4,5 +4,7 @@ Please add the following statement at the end of the pr description: `I submit this contribution under the Apache-2.0 license.` +In case the statement has already been added, make sure it is the last sentence in the description and the only one in its line. + Thank you! *KICS Team* \ No newline at end of file diff --git a/.github/workflows/check-apache-license.yaml b/.github/workflows/check-apache-license.yaml index be1bda73e14..5767cf55485 100644 --- a/.github/workflows/check-apache-license.yaml +++ b/.github/workflows/check-apache-license.yaml @@ -18,7 +18,7 @@ jobs: .github/scripts/pr-issue-info/apache-check.md - name: Check for Apache License run: | - echo "$BODY" | grep -iPq "I submit this contribution under the Apache-2.0 license." || echo "CHECK_FAILED=true" >> $GITHUB_ENV + echo "$BODY" | grep -iPq "^I submit this contribution under the Apache-2.0 license.$" || echo "CHECK_FAILED=true" >> $GITHUB_ENV - name: Delete comment if license is fixed if: env.CHECK_FAILED != 'true' uses: thollander/actions-comment-pull-request@v2 From 2961088af6ee177f79ad558569ba3ae0efb355dd Mon Sep 17 00:00:00 2001 From: Millena Santos Date: Fri, 11 Aug 2023 17:49:52 +0100 Subject: [PATCH 7/7] check if comment exists before deleting --- .github/workflows/check-apache-license.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-apache-license.yaml b/.github/workflows/check-apache-license.yaml index 5767cf55485..9033a97ff08 100644 --- a/.github/workflows/check-apache-license.yaml +++ b/.github/workflows/check-apache-license.yaml @@ -19,8 +19,18 @@ jobs: - name: Check for Apache License run: | echo "$BODY" | grep -iPq "^I submit this contribution under the Apache-2.0 license.$" || echo "CHECK_FAILED=true" >> $GITHUB_ENV - - name: Delete comment if license is fixed + - name: Check for comment tag if: env.CHECK_FAILED != 'true' + run: | + comments=$(curl -s -H "Authorization: token ${{ secrets.KICS_BOT_PAT }}" \ + -X GET "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments") + if echo "$comments" | grep -q "apache_license"; then + echo "TAG_EXISTS=true" >> $GITHUB_ENV + else + echo "TAG_EXISTS=false" >> $GITHUB_ENV + fi + - name: Delete comment if license is fixed + if: env.TAG_EXISTS == 'true' uses: thollander/actions-comment-pull-request@v2 with: message: |