name: 🗜️ SVG Compression

on:
  push:
    paths:
      - '**/*.svg'
  workflow_dispatch:
  
jobs:
  compress-images:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      
      - name: Install Dependencies
        run: |
          sudo apt-get update
          sudo npm install -g svgo
          
      - name: Compress SVGs
        run: |
          echo "🎨  Compressing SVGs..."
          git diff --name-only --diff-filter=d "${{ github.event.before }}..${{ github.event.after }}" | grep "\.svg$" | xargs -P 4 -I{} sh -c 'echo "Compressing {}"; svgo --quiet --multipass {}' || true
          
      - name: Load to GitHub
        run: |-
          git config --global user.email "noreply@walkx.fyi"
          git config --global user.name "Dashboard Icons Bot"
          git add -A
          git commit -m ":clamp: Compresses SVGs" || exit 0
          git push
