name: Update changes on commit

on:
  workflow_dispatch:
  push:
    branches: [master]
    paths:
      - "assets/**"
      - "customize/**"

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@master
      - name: 📂 Create temp folder
        run: |
          mkdir temp
      - name: 🖼️ Add backgrounds
        run: |
          for file in assets/backgrounds/*.png ; do
            filename=$(basename "$file" .png)
            mkdir "temp/$filename"
            cp "$file" "temp/$filename/background.png"
          done
      - name: 🎨 Add icons
        run: |
          for dest in temp/* ; do cp -rv assets/icons "$dest"; done
      - name: 📇 Add fonts
        run: |
          for dest in temp/* ; do cp -rva assets/fonts/. "$dest"; done
      - name: 🌿 Add menu
        run: |
          for dest in temp/* ; do cp -rva assets/menu/. "$dest"; done
      - name: 📃 Add theme
        run: |
          for dest in temp/* ; do cp -rv assets/theme.txt "$dest"; done
      - name: 🗑️ Cleanup old themes
        run: |
          rm -rf themes/*
      - name: 💼 Create archives
        run: |
          cd temp;
          for dest in * ; do find "$dest" -printf "%P\n" | tar -vcf ../themes/"$dest".tar --no-recursion -C "$dest" -T -; done
      - name: Remove artifacts
        run: |
          rm -r temp
      - name: 🔥 Commit changes
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
          git fetch
          git add .
          git commit -m "🤖 Update files"
          git push
