Skip to content

Commit 80c9426

Browse files
authored
build: add SVGO for image optimization (#300)
1 parent b050a33 commit 80c9426

File tree

11 files changed

+91
-170
lines changed

11 files changed

+91
-170
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Optimize Images
2+
3+
# **What it does**: Automatically compress and optimize images.
4+
# **Why we have it**: Reduces bandwidth needs of app and repo.
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- '**.jpg'
12+
- '**.jpeg'
13+
- '**.png'
14+
- '**.webp'
15+
- '**.svg'
16+
pull_request:
17+
paths:
18+
- '**.jpg'
19+
- '**.jpeg'
20+
- '**.png'
21+
- '**.webp'
22+
- '**.svg'
23+
workflow_dispatch:
24+
25+
permissions:
26+
contents: read
27+
28+
jobs:
29+
build:
30+
name: Optimize Images
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: write
34+
pull-requests: write
35+
# Only run on main repo and PRs that match the main repo
36+
if: >
37+
github.repository == 'fastify/website' && (github.event_name != 'pull_request' ||
38+
github.event.pull_request.head.repo.full_name == github.repository)
39+
40+
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
with:
45+
persist-credentials: false
46+
ref: main
47+
48+
- name: Optimize svg images
49+
run: |
50+
npx svgo -rf ./static/img
51+
52+
- name: Verify Changed files
53+
uses: tj-actions/verify-changed-files@v20
54+
id: verify-changed-files
55+
with:
56+
files: |
57+
**/*.svg
58+
59+
- name: Compress images
60+
id: calibre
61+
uses: calibreapp/image-actions@main
62+
with:
63+
githubToken: ${{ secrets.GITHUB_TOKEN }}
64+
jpegQuality: '100'
65+
pngQuality: '100'
66+
webpQuality: '100'
67+
# For non-Pull Requests, run in compressOnly mode and PR after
68+
compressOnly: ${{ github.event_name != 'pull_request' }}
69+
70+
- name: Create pull request
71+
# If it is not a Pull Request then commit any changes as a new PR
72+
if: >
73+
github.event_name != 'pull_request' && (steps.calibre.outputs.markdown != '' || steps.verify-changed-files.outputs.files_changed == 'true')
74+
75+
76+
uses: peter-evans/create-pull-request@v7
77+
with:
78+
title: 'chore: auto-compress images'
79+
branch-suffix: timestamp
80+
commit-message: 'chore: auto-compress images'
81+
body: ${{ steps.calibre.outputs.markdown }}

static/img/logo.svg

Lines changed: 1 addition & 1 deletion
Loading

static/img/logos/fastify-black.svg

Lines changed: 1 addition & 12 deletions
Loading

0 commit comments

Comments
 (0)