spoo-me / url-shortener

spoo.me is a free and easy-to-use URL shortener that lets you create short links for any website. You can choose your own alias, set a password, and limit the number of clicks.
https://spoo.me
Apache License 2.0
72 stars 10 forks source link

Add: Workflows to Minify HTML, CSS, and JS and Push to Deployment Branch #24

Open Zingzy opened 19 hours ago

Zingzy commented 19 hours ago

Description

Implement a GitHub Actions workflow to automatically minify HTML, CSS, and JavaScript files and push the optimized code to a deployment branch. This will improve the performance of the web application by reducing the size of the files that need to be downloaded by the user's browser.

Tasks

Zingzy commented 19 hours ago
name: Minify and Deploy

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install dependencies
      run: npm install html-minifier cssnano uglify-js

    - name: Minify HTML
      run: |
        find . -name "*.html" -exec html-minifier --collapse-whitespace --remove-comments --minify-css true --minify-js true -o {} {} \;

    - name: Minify CSS
      run: |
        find . -name "*.css" -exec cssnano {} {} \;

    - name: Minify JS
      run: |
        find . -name "*.js" -exec uglifyjs --compress --mangle -o {} -- {} \;

    - name: Commit and push changes
      run: |
        git config --global user.name 'github-actions'
        git config --global user.email 'github-actions@github.com'
        git checkout -b deployment
        git add .
        git commit -m "Minify HTML, CSS, and JS files"
        git push --force --set-upstream origin deployment
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Possible Workflow (Untested)