2025-07-23 20:06:07 +02:00

53 lines
1.8 KiB
YAML

name: Check for image compression
on:
workflow_call:
jobs:
compress:
name: Compress and make a PR if needed
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install optipng
run: sudo apt-get update && sudo apt-get install -y optipng
- name: Optimize PNG files
run: |
find . -type f -name "*.png" ! -path "./.git/*" -exec optipng -o7 {} +
- name: Check for changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "Everything is already correctly compressed."
exit 0
else
echo "Some files aren't correctly compressed."
exit 1
fi
- name: Create Pull Request if Needed
if: ${{ failure() && github.event_name == 'pull_request' && !github.event.pull_request.draft }}
run: |
git config user.name "GitHub GTNH Actions"
git config user.email "<>"
git switch -c "${FIXED_BRANCH}"
git commit -am "optimizing images"
git push --force-with-lease origin "${FIXED_BRANCH}"
gh pr create \
--head "${FIXED_BRANCH}" \
--base "${PR_BRANCH}" \
--title "Optimising images contained in ${PR_BRANCH} for #${{ github.event.pull_request.number }}" \
--body "Automatic image compression, applies to PR #${{ github.event.pull_request.number }}" \
2>&1 | tee pr-message.log || true
gh pr comment "${PR_BRANCH}" -F pr-message.log || true
shell:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BRANCH: ${{ github.head_ref }}
FIXED_BRANCH: ${{ github.head_ref }}-image-compression