From 0ac9e32f1251bed0953e8afc6e603f50b1a044d2 Mon Sep 17 00:00:00 2001 From: sijmenhuizenga Date: Mon, 5 Oct 2020 16:03:14 +0200 Subject: [PATCH] Added workflow to automatically resize large gifs --- .github/workflows/resize-gifs.yml | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/resize-gifs.yml diff --git a/.github/workflows/resize-gifs.yml b/.github/workflows/resize-gifs.yml new file mode 100644 index 0000000..2697054 --- /dev/null +++ b/.github/workflows/resize-gifs.yml @@ -0,0 +1,38 @@ +name: Resize gifs + +on: + pull_request: + paths: + - 'public/images/*.gif' + +jobs: + resize-images: + name: resize image + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + # Ref needed to work on forked repo + ref: ${{ github.event.pull_request.head.ref }} + - name: Resize large images to 300px width + run: | + for filename in public/images/*.gif; do + width=$( identify -ping -format '%w ' $filename | cut -d " " -f 1) + if (( $width > 300 )); then + echo "GIF $filename has width $width. Resizing to 300px width" + mogrify -resize 300 $filename + else + echo "GIF $filename has width $width. Not resizing." + fi + done + - name: Add & Commit files + run: | + # only commit if files were changed + if [[ $(git diff --stat) != '' ]]; then + git config --local user.email github-actions@github.com + git config --local user.name github-actions + git add . + git commit -m "Resize large images to 300px" -a + git push + fi \ No newline at end of file