|
| 1 | +name: Generate PNGs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + convert-svg-to-png: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout Repository |
| 14 | + uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - name: Install Inkscape |
| 17 | + run: | |
| 18 | + sudo apt install inkscape |
| 19 | +
|
| 20 | + - name: Install Pngquant |
| 21 | + run: | |
| 22 | + sudo apt install pngquant |
| 23 | +
|
| 24 | + - name: Convert SVGs to PNGs |
| 25 | + run: | |
| 26 | + total_files=$(find ./ -type f -name "*.svg" | wc -l) |
| 27 | + progress=0 |
| 28 | +
|
| 29 | + find ./ -type f -name "*.svg" | while IFS= read -r file; do |
| 30 | + progress=$((progress + 1)) |
| 31 | + percentage=$((progress * 100 / total_files)) |
| 32 | + filled=$((percentage / 2)) |
| 33 | + unfilled=$((50 - filled)) |
| 34 | + |
| 35 | + printf "\rProgress: [%${filled}s%${unfilled}s] %d%%" "$(printf '#%.0s' $(seq 1 $filled))" "$(printf ' %.0s' $(seq 1 $unfilled))" "$percentage" |
| 36 | + png_file="${file%.svg} 4k" |
| 37 | + # convert -background none -density 700 "$file" -quality 100 -resize 4000 "$png_file" |
| 38 | + inkscape "$file" --export-background-opacity=0 -h 4000 -o "$png_file".temp.png |
| 39 | + pngquant -f --quality 100 "$png_file".temp.png --output "$png_file".png |
| 40 | + rm "$png_file".temp.png |
| 41 | + done |
| 42 | + echo |
| 43 | +
|
| 44 | + - name: Commit and Push Converted PNGs |
| 45 | + env: |
| 46 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + run: | |
| 48 | + git config --global user.name "github-actions[bot]" |
| 49 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 50 | + git fetch origin "${GITHUB_HEAD_REF}" |
| 51 | + git checkout "${GITHUB_HEAD_REF}" |
| 52 | + git add . |
| 53 | + git commit -m "Generate PNGs" |
| 54 | + git push origin "${GITHUB_HEAD_REF}" |
0 commit comments