diff --git a/.github/workflows/check-pr-size.yml b/.github/workflows/check-pr-size.yml new file mode 100644 index 00000000..6289183a --- /dev/null +++ b/.github/workflows/check-pr-size.yml @@ -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 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 0a1f9247..7e9a6ad6 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: