mirror of
https://github.com/GTNewHorizons/GTNH-Actions-Workflows.git
synced 2025-08-29 14:50:23 +02:00
add image compression workflow
This commit is contained in:
parent
031b79f439
commit
dbf92f682a
55
.github/workflows/optimize-images.yml
vendored
Normal file
55
.github/workflows/optimize-images.yml
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
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 Repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Compress Images
|
||||||
|
id: compress-images
|
||||||
|
uses: stellasoftio/image-optimizer-action@v1
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
compress-png: true
|
||||||
|
compress-svg: false
|
||||||
|
compress-jpg: false
|
||||||
|
compress-webp: false
|
||||||
|
compress-avif: false
|
||||||
|
|
||||||
|
- name: Fail if image optimization was needed
|
||||||
|
if: steps.compress-images.outputs.markdown_report != ''
|
||||||
|
run: |
|
||||||
|
echo "Unoptimized image(s) have been detected."
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
|
||||||
|
- name: Create Pull Request if Needed
|
||||||
|
if: steps.compress-images.outputs.markdown_report != ''
|
||||||
|
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 }}\n\n${{ steps.compress-images.outputs.markdown_report }}" \
|
||||||
|
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
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user