From 866aebb456f9976367aed506cd057002a23c0dae Mon Sep 17 00:00:00 2001 From: Rajendra Reddy Date: Thu, 16 Apr 2026 09:42:13 +0000 Subject: [PATCH] Add .gitea/workflows/compressimages.yml --- .gitea/workflows/compressimages.yml | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .gitea/workflows/compressimages.yml diff --git a/.gitea/workflows/compressimages.yml b/.gitea/workflows/compressimages.yml new file mode 100644 index 0000000..6804a88 --- /dev/null +++ b/.gitea/workflows/compressimages.yml @@ -0,0 +1,79 @@ +name: Enforce Image Standards + +on: + pull_request: + branches: + - main + - beta + - testing + - client + - staging + - production + types: [opened, synchronize, reopened] + paths: + - '**/*.jpg' + - '**/*.jpeg' + - '**/*.png' + + workflow_dispatch: + inputs: + target_branch: + description: "Branch to optimize images on" + required: false + default: "main" + +jobs: + optimize: + runs-on: ubuntu-latest + + steps: + - name: Determine Branch + id: branch + run: | + if [ "${{ gitea.event_name }}" = "pull_request" ]; then + echo "branch=${{ gitea.head_ref }}" >> $GITHUB_OUTPUT + else + echo "branch=${{ inputs.target_branch }}" >> $GITHUB_OUTPUT + fi + + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ steps.branch.outputs.branch }} + + - name: Install Image Tools + run: | + sudo apt-get update + sudo apt-get install -y imagemagick jpegoptim pngquant + + - name: Resize Oversized Images + run: | + find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) \ + -exec mogrify -resize 1920x1920\> {} \; + + - name: Optimize JPEG + run: | + find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) \ + -exec jpegoptim --strip-all --max=85 {} \; + + - name: Optimize PNG + run: | + find . -type f -iname "*.png" \ + -exec pngquant --force --ext .png --quality=75-90 {} \; + + - name: Commit changes + run: | + git config --global user.name "CI Bot" + git config --global user.email "ci@local" + + if [ -n "$(git status --porcelain)" ]; then + git add . + git commit -m "chore: optimize images via CI" + else + echo "No changes to commit" + fi + + - name: Push changes + run: | + git push origin HEAD:${{ steps.branch.outputs.branch }} \ No newline at end of file