From 7e57cf7d4eb984501f9ea6425fc8641f74262740 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:10:41 -0700 Subject: [PATCH 1/8] Github action asserting license statement in PR description --- .../workflows/assert_license_statement.yml | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/assert_license_statement.yml diff --git a/.github/workflows/assert_license_statement.yml b/.github/workflows/assert_license_statement.yml new file mode 100644 index 0000000000..76ccbb531e --- /dev/null +++ b/.github/workflows/assert_license_statement.yml @@ -0,0 +1,36 @@ +name: Assert PR description license statement +on: + pull_request: + types: [opened, edited] +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true +jobs: + check-pr-description: + if: github.repository_owner == 'aws' + runs-on: ubuntu-latest + + steps: + - name: Install jq + run: | + sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none + sudo apt-get install -y jq + + - name: Check PR description + run: | + # Fetches the PR description. + PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body) + + LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." + + echo "PR description: ${PR_DESCRIPTION}" + echo "Must contain: ${LICENSE_STATEMENT}" + + # Assert this is the case. + if echo "${PR_DESCRIPTION}" | grep -q "${LICENSE_STATEMENT}"; then + echo "PR description contains license statement." + else + echo "Error: PR description does not contain the required license statement." + exit 1 + fi From 3c0b054b5576930d3faee8c5c1d5a9b08c4fd739 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:24:49 -0700 Subject: [PATCH 2/8] Match exact --- .github/workflows/assert_license_statement.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assert_license_statement.yml b/.github/workflows/assert_license_statement.yml index 76ccbb531e..938d5e10e2 100644 --- a/.github/workflows/assert_license_statement.yml +++ b/.github/workflows/assert_license_statement.yml @@ -28,7 +28,7 @@ jobs: echo "Must contain: ${LICENSE_STATEMENT}" # Assert this is the case. - if echo "${PR_DESCRIPTION}" | grep -q "${LICENSE_STATEMENT}"; then + if echo "${PR_DESCRIPTION}" | grep -xq "${LICENSE_STATEMENT}"; then echo "PR description contains license statement." else echo "Error: PR description does not contain the required license statement." From 910009ccb81f58c185d04e5c6dfe33050d9e2f6f Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:32:29 -0700 Subject: [PATCH 3/8] Also trigger for push updates --- .github/workflows/assert_license_statement.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/assert_license_statement.yml b/.github/workflows/assert_license_statement.yml index 938d5e10e2..b7d9c6b63d 100644 --- a/.github/workflows/assert_license_statement.yml +++ b/.github/workflows/assert_license_statement.yml @@ -1,5 +1,7 @@ name: Assert PR description license statement on: + push: + branches: [ '*' ] pull_request: types: [opened, edited] concurrency: From 336273e3f4beaa23193aa39c6ef6c548b19a9868 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:39:13 -0700 Subject: [PATCH 4/8] Rework into existing action --- .../workflows/assert_license_statement.yml | 38 ------------------- .github/workflows/misc-tests.yaml | 31 ++++++++++++++- 2 files changed, 30 insertions(+), 39 deletions(-) delete mode 100644 .github/workflows/assert_license_statement.yml diff --git a/.github/workflows/assert_license_statement.yml b/.github/workflows/assert_license_statement.yml deleted file mode 100644 index b7d9c6b63d..0000000000 --- a/.github/workflows/assert_license_statement.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Assert PR description license statement -on: - push: - branches: [ '*' ] - pull_request: - types: [opened, edited] -concurrency: - group: ${{ github.workflow }}-${{ github.ref_name }} - cancel-in-progress: true -jobs: - check-pr-description: - if: github.repository_owner == 'aws' - runs-on: ubuntu-latest - - steps: - - name: Install jq - run: | - sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none - sudo apt-get install -y jq - - - name: Check PR description - run: | - # Fetches the PR description. - PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body) - - LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." - - echo "PR description: ${PR_DESCRIPTION}" - echo "Must contain: ${LICENSE_STATEMENT}" - - # Assert this is the case. - if echo "${PR_DESCRIPTION}" | grep -xq "${LICENSE_STATEMENT}"; then - echo "PR description contains license statement." - else - echo "Error: PR description does not contain the required license statement." - exit 1 - fi diff --git a/.github/workflows/misc-tests.yaml b/.github/workflows/misc-tests.yaml index 126111a88c..b1ebc7318d 100644 --- a/.github/workflows/misc-tests.yaml +++ b/.github/workflows/misc-tests.yaml @@ -1,4 +1,4 @@ -name: Misc tests +name: Miscellaneous test jobs on: push: branches: [ '*' ] @@ -26,3 +26,32 @@ jobs: - name: Test sandbox configuration run: | ./tests/ci/run_presandbox_tests.sh + + assert-license-statement-in-pr-description: + if: github.repository_owner == 'aws' + runs-on: ubuntu-latest + + steps: + - name: Install jq + run: | + sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none + sudo apt-get install -y jq + + - name: Check PR description + run: | + # Fetches the PR description. + PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body) + + LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." + + echo "PR description: ${PR_DESCRIPTION}" + echo "Must contain: ${LICENSE_STATEMENT}" + + # Assert this is the case. + if echo "${PR_DESCRIPTION}" | grep -xq "${LICENSE_STATEMENT}"; then + echo "PR description contains license statement." + else + echo "Error: PR description does not contain the required license statement." + exit 1 + fi From a8755b80af02f94998a28cdc519c37f9c58fc5d6 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:57:51 -0700 Subject: [PATCH 5/8] Better debug separation --- .github/workflows/misc-tests.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/misc-tests.yaml b/.github/workflows/misc-tests.yaml index b1ebc7318d..929b322039 100644 --- a/.github/workflows/misc-tests.yaml +++ b/.github/workflows/misc-tests.yaml @@ -45,11 +45,14 @@ jobs: LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." + echo "" echo "PR description: ${PR_DESCRIPTION}" + echo "" echo "Must contain: ${LICENSE_STATEMENT}" + echo "" # Assert this is the case. - if echo "${PR_DESCRIPTION}" | grep -xq "${LICENSE_STATEMENT}"; then + if echo "${PR_DESCRIPTION}" | grep -xiq "${LICENSE_STATEMENT}"; then echo "PR description contains license statement." else echo "Error: PR description does not contain the required license statement." From f02080499ecbd099f939e662c780c263e1c01828 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 09:11:39 -0700 Subject: [PATCH 6/8] Okay try something more pedantic --- .github/workflows/misc-tests.yaml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/misc-tests.yaml b/.github/workflows/misc-tests.yaml index 929b322039..24921f1c58 100644 --- a/.github/workflows/misc-tests.yaml +++ b/.github/workflows/misc-tests.yaml @@ -43,17 +43,24 @@ jobs: PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body) + # Normalize line endings (convert CRLF to LF) + PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | tr -d '\r') + + # Escape quotes in PR description + PR_DESCRIPTION=$(echo "$PR_DESCRIPTION" | sed 's/"/\\"/g; s/'"'"'/\\'"'"'/g') + LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." + printf "PR description:\n%s" "${PR_DESCRIPTION}" + echo "" echo "" - echo "PR description: ${PR_DESCRIPTION}" + printf "Must contain:\n%s" "${LICENSE_STATEMENT}" echo "" - echo "Must contain: ${LICENSE_STATEMENT}" echo "" # Assert this is the case. - if echo "${PR_DESCRIPTION}" | grep -xiq "${LICENSE_STATEMENT}"; then - echo "PR description contains license statement." + if printf "%s\n" "${PR_DESCRIPTION}" | grep -ixq "${LICENSE_STATEMENT}"; then + echo "Success: PR description contains license statement." else echo "Error: PR description does not contain the required license statement." exit 1 From e9340cc8f247c51fbac0f7a5c6ee7d4a48f7fbbb Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 09:19:31 -0700 Subject: [PATCH 7/8] Last experiment --- .github/workflows/misc-tests.yaml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/misc-tests.yaml b/.github/workflows/misc-tests.yaml index 24921f1c58..57f6b441a6 100644 --- a/.github/workflows/misc-tests.yaml +++ b/.github/workflows/misc-tests.yaml @@ -43,18 +43,32 @@ jobs: PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body) + printf "PR description:\n%s" "${PR_DESCRIPTION}" + echo "" + echo "" + # Normalize line endings (convert CRLF to LF) PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | tr -d '\r') + # Remove all spaces and tabs + PR_DESCRIPTION=$(echo "$PR_DESCRIPTION" | tr -d ' \t') + # Escape quotes in PR description PR_DESCRIPTION=$(echo "$PR_DESCRIPTION" | sed 's/"/\\"/g; s/'"'"'/\\'"'"'/g') LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." - printf "PR description:\n%s" "${PR_DESCRIPTION}" + printf "Must contain:\n%s" "${LICENSE_STATEMENT}" echo "" echo "" - printf "Must contain:\n%s" "${LICENSE_STATEMENT}" + + # Remove all spaces and tabs + LICENSE_STATEMENT=$(echo "$LICENSE_STATEMENT" | tr -d ' \t') + + printf "PR description trimmed:\n%s" "${PR_DESCRIPTION}" + echo "" + echo "" + printf "Must contain trimmed:\n%s" "${LICENSE_STATEMENT}" echo "" echo "" From 0f546cf9d4cf2ab0fbadabc9230c851445704f05 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Tue, 1 Oct 2024 09:28:00 -0700 Subject: [PATCH 8/8] Clean up script --- .github/workflows/misc-tests.yaml | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/misc-tests.yaml b/.github/workflows/misc-tests.yaml index 57f6b441a6..9e5253ea1b 100644 --- a/.github/workflows/misc-tests.yaml +++ b/.github/workflows/misc-tests.yaml @@ -39,6 +39,9 @@ jobs: - name: Check PR description run: | + # License statement we want present. + LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." + # Fetches the PR description. PR_DESCRIPTION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .body) @@ -46,24 +49,19 @@ jobs: printf "PR description:\n%s" "${PR_DESCRIPTION}" echo "" echo "" + printf "Must contain:\n%s" "${LICENSE_STATEMENT}" + echo "" + echo "" # Normalize line endings (convert CRLF to LF) PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | tr -d '\r') - # Remove all spaces and tabs - PR_DESCRIPTION=$(echo "$PR_DESCRIPTION" | tr -d ' \t') - # Escape quotes in PR description - PR_DESCRIPTION=$(echo "$PR_DESCRIPTION" | sed 's/"/\\"/g; s/'"'"'/\\'"'"'/g') - - LICENSE_STATEMENT="By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license." - - printf "Must contain:\n%s" "${LICENSE_STATEMENT}" - echo "" - echo "" + PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | sed 's/"/\\"/g; s/'"'"'/\\'"'"'/g') # Remove all spaces and tabs - LICENSE_STATEMENT=$(echo "$LICENSE_STATEMENT" | tr -d ' \t') + PR_DESCRIPTION=$(echo "${PR_DESCRIPTION}" | tr -d ' \t') + LICENSE_STATEMENT=$(echo "${LICENSE_STATEMENT}" | tr -d ' \t') printf "PR description trimmed:\n%s" "${PR_DESCRIPTION}" echo "" @@ -72,7 +70,7 @@ jobs: echo "" echo "" - # Assert this is the case. + # Assert PR description contains license statement. if printf "%s\n" "${PR_DESCRIPTION}" | grep -ixq "${LICENSE_STATEMENT}"; then echo "Success: PR description contains license statement." else