diff --git a/.gitea/workflows/minify.yaml b/.gitea/workflows/minify.yaml new file mode 100644 index 0000000..1ad4656 --- /dev/null +++ b/.gitea/workflows/minify.yaml @@ -0,0 +1,46 @@ +name: Minify HTML and CSS + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + minify: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Install minification tools + run: | + npm install -g html-minifier-terser csso-cli + + - name: Minify HTML files + run: | + find src/ -name '*.html' -exec sh -c 'html-minifier-terser --collapse-whitespace --remove-comments --minify-js true --minify-css true -o "${0%.html}.min.html" "$0"' {} \; + + - name: Minify CSS files + run: | + find src/css/ -name '*.css' -exec sh -c 'csso "$0" --output "${0%.css}.min.css"' {} \; + + - name: Commit and push changes + env: + USERNAME_GITEA: ${{ secrets.USERNAME_GITEA }} + TOKEN_GITEA: ${{ secrets.TOKEN_GITEA }} + run: | + git config --global user.name "LibreCloud Actions Bot" + git config --global user.email "git@pontusmail.org" + git remote set-url origin https://${USERNAME_GITEA}:${TOKEN_GITEA}@git.pontusmail.org/aidan/pontus.git + git add . + git commit -m "[bot] Minifying HTML and CSS automatically" + git push origin main