Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/check-pr-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Check PR size

on:
pull_request:

jobs:
check_pr_size:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- 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" \
| grep -v "yarn.lock" \
| 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
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down