From 6cf93e42660cebe9f6c0c26d442a0f919845cb05 Mon Sep 17 00:00:00 2001 From: ccamel Date: Mon, 25 Sep 2023 13:40:05 +0200 Subject: [PATCH] ci(workflow): add lint-image-size job --- .github/workflows/lint.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a4023fc11d8..0967790c438 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -84,7 +84,7 @@ jobs: if [[ $type =~ ^(WEBP|SVG|ICO)$ ]]; then echo "✅ $file" else - >&2 echo "❌ $file incorrect. Please use only webp or svg format 🙏" + >&2 echo "❌ $file incorrect. Please use only webp or svg format. 🙏" FAILED=1 fi done @@ -94,6 +94,31 @@ jobs: env: FOLDER: ./static + lint-image-size: + runs-on: ubuntu-22.04 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Lint image files + run: | + MAX_SIZE=200000 + FAILED=0 + for file in $(find "$FOLDER" -regextype posix-egrep -regex '.+\.(bmp|ico|jpg|jpeg|png|svg|webp)'); do + size=$(wc -c "$file" | awk '{print $1}') + if [ "$size" -gt "$MAX_SIZE" ]; then + >&2 echo "❌ $file is $size. Please reduce its size to a maximum of $MAX_SIZE. 🙏" + FAILED=1 + else + echo "✅ $file" + fi + done + if [ "${FAILED}" = "1" ]; then + exit 1 + fi + env: + FOLDER: ./static + report-new-dependencies: runs-on: ubuntu-22.04 if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'