Add Diana (Pragmata) #3
This file contains hidden or 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
| name: Convert PNG to WebP | |
| on: | |
| push: | |
| branches: [ dev ] | |
| paths: | |
| - 'images/**/*.png' | |
| workflow_dispatch: | |
| jobs: | |
| convert: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install ImageMagick | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y imagemagick | |
| - name: Convert PNG files to WebP | |
| run: | | |
| set -euo pipefail | |
| mkdir -p webp | |
| : > /tmp/converted_webp_files.txt | |
| if command -v magick >/dev/null 2>&1; then | |
| IMAGEMAGICK_CMD="magick" | |
| else | |
| IMAGEMAGICK_CMD="convert" | |
| fi | |
| while IFS= read -r -d '' png_file; do | |
| relative_path="${png_file#images/}" | |
| relative_base="${relative_path%.png}" | |
| webp_file="webp/${relative_base}.webp" | |
| mkdir -p "$(dirname "${webp_file}")" | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ ! -f "${webp_file}" ]; then | |
| "${IMAGEMAGICK_CMD}" "${png_file}" \ | |
| -strip \ | |
| -quality 90 \ | |
| -define webp:lossless=false \ | |
| -define webp:method=6 \ | |
| -define webp:auto-filter=true \ | |
| -define webp:alpha-quality=100 \ | |
| -define webp:use-sharp-yuv=true \ | |
| "${webp_file}" | |
| echo "${webp_file}" >> /tmp/converted_webp_files.txt | |
| fi | |
| done < <(find images -type f -name '*.png' -print0) | |
| if [ -s /tmp/converted_webp_files.txt ]; then | |
| echo "Converted files:" | |
| cat /tmp/converted_webp_files.txt | |
| else | |
| echo "No PNG files required conversion." | |
| fi | |
| - name: Commit converted WebP files | |
| run: | | |
| git add webp | |
| if git diff --cached --quiet; then | |
| echo "No new WebP files to commit." | |
| exit 0 | |
| fi | |
| git config --local user.name 'AmiiboAPI (Automated)' | |
| git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| if git commit -m "[Automated] Convert PNG to WebP images"; then | |
| git push | |
| fi |