3
0
mirror of https://github.com/NekoMonci12/mine-compress.git synced 2025-12-19 15:09:20 +00:00

Update Workflows

This commit is contained in:
Muhammad Tamir
2025-07-08 16:12:35 +07:00
parent 3c62cf44d3
commit c1b0fbae0d

View File

@@ -6,61 +6,153 @@ on:
jobs: jobs:
process_resource_pack: process_resource_pack:
# Only run if the added label is 'optimize-request'
if: github.event.label.name == 'optimize-request' if: github.event.label.name == 'optimize-request'
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps: steps:
- name: Extract .zip link from issue body - name: Extract zip link from issue
id: extract id: extract
run: | run: |
echo "Issue body:" ZIP_URL=$(echo "${{ github.event.issue.body }}" | grep -oP 'https?://\S+\.zip' | head -n 1)
echo "${{ github.event.issue.body }}"
ZIP_URL=$(echo "${{ github.event.issue.body }}" | grep -oP 'https?://\S+\.zip')
if [[ -z "$ZIP_URL" ]]; then if [[ -z "$ZIP_URL" ]]; then
echo "No .zip URL found in issue body. Exiting." echo "No .zip URL found in issue body."
echo "status=failed" >> "$GITHUB_OUTPUT"
exit 1 exit 1
fi fi
echo "zip_url=$ZIP_URL"
echo "zip_url=$ZIP_URL" >> "$GITHUB_OUTPUT" echo "zip_url=$ZIP_URL" >> "$GITHUB_OUTPUT"
echo "status=success" >> "$GITHUB_OUTPUT"
- name: Download and unzip resource pack - name: Download and unzip resource pack
run: | run: |
mkdir input mkdir input
cd input cd input
curl -L "${{ steps.extract.outputs.zip_url }}" -o pack.zip echo "⬇️ Downloading zip file..."
unzip pack.zip -d unpacked curl -sL "${{ steps.extract.outputs.zip_url }}" -o pack.zip
echo "📦 Unpacking zip..."
unzip -q pack.zip -d unpacked
echo "✅ Resource pack extracted."
- name: Install dependencies - name: Install dependencies
run: | run: |
sudo apt update sudo apt-get update -qq > /dev/null
sudo apt install -y optipng ffmpeg zip sudo apt-get install -y -qq optipng ffmpeg zip > /dev/null
- name: Optimize PNG files echo "🔍 Verifying installation..."
run: | for cmd in optipng ffmpeg zip; do
find input/unpacked -type f -iname '*.png' | while read -r file; do if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Optimizing: $file" echo "❌ $cmd not found after installation."
optipng -o7 "$file" exit 1
else
echo "✅ $cmd is installed: $($cmd --version | head -n 1)"
fi
done done
- name: Compress OGG files - name: Optimize PNG files
shell: bash
run: | run: |
find input/unpacked -type f -iname '*.ogg' | while read -r file; do set +e # disable exit-on-error
echo "Compressing: $file" set +o pipefail # ignore broken pipes from printf
ffmpeg -y -i "$file" -ac 1 -ab 64k "${file}.tmp.ogg" echo "🖼️ Scanning PNG files..."
mapfile -t FILES < <(find input/unpacked -type f -iname '*.png')
TOTAL=${#FILES[@]}
echo "🖼️ Optimizing $TOTAL PNG files..."
i=0
for file in "${FILES[@]}"; do
((i++))
# Output progress quietly, avoid broken pipe crashes
{ printf "\r[%4d/%4d] %s" "$i" "$TOTAL" "$(basename "$file")"; } || true
optipng -o7 -fix "$file" > /dev/null 2>&1 || true
done
echo -e "\n✅ PNG optimization complete."
- name: Compress OGG files
shell: bash
run: |
set +e
set +o pipefail
echo "🔊 Scanning OGG files..."
mapfile -t FILES < <(find input/unpacked -type f -iname '*.ogg')
TOTAL=${#FILES[@]}
echo "🔊 Compressing $TOTAL OGG files..."
i=0
for file in "${FILES[@]}"; do
((i++))
{ printf "\r[%4d/%4d] %s" "$i" "$TOTAL" "$(basename "$file")"; } || true
ffmpeg -v error -y -i "$file" -ac 1 -ab 64k "${file}.tmp.ogg" > /dev/null 2>&1 || true
if [[ -f "${file}.tmp.ogg" ]]; then if [[ -f "${file}.tmp.ogg" ]]; then
mv -f "${file}.tmp.ogg" "$file" mv -f "${file}.tmp.ogg" "$file"
fi fi
done done
- name: Re-zip optimized pack echo -e "\n✅ OGG compression complete."
- name: Re-zip Packs
run: | run: |
cd input/unpacked cd input/unpacked
zip -r ../../optimized-pack.zip . zip -r ../../optimized-pack.zip .
- name: Upload optimized resource pack - name: Verify Packs
run: |
if [[ ! -f optimized-pack.zip ]]; then
echo "❌ optimized-pack.zip not found!"
exit 1
else
echo "✅ optimized-pack.zip exists."
ls -lh optimized-pack.zip
fi
- name: Upload Packs
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: optimized-pack name: optimized-pack
path: optimized-pack.zip path: optimized-pack.zip
- name: Comment + Label + Close Issue
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
ISSUE_NUMBER="${{ github.event.issue.number }}"
REPO="${{ github.repository }}"
RUN_ID="${{ github.run_id }}"
if ! command -v gh > /dev/null; then
sudo apt-get update -qq
sudo apt-get install -y -qq gh
fi
if [[ "${{ steps.extract.outputs.status }}" == "success" && -f optimized-pack.zip ]]; then
gh issue comment "$ISSUE_NUMBER" --repo "$REPO" \
--body=$'✅ Optimization complete!\n\nDownload from: https://github.com/'"$REPO"'/actions/runs/'"$RUN_ID"
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" \
--add-label optimization-success \
--remove-label optimize-request
gh issue close "$ISSUE_NUMBER" --repo "$REPO"
else
gh issue comment "$ISSUE_NUMBER" --repo "$REPO" \
--body=$'❌ Optimization failed.\n\nEnsure your issue contains a valid public .zip file link.'
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" \
--add-label optimization-failed \
--remove-label optimize-request
gh issue close "$ISSUE_NUMBER" --repo "$REPO"
fi