minify assets #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# Inspired by: https://stackoverflow.com/a/73882805/11035513 | |
name: minify-assets | |
run-name: minify assets | |
# Run on pushes to `release` branch | |
on: | |
push: | |
branches: | |
- release | |
jobs: | |
checkout-minify-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Install NodeJS and CLI tools | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- run: npm install -g terser | |
- run: npm install -g csso-cli | |
- run: npm install -g html-minifier | |
- run: npm install -g svgo | |
# Perform minification, overwriting original files | |
- run: terser ./scripts/timeline.js --compress --mangle --output ./scripts/timeline.js | |
- run: | | |
css_font_files=$(ls ./styles/*.css) | |
echo "$css_font_files" | while IFS= read -r file; do | |
echo "Minifying $file" | |
csso --force-media-merge $file --output $file | |
done | |
- run: html-minifier --case-sensitive --collapse-inline-tag-whitespace --collapse-whitespace --minify-css --minify-js --minify-urls --quote-character='"' --remove-comments index.html --output index.html | |
- run: svgo -f ./images -o ./images | |
# (Force) push changes to `gh-pages` branch | |
- run: | | |
git config user.name stepanjakl | |
git config user.email [email protected] | |
git commit -am "Automated minify of ${{ github.sha }}" | |
git push --force -u origin release:gh-pages |