Skip to content

Commit 26d998e

Browse files
Update check-pr-size.yml
1 parent 147428a commit 26d998e

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

.github/workflows/check-pr-size.yml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,38 @@ jobs:
99

1010
steps:
1111
- name: Checkout code
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v3
1313
with:
1414
fetch-depth: 0
1515

16-
- name: Check PR size
17-
uses: maidsafe/pr_size_checker@v2
18-
with:
19-
max_lines_changed: 500
16+
- name: Calculate changed lines
17+
id: diff_check
18+
run: |
19+
# Get the target branch commit (base) and the PR branch commit (head)
20+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
21+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
22+
echo "Base SHA: $BASE_SHA"
23+
echo "Head SHA: $HEAD_SHA"
24+
25+
# Compute the merge base between the two branches.
26+
MERGE_BASE=$(git merge-base "$HEAD_SHA" "$BASE_SHA")
27+
echo "Merge Base: $MERGE_BASE"
28+
29+
# Calculate added and deleted lines between the merge base and the head commit.
30+
TOTAL_CHANGED=$(git diff --numstat "$MERGE_BASE" "$HEAD_SHA" \
31+
| awk '{ added += $1; deleted += $2 } END { print added + deleted }')
32+
33+
# Default to 0 if nothing is output.
34+
TOTAL_CHANGED=${TOTAL_CHANGED:-0}
35+
echo "Total changed lines: $TOTAL_CHANGED"
36+
37+
# Make the total available for later steps.
38+
echo "total=$TOTAL_CHANGED" >> "$GITHUB_OUTPUT"
39+
40+
- name: Fail if too many changes
41+
if: ${{ steps.diff_check.outputs.total > 500 }}
42+
run: |
43+
echo "PR has ${{ steps.diff_check.outputs.total }} changed lines, which exceeds the 500-line limit."
44+
echo "Please reduce the size of this PR."
45+
exit 1
46+

0 commit comments

Comments
 (0)