-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (39 loc) · 1.41 KB
/
minify.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
46
47
48
49
# This workflow is triggered by a push to the `main` branch
# which it checks out, minimises the appropriate html/css/js
# in-place, and pushes the changes to the `gh-pages` branch
name: Minify
on:
push:
branches:
- "main"
permissions:
contents: write
jobs:
checkout-minify-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Minification Tools
run: |
npm install -g terser csso-cli html-minifier-terser
- name: Minify HTML, CSS, and JS
run: |
# Minify HTML files
find . -name "*.html" -exec html-minifier-terser --collapse-whitespace --remove-comments --minify-js true --minify-css true --output {}.min {} \;
find . -name "*.html.min" -exec bash -c 'mv "$0" "${0%.min}"' {} \;
# Minify CSS files
find . -name "*.css" -exec csso --output {} {} \;
# Minify JavaScript files
find . -name "*.js" -exec terser --compress --mangle --output {} -- {} \;
- name: Deploy to gh-pages
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git checkout --orphan gh-pages
git reset
git add -f .
git commit -m "Deploy minified files to gh-pages"
git push -f origin gh-pages
- name: Return to main
run: git checkout main