From a5605d6c46c08ecda49fe545e2d7bff963466284 Mon Sep 17 00:00:00 2001 From: Daniil Leontiev Date: Sun, 21 Mar 2021 22:16:01 +0300 Subject: [PATCH] Add images size checking in PR (#281) * Add images size checking in PR * Fix typo * Switched to POSIX shell * More proper diff --- .github/workflows/pr.yaml | 12 ++++++++++++ .github/workflows/scripts/check-size.sh | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/workflows/pr.yaml create mode 100755 .github/workflows/scripts/check-size.sh diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..756bd07 --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,12 @@ +on: pull_request + +jobs: + check_size: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Check file size + run: .github/workflows/scripts/check-size.sh + diff --git a/.github/workflows/scripts/check-size.sh b/.github/workflows/scripts/check-size.sh new file mode 100755 index 0000000..15027bd --- /dev/null +++ b/.github/workflows/scripts/check-size.sh @@ -0,0 +1,25 @@ +#!/bin/sh +set -eu + +SIZE_LIMIT=150000 + +check_size() { + local size=$(stat --printf="%s" $1) + if [ "$size" -gt "$SIZE_LIMIT" ]; then + echo "File $1 is bigger than specified $SIZE_LIMIT limit" + exit 1 + fi +} + +git diff --name-only `git merge-base origin/master HEAD` | while IFS= read -r file; do + case "$file" in + *.webp) + echo "Checking size of $file" + check_size $file + ;; + *) + echo "Skipping $file" + ;; + esac +done +