-
Notifications
You must be signed in to change notification settings - Fork 1
45 lines (44 loc) · 1.37 KB
/
image-optimize-actions.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
name: Compress Images on Push to Main with Commit
on:
push:
branches:
- main
paths:
- 'content/uploads/**.jpg'
- 'content/uploads/**.jpeg'
- 'content/uploads/**.png'
- 'content/uploads/**.webp'
- 'content/posts/**/**.jpg'
- 'content/posts/**/**.jpeg'
- 'content/posts/**/**.png'
- 'content/posts/**/**.webp'
jobs:
build:
name: optimize-images
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@main
- name: Resize Images
id: resize-images
uses: gonzalonaveira/gh-image-resizing@master
with:
IMAGES_MAX_WIDTH: "1080"
IMAGES_QUALITY: "80"
IMAGES_FORMATS: "jpg, jpeg, png, webp"
IMAGES_DIRECTORIES: "content/uploads,content/posts"
- name: Commit changes direct to main
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "Committing compressed images"
git config --global user.email "[email protected]"
git config --global user.name "Peter"
git stash clear
git stash
git pull
git stash pop
git diff-index --quiet HEAD || git commit -am "Compressing images"
git push
else
echo "There are no changes to commit";
fi