From eb63d40a0f86cd93923e05050efeab1e07b21d4a Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Mon, 12 May 2025 16:10:00 -0700 Subject: [PATCH 1/4] Added workflow to disallow large PRs --- .github/workflows/large-prs.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/large-prs.yml diff --git a/.github/workflows/large-prs.yml b/.github/workflows/large-prs.yml new file mode 100644 index 000000000000..40fc09dd9b45 --- /dev/null +++ b/.github/workflows/large-prs.yml @@ -0,0 +1,24 @@ +name: "Detect large PRs" +permissions: read-all + +on: + pull_request + +jobs: + disallow-submodules: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 + - name: Check PR size + run: | + response=$(curl --get -Ss -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/pulls/${{github.event.pull_request.number}}") + additions=$(echo "$response" | jq -r '.additions') + deletions=$(echo "$response" | jq -r '.deletions') + echo "$additions lines added; $deletions lines deleted" + if (( $additions + $deletions > 500 )); then + echo "This PR changed more than 500 lines of code, which is too large. Your reviewer may ask you to break it into multiple PRs." + exit 1 + else + echo "This PR changed 500 or fewer lines of code." + fi From 951f48df26713b66c32cc5e3a8654c87ba468292 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Mon, 12 May 2025 16:14:27 -0700 Subject: [PATCH 2/4] Combined with disallow-submodules --- .../{large-prs.yml => basic-pr-checks.yml} | 15 ++++++++++++- .github/workflows/disallow-submodules.yml | 22 ------------------- 2 files changed, 14 insertions(+), 23 deletions(-) rename .github/workflows/{large-prs.yml => basic-pr-checks.yml} (72%) delete mode 100644 .github/workflows/disallow-submodules.yml diff --git a/.github/workflows/large-prs.yml b/.github/workflows/basic-pr-checks.yml similarity index 72% rename from .github/workflows/large-prs.yml rename to .github/workflows/basic-pr-checks.yml index 40fc09dd9b45..96228fbfcbb2 100644 --- a/.github/workflows/large-prs.yml +++ b/.github/workflows/basic-pr-checks.yml @@ -1,4 +1,4 @@ -name: "Detect large PRs" +name: "Basic PR checks" permissions: read-all on: @@ -10,6 +10,19 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 + - name: Check for submodules + run: | + output=$(git submodule status --recursive 2>&1) + if [ ! -z $output ]; then + echo $output + echo "Submodules are not allowed" + exit 1 + else + echo "No submodules found" + fi + disallow-large-prs: + runs-on: ubuntu-22.04 + steps: - name: Check PR size run: | response=$(curl --get -Ss -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/pulls/${{github.event.pull_request.number}}") diff --git a/.github/workflows/disallow-submodules.yml b/.github/workflows/disallow-submodules.yml deleted file mode 100644 index c61685931565..000000000000 --- a/.github/workflows/disallow-submodules.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: "Disallow submodules" -permissions: read-all - -on: - pull_request - -jobs: - disallow-submodules: - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 - - name: Check for submodules - run: | - output=$(git submodule status --recursive 2>&1) - if [ ! -z $output ]; then - echo $output - echo "Submodules are not allowed" - exit 1 - else - echo "No submodules found" - fi From fa19c13d02d020a422620d1aba00466a75bdd33d Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Mon, 12 May 2025 16:17:40 -0700 Subject: [PATCH 3/4] Added total to output --- .github/workflows/basic-pr-checks.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/basic-pr-checks.yml b/.github/workflows/basic-pr-checks.yml index 96228fbfcbb2..20b2e3debb00 100644 --- a/.github/workflows/basic-pr-checks.yml +++ b/.github/workflows/basic-pr-checks.yml @@ -28,10 +28,11 @@ jobs: response=$(curl --get -Ss -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/pulls/${{github.event.pull_request.number}}") additions=$(echo "$response" | jq -r '.additions') deletions=$(echo "$response" | jq -r '.deletions') + total=(( $additions + $deletions )) echo "$additions lines added; $deletions lines deleted" - if (( $additions + $deletions > 500 )); then - echo "This PR changed more than 500 lines of code, which is too large. Your reviewer may ask you to break it into multiple PRs." + if (( $total > 500 )); then + echo "This PR changed $total lines of code, which is above the recommended limit of 500. Your reviewer may ask you to break it into multiple PRs." exit 1 else - echo "This PR changed 500 or fewer lines of code." + echo "This PR changed $total lines of code, which meets the recommended limit of 500." fi From e4025634bc0a40cce8bd12ad07d35ecc59432f13 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Mon, 12 May 2025 16:18:47 -0700 Subject: [PATCH 4/4] Fixed bash syntax --- .github/workflows/basic-pr-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/basic-pr-checks.yml b/.github/workflows/basic-pr-checks.yml index 20b2e3debb00..23d676229e7b 100644 --- a/.github/workflows/basic-pr-checks.yml +++ b/.github/workflows/basic-pr-checks.yml @@ -28,7 +28,7 @@ jobs: response=$(curl --get -Ss -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/pulls/${{github.event.pull_request.number}}") additions=$(echo "$response" | jq -r '.additions') deletions=$(echo "$response" | jq -r '.deletions') - total=(( $additions + $deletions )) + total=$(( $additions + $deletions )) echo "$additions lines added; $deletions lines deleted" if (( $total > 500 )); then echo "This PR changed $total lines of code, which is above the recommended limit of 500. Your reviewer may ask you to break it into multiple PRs."