ci(images): add workflow to optimize images on asset changes
This commit is contained in:
@@ -0,0 +1,48 @@
|
|||||||
|
name: Optimize images
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, master ]
|
||||||
|
paths:
|
||||||
|
- 'src/assets/**'
|
||||||
|
- 'assets/**'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'src/assets/**'
|
||||||
|
- 'assets/**'
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
optimize:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '18'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Run image optimizer
|
||||||
|
run: npm run optimize-images
|
||||||
|
|
||||||
|
- name: Commit optimized images
|
||||||
|
run: |
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add public/images || true
|
||||||
|
if ! git diff --staged --quiet; then
|
||||||
|
git commit -m "chore(images): add optimized WebP images [skip ci]" || echo "no changes to commit"
|
||||||
|
git push
|
||||||
|
else
|
||||||
|
echo "No optimized images to commit"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user