Merge pull request #161 from SashaIr/main #404
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 to ICO | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'svg/**' | |
| - 'small/**' | |
| jobs: | |
| convert: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout SVG Repo | |
| uses: actions/checkout@v3 | |
| with: | |
| repository: icon11-community/Folder11 | |
| path: Folder11 | |
| fetch-depth: 0 | |
| - name: Checkout ICO Repo | |
| uses: actions/checkout@v3 | |
| with: | |
| repository: icon11-community/Folder-Ico | |
| token: ${{ secrets.ACTION_TOKEN }} | |
| path: Folder-Ico | |
| - name: Setup Dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y imagemagick jq --fix-missing | |
| npm install -g svgexport | |
| - name: Convert SVG to ICO | |
| id: convert_svg | |
| run: | | |
| MAIN_SVG_DIR="./Folder11/svg" | |
| SMALL_SVG_DIR="./Folder11/small" | |
| ICO_DIR="./Folder-Ico/ico" | |
| HASH_DIR="./Folder-Ico/hash" | |
| TEMP_DIR=$(mktemp -d) | |
| mkdir -p "$ICO_DIR" "$HASH_DIR" | |
| for main_svg in "$MAIN_SVG_DIR"/*.svg; do | |
| [ -f "$main_svg" ] || continue | |
| filename=$(basename -- "$main_svg") | |
| name="${filename%.*}" | |
| small_svg="$SMALL_SVG_DIR/$filename" | |
| if [ -f "$small_svg" ]; then | |
| # Kombinasikan hash dari file main dan small | |
| main_hash=$(git hash-object "$main_svg") | |
| small_hash=$(git hash-object "$small_svg") | |
| current_hash=$(echo -n "${main_hash}_${small_hash}" | sha1sum | awk '{print $1}') | |
| else | |
| current_hash=$(git hash-object "$main_svg") | |
| fi | |
| hash_file="$HASH_DIR/$name.hash" | |
| if [ -f "$hash_file" ] && [ -f "$ICO_DIR/$name.ico" ] && [ "$current_hash" == "$(cat "$hash_file")" ]; then | |
| echo "🟢 No changes for: $name" | |
| continue | |
| fi | |
| echo "🔵 Converting: $name" | |
| ico_output="$ICO_DIR/$name.ico" | |
| if [ -f "$small_svg" ]; then | |
| temp_png_main="$TEMP_DIR/${name}_main.png" | |
| svgexport "$main_svg" "$temp_png_main" png 2048:2048 | |
| temp_png_small="$TEMP_DIR/${name}_small.png" | |
| svgexport "$small_svg" "$temp_png_small" png 2048:2048 | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_main" -resize 256x256 "$TEMP_DIR/${name}_256.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_main" -resize 64x64 "$TEMP_DIR/${name}_64.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_main" -resize 48x48 "$TEMP_DIR/${name}_48.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_main" -resize 40x40 "$TEMP_DIR/${name}_40.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_small" -resize 32x32 "$TEMP_DIR/${name}_32.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_small" -resize 24x24 "$TEMP_DIR/${name}_24.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_small" -resize 20x20 "$TEMP_DIR/${name}_20.png" | |
| convert -background transparent -filter Lanczos -colorspace sRGB \ | |
| "$temp_png_small" -resize 16x16 "$TEMP_DIR/${name}_16.png" | |
| convert "$TEMP_DIR/${name}_256.png" "$TEMP_DIR/${name}_64.png" "$TEMP_DIR/${name}_48.png" "$TEMP_DIR/${name}_40.png" \ | |
| "$TEMP_DIR/${name}_32.png" "$TEMP_DIR/${name}_24.png" "$TEMP_DIR/${name}_20.png" "$TEMP_DIR/${name}_16.png" \ | |
| "$ico_output" | |
| else | |
| temp_png="$TEMP_DIR/${name}.png" | |
| svgexport "$main_svg" "$temp_png" png 2048:2048 | |
| convert -background transparent -filter Lanczos -colorspace sRGB "$temp_png" \ | |
| -define icon:auto-resize="256,64,48,40,32,24,20,16" \ | |
| "$ico_output" | |
| fi | |
| echo "$current_hash" > "$hash_file" | |
| done | |
| for ico_file in "$ICO_DIR"/*.ico; do | |
| [ -f "$ico_file" ] || continue | |
| filename=$(basename -- "$ico_file") | |
| name="${filename%.*}" | |
| main_svg="$MAIN_SVG_DIR/$name.svg" | |
| if [ ! -f "$main_svg" ]; then | |
| echo "🔴 Removing orphaned: $name" | |
| rm -f "$ico_file" | |
| rm -f "$HASH_DIR/$name.hash" | |
| fi | |
| done | |
| rm -rf "$TEMP_DIR" | |
| echo "hash=$current_hash" >> $GITHUB_ENV | |
| - name: Generate icon.json | |
| run: | | |
| ICO_DIR="./Folder-Ico/ico" | |
| HASH_DIR="./Folder-Ico/hash" | |
| SMALL_SVG_DIR="./Folder11/small" | |
| JSON_FILE="./Folder-Ico/Folder11.json" | |
| json_content=$( | |
| jq -n --argjson icons '[]' ' | |
| { | |
| "icons": $icons | |
| } | |
| ' | |
| ) | |
| for ico_file in "$ICO_DIR"/*.ico; do | |
| [ -f "$ico_file" ] || continue | |
| filename=$(basename -- "$ico_file") | |
| name="${filename%.*}" | |
| size=$(stat -c%s "$ico_file") | |
| url_icon="https://raw.githubusercontent.com/icon11-community/Folder-Ico/main/ico/$filename" | |
| hash=$(cat "$HASH_DIR/$name.hash") | |
| svg_file_path="svg/$name.svg" | |
| date=$(git -C ./Folder11 log -1 --format=%cd --date=iso-strict -- "$svg_file_path") | |
| small_svg_url="" | |
| if [ -f "$SMALL_SVG_DIR/$name.svg" ]; then | |
| small_svg_url="https://raw.githubusercontent.com/icon11-community/Folder11/main/small/$name.svg" | |
| fi | |
| json_content=$( | |
| echo "$json_content" | jq --arg name "$name" --arg size "$size" --arg url_icon "$url_icon" --arg hash "$hash" --arg date "$date" --arg small_svg_url "$small_svg_url" ' | |
| .icons += [ | |
| { | |
| "name": $name, | |
| "size": $size, | |
| "url_icon": $url_icon, | |
| "hash": $hash, | |
| "date": $date, | |
| "small_svg_url": $small_svg_url | |
| } | |
| ] | |
| ' | |
| ) | |
| done | |
| echo "$json_content" | jq . > "$JSON_FILE" | |
| - name: Commit and Push Changes | |
| run: | | |
| cd Folder-Ico | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git add . | |
| git commit -m "gen: ${{ env.hash }}" | |
| git push | |
| else | |
| echo "No changes to commit" | |
| fi |