From 53fccf6aa342b03836489888c6a3df7e13df58c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 25 Feb 2025 12:35:00 +0100 Subject: [PATCH 1/6] Check PR size --- .github/workflows/pull-request.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 0a1f9247..214aa806 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -1,10 +1,10 @@ -name: Some pull request checks +name: Pull request checks on: pull_request: jobs: - type-check: + checks: runs-on: windows-latest steps: @@ -16,6 +16,11 @@ jobs: with: node-version: 18 + - name: Check PR size + - uses: maidsafe/pr_size_checker@v2 + with: + max_lines_changed: 500 + - name: Install dependencies run: yarn install --ignore-scripts From 406087baec88978b007e749cd1d948721abb1df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 25 Feb 2025 12:43:03 +0100 Subject: [PATCH 2/6] Update pull-request.yml --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 214aa806..f46b430b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -17,7 +17,7 @@ jobs: node-version: 18 - name: Check PR size - - uses: maidsafe/pr_size_checker@v2 + uses: maidsafe/pr_size_checker@v2 with: max_lines_changed: 500 From fb5df581aa0dcf8e2d2970497ed542a4f5ce158a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 25 Feb 2025 12:44:54 +0100 Subject: [PATCH 3/6] Split check PR size --- .github/workflows/check-pr-size.yml | 17 +++++++++++++++++ .github/workflows/pull-request.yml | 5 ----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/check-pr-size.yml diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml new file mode 100644 index 00000000..dcac5602 --- /dev/null +++ b/.github/workflows/check-pr-size.yml @@ -0,0 +1,17 @@ +name: Check PR size + +on: + pull_request: + +jobs: + checks: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Check PR size + uses: maidsafe/pr_size_checker@v2 + with: + max_lines_changed: 500 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f46b430b..7e9a6ad6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -16,11 +16,6 @@ jobs: with: node-version: 18 - - name: Check PR size - uses: maidsafe/pr_size_checker@v2 - with: - max_lines_changed: 500 - - name: Install dependencies run: yarn install --ignore-scripts From 147428a6629d454f37e28804e5fdd477373c9232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 25 Feb 2025 12:47:59 +0100 Subject: [PATCH 4/6] Update check-pr-size.yml --- .github/workflows/check-pr-size.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml index dcac5602..d5d0d376 100644 --- a/.github/workflows/check-pr-size.yml +++ b/.github/workflows/check-pr-size.yml @@ -4,12 +4,14 @@ on: pull_request: jobs: - checks: + check_pr_size: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Check PR size uses: maidsafe/pr_size_checker@v2 From 26d998e253dcd32ef77192b4ba19c4fb680375d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 25 Feb 2025 13:07:15 +0100 Subject: [PATCH 5/6] Update check-pr-size.yml --- .github/workflows/check-pr-size.yml | 37 +++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml index d5d0d376..d19b4d0c 100644 --- a/.github/workflows/check-pr-size.yml +++ b/.github/workflows/check-pr-size.yml @@ -9,11 +9,38 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Check PR size - uses: maidsafe/pr_size_checker@v2 - with: - max_lines_changed: 500 + - name: Calculate changed lines + id: diff_check + run: | + # Get the target branch commit (base) and the PR branch commit (head) + BASE_SHA="${{ github.event.pull_request.base.sha }}" + HEAD_SHA="${{ github.event.pull_request.head.sha }}" + echo "Base SHA: $BASE_SHA" + echo "Head SHA: $HEAD_SHA" + + # Compute the merge base between the two branches. + MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA") + echo "Merge Base: $MERGE_BASE" + + # Calculate added and deleted lines between the merge base and the head commit. + TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \ + | awk '{ added += $1; deleted += $2 } END { print added + deleted }') + + # Default to 0 if nothing is output. + TOTAL_CHANGED=${TOTAL_CHANGED:-0} + echo "Total changed lines: $TOTAL_CHANGED" + + # Make the total available for later steps. + echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT" + + - name: Fail if too many changes + if: ${{ steps.diff_check.outputs.total > 500 }} + run: | + echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit." + echo "Please reduce the size of this PR." + exit 1 + From 374d011e2c4cb726c7dee893858a0008507cd1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jim=C3=A9nez=20Rivera?= Date: Tue, 25 Feb 2025 13:09:18 +0100 Subject: [PATCH 6/6] Update check-pr-size.yml --- .github/workflows/check-pr-size.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml index d19b4d0c..6289183a 100644 --- a/.github/workflows/check-pr-size.yml +++ b/.github/workflows/check-pr-size.yml @@ -22,19 +22,20 @@ jobs: echo "Base SHA: $BASE_SHA" echo "Head SHA: $HEAD_SHA" - # Compute the merge base between the two branches. + # Compute the merge base between the two branches MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA") echo "Merge Base: $MERGE_BASE" - # Calculate added and deleted lines between the merge base and the head commit. + # Calculate added and deleted lines between the merge base and the head commit TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \ + | grep -v "yarn.lock" \ | awk '{ added += $1; deleted += $2 } END { print added + deleted }') - # Default to 0 if nothing is output. + # Default to 0 if nothing is output TOTAL_CHANGED=${TOTAL_CHANGED:-0} echo "Total changed lines: $TOTAL_CHANGED" - # Make the total available for later steps. + # Make the total available for later steps echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT" - name: Fail if too many changes @@ -43,4 +44,3 @@ jobs: echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit." echo "Please reduce the size of this PR." exit 1 -