-
Notifications
You must be signed in to change notification settings - Fork 53
53 lines (49 loc) · 1.47 KB
/
restrict-pr-size.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: 'PR Size Checker'
on:
pull_request:
branches:
- main
env:
MAX_LINE_CHANGED: 1200 # Maximum number of lines changed allowed
TARGET_BRANCH: main
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
deployments: read
packages: none
steps:
# checkout your code with your git history
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- id: get_total_lines_changed
run: |
size=$(git diff --stat origin/${{ env.TARGET_BRANCH }} \
| grep -v .lock \
| grep -v Bin \
| awk -F"|" '{ print $2 }' \
| awk '{ print $1 }' \
| sed '/^$/d' \
| paste -sd+ - \
| bc)
echo "size=${size}" >> $GITHUB_ENV
echo ""
echo "Total lines changed (note: *.lock files are excluded from this count): "
echo $size
shell: bash
- run: |
COMMITMSG=$(git log --format=%B -n 1 ${{github.event.after}})
echo "${COMMITMSG}"
if [[ $size -gt ${{ env.MAX_LINE_CHANGED }} && "${COMMITMSG}" != *"[skip pr-size]"* ]]
then
echo "Warning - total lines changed is greater than" ${{ env.MAX_LINE_CHANGED }}.
echo "Please consider breaking this PR down."
exit 1
fi
shell: bash