-
Notifications
You must be signed in to change notification settings - Fork 0
37 lines (35 loc) · 1.3 KB
/
image-optimization.yml
File metadata and controls
37 lines (35 loc) · 1.3 KB
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
name: Image Optimization
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
optimize:
name: Optimize images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install optimization tools
run: |
npm init -y
npm install -D svgo imagemin-cli imagemin-mozjpeg imagemin-pngquant
- name: Optimize SVGs with SVGO
run: npx svgo -f assets --config=./.svgo.yml || true
- name: Optimize raster images (lossless)
run: npx imagemin "assets/*.{png,jpg,jpeg}" --out-dir=assets || true
- name: Commit optimized assets
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add assets || true
if ! git diff --cached --quiet; then
git commit -m "chore: optimize images (automated)" || true
git push
else
echo "No changes to commit"
fi