From af198a06d36639062fb8261c2c4e141768548def Mon Sep 17 00:00:00 2001 From: "benjamin.ayliffe" Date: Tue, 2 Jan 2024 14:42:36 +0000 Subject: [PATCH] A size checker action which checks for files > 100KB. If any files being added or changed by a pull request are larger in size than 100KB this test will fail and print the list of files that exceed this threshold size. --- .github/workflows/size_check.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/size_check.yml diff --git a/.github/workflows/size_check.yml b/.github/workflows/size_check.yml new file mode 100644 index 0000000..c518b5a --- /dev/null +++ b/.github/workflows/size_check.yml @@ -0,0 +1,20 @@ +name: Enforce 100KB size limit +on: + pull_request +jobs: + checks: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 2 + # Check only files modified by this change to see if any exceed 100K + - name: Size check + run: | + changed=$(git diff --name-only -r HEAD^1 HEAD) + if [[ -z $changed ]]; then exit 0; fi + big=$(find $changed -size +50k -size -100k) + if [[ -n $big ]]; then for file in $big; do echo "::warning file=${file},title=Large file::This file is >50KB, consider shrinking it if possible."; done; fi + too_large=$(find $changed -size +100k) + if [[ -n $too_large ]]; then for file in $too_large; do echo "::error file=${file},title=File too large::This file is >100KB and must be shrunk prior to being comitted."; done; exit 1; fi