From 8b3ed2ca80208cd1a2837e7f8a2defc4d934e0d1 Mon Sep 17 00:00:00 2001 From: Muhammad Tamir Date: Tue, 8 Jul 2025 15:55:06 +0700 Subject: [PATCH] Initial Commit --- .github/ISSUE_TEMPLATE/config.yml | 2 + .github/ISSUE_TEMPLATE/optimize_request.yml | 25 ++++++++ .github/workflows/optimize.yml | 66 ++++++++++++++++++++ optimize_script.sh | 68 +++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/optimize_request.yml create mode 100644 .github/workflows/optimize.yml create mode 100644 optimize_script.sh diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..8005e32 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,2 @@ +blank_issues_enabled: false +contact_links: [] diff --git a/.github/ISSUE_TEMPLATE/optimize_request.yml b/.github/ISSUE_TEMPLATE/optimize_request.yml new file mode 100644 index 0000000..c603f1e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/optimize_request.yml @@ -0,0 +1,25 @@ +name: Optimize Resource Pack +description: Upload your resource pack as a .zip and get back an optimized version. +title: "[Optimize] Resource Pack Optimization Request" +labels: [optimize-request] +body: + - type: markdown + attributes: + value: | + 🎯 **This request will automatically trigger an optimization workflow.** + Please ensure your `.zip` file is uploaded somewhere publicly accessible (GitHub, GDrive, Dropbox with direct links, etc). + + - type: input + id: zip_link + attributes: + label: Public Download Link to .zip + description: Paste the full URL to the .zip file that contains your resource pack. + placeholder: "https://example.com/my-pack.zip" + validations: + required: true + + - type: textarea + id: notes + attributes: + label: Notes or Extra Info (Optional) + description: Add anything else we need to know (e.g. Minecraft version, compression preferences). diff --git a/.github/workflows/optimize.yml b/.github/workflows/optimize.yml new file mode 100644 index 0000000..6da3f84 --- /dev/null +++ b/.github/workflows/optimize.yml @@ -0,0 +1,66 @@ +name: Optimize Resource Pack + +on: + issues: + types: [labeled] + +jobs: + process_resource_pack: + # Only run if the added label is 'optimize-request' + if: github.event.label.name == 'optimize-request' + runs-on: ubuntu-latest + + steps: + - name: Extract .zip link from issue body + id: extract + run: | + echo "Issue body:" + echo "${{ github.event.issue.body }}" + + ZIP_URL=$(echo "${{ github.event.issue.body }}" | grep -oP 'https?://\S+\.zip') + + if [[ -z "$ZIP_URL" ]]; then + echo "No .zip URL found in issue body. Exiting." + exit 1 + fi + echo "zip_url=$ZIP_URL" >> "$GITHUB_OUTPUT" + + - name: Download and unzip resource pack + run: | + mkdir input + cd input + curl -L "${{ steps.extract.outputs.zip_url }}" -o pack.zip + unzip pack.zip -d unpacked + + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y optipng ffmpeg zip + + - name: Optimize PNG files + run: | + find input/unpacked -type f -iname '*.png' | while read -r file; do + echo "Optimizing: $file" + optipng -o7 "$file" + done + + - name: Compress OGG files + run: | + find input/unpacked -type f -iname '*.ogg' | while read -r file; do + echo "Compressing: $file" + ffmpeg -y -i "$file" -ac 1 -ab 64k "${file}.tmp.ogg" + if [[ -f "${file}.tmp.ogg" ]]; then + mv -f "${file}.tmp.ogg" "$file" + fi + done + + - name: Re-zip optimized pack + run: | + cd input/unpacked + zip -r ../../optimized-pack.zip . + + - name: Upload optimized resource pack + uses: actions/upload-artifact@v4 + with: + name: optimized-pack + path: optimized-pack.zip diff --git a/optimize_script.sh b/optimize_script.sh new file mode 100644 index 0000000..fc8d5f9 --- /dev/null +++ b/optimize_script.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -e + +# =========[ Auto Dependency Installer ]========= +install_dependencies() { + echo "Checking and installing dependencies: optipng, ffmpeg" + + # Detect package manager + if command -v apt >/dev/null; then + PKG_INSTALL="sudo apt install -y" + PKG_UPDATE="sudo apt update" + elif command -v dnf >/dev/null; then + PKG_INSTALL="sudo dnf install -y" + PKG_UPDATE="sudo dnf check-update" + elif command -v pacman >/dev/null; then + PKG_INSTALL="sudo pacman -S --noconfirm" + PKG_UPDATE="sudo pacman -Sy" + else + echo "Unsupported package manager. Please install 'optipng' and 'ffmpeg' manually." + exit 1 + fi + + # Update package list and install + $PKG_UPDATE + $PKG_INSTALL optipng ffmpeg +} + +# Check if tools are already installed +if ! command -v optipng >/dev/null || ! command -v ffmpeg >/dev/null; then + install_dependencies +else + echo "Dependencies already installed." +fi + +# =========[ User Input ]========= +read -rp "Enter the full path to your resource pack folder: " target_folder + +if [[ ! -d "$target_folder" ]]; then + echo "Folder does not exist: $target_folder" + exit 1 +fi + +# =========[ PNG Optimization ]========= +echo "========================" +echo "Optimizing PNG files..." +echo "========================" + +find "$target_folder" -type f -iname '*.png' | while read -r file; do + echo "Processing: $file" + optipng -o7 "$file" +done + +# =========[ OGG Compression ]========= +echo "========================" +echo "Compressing OGG files..." +echo "========================" + +find "$target_folder" -type f -iname '*.ogg' | while read -r file; do + echo "Processing: $file" + ffmpeg -y -i "$file" -ac 1 -ab 64k "${file}.tmp.ogg" + if [[ -f "${file}.tmp.ogg" ]]; then + mv -f "${file}.tmp.ogg" "$file" + fi +done + +echo "========================" +echo "Optimization complete."