From 91eba1dc5b95fdf3707a0b9e9a786c0df0cf97c0 Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 11:28:04 +0000 Subject: [PATCH 1/7] ci: add a gh action to check diff size on pr --- .github/workflows/check-diff-size.yml | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/check-diff-size.yml diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml new file mode 100644 index 0000000000..7482672b2b --- /dev/null +++ b/.github/workflows/check-diff-size.yml @@ -0,0 +1,28 @@ +name: Test + +on: + pull_request: + +jobs: + + check-diff: + name: Check diff size + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: "Check that diff isn't too large" + run: | + FILES_CHANGED=$(git diff origin/${{github.base_ref}}...origin/${{github.head_ref}} --name-status | wc -l) + if [ $FILES_CHANGED > 10 ] + then + echo "The diff is too large. Please the check the number of files changed in your PR!" + exit 1 + else + echo "The diff looks nice and small - good work! 😎" + exit 0 + fi + \ No newline at end of file From e3fdcfe9f52f933bf02e33cc0589d28fd60bfbb2 Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 13:04:25 +0000 Subject: [PATCH 2/7] log files_changed --- .github/workflows/check-diff-size.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml index 7482672b2b..c4eb185753 100644 --- a/.github/workflows/check-diff-size.yml +++ b/.github/workflows/check-diff-size.yml @@ -19,6 +19,7 @@ jobs: FILES_CHANGED=$(git diff origin/${{github.base_ref}}...origin/${{github.head_ref}} --name-status | wc -l) if [ $FILES_CHANGED > 10 ] then + echo $FILES_CHANGED echo "The diff is too large. Please the check the number of files changed in your PR!" exit 1 else From b315cb2f9840b2a386b411fd9ae319f09bfce2b2 Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 13:06:22 +0000 Subject: [PATCH 3/7] update comparison operator for bash if statement --- .github/workflows/check-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml index c4eb185753..11761d2839 100644 --- a/.github/workflows/check-diff-size.yml +++ b/.github/workflows/check-diff-size.yml @@ -17,7 +17,7 @@ jobs: - name: "Check that diff isn't too large" run: | FILES_CHANGED=$(git diff origin/${{github.base_ref}}...origin/${{github.head_ref}} --name-status | wc -l) - if [ $FILES_CHANGED > 10 ] + if [ $FILES_CHANGED -gt 10 ] then echo $FILES_CHANGED echo "The diff is too large. Please the check the number of files changed in your PR!" From 4e6b386468ed25b109dcaf1ffb451b64cea547ff Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 13:10:20 +0000 Subject: [PATCH 4/7] ad files_changed to the bash output --- .github/workflows/check-diff-size.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml index 11761d2839..6a06aea96c 100644 --- a/.github/workflows/check-diff-size.yml +++ b/.github/workflows/check-diff-size.yml @@ -17,10 +17,10 @@ jobs: - name: "Check that diff isn't too large" run: | FILES_CHANGED=$(git diff origin/${{github.base_ref}}...origin/${{github.head_ref}} --name-status | wc -l) + echo "Number of files changed in this PR: ${FILES_CHANGED}" if [ $FILES_CHANGED -gt 10 ] then - echo $FILES_CHANGED - echo "The diff is too large. Please the check the number of files changed in your PR!" + echo "The diff is too large. You've changed ${FILES_CHANGED) in this PR!" exit 1 else echo "The diff looks nice and small - good work! 😎" From 8d0a6d1d6c773429e835a9babc48b2265d33f150 Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 13:15:52 +0000 Subject: [PATCH 5/7] correct to curly brace in string interpolation --- .github/workflows/check-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml index 6a06aea96c..a31ffb7712 100644 --- a/.github/workflows/check-diff-size.yml +++ b/.github/workflows/check-diff-size.yml @@ -20,7 +20,7 @@ jobs: echo "Number of files changed in this PR: ${FILES_CHANGED}" if [ $FILES_CHANGED -gt 10 ] then - echo "The diff is too large. You've changed ${FILES_CHANGED) in this PR!" + echo "The diff is too large. You've changed ${FILES_CHANGED} in this PR!" exit 1 else echo "The diff looks nice and small - good work! 😎" From 30dfac4c512549035eba06669611b26c1256ab85 Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 16:01:36 +0000 Subject: [PATCH 6/7] use gh cli command --- .github/workflows/check-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml index a31ffb7712..fd09d931ae 100644 --- a/.github/workflows/check-diff-size.yml +++ b/.github/workflows/check-diff-size.yml @@ -16,7 +16,7 @@ jobs: - name: "Check that diff isn't too large" run: | - FILES_CHANGED=$(git diff origin/${{github.base_ref}}...origin/${{github.head_ref}} --name-status | wc -l) + FILES_CHANGED=$(gh pr diff ${{github.event.pull_request.number}} --name-only | wc -l) echo "Number of files changed in this PR: ${FILES_CHANGED}" if [ $FILES_CHANGED -gt 10 ] then From 709fd1d496f9a1b27d89fe7943e300c123905194 Mon Sep 17 00:00:00 2001 From: Dedekind561 Date: Tue, 7 Feb 2023 16:06:33 +0000 Subject: [PATCH 7/7] set github token in env --- .github/workflows/check-diff-size.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-diff-size.yml b/.github/workflows/check-diff-size.yml index fd09d931ae..b2dcc67798 100644 --- a/.github/workflows/check-diff-size.yml +++ b/.github/workflows/check-diff-size.yml @@ -15,6 +15,8 @@ jobs: fetch-depth: 0 - name: "Check that diff isn't too large" + env: + GH_TOKEN: ${{ github.token }} run: | FILES_CHANGED=$(gh pr diff ${{github.event.pull_request.number}} --name-only | wc -l) echo "Number of files changed in this PR: ${FILES_CHANGED}"