mirror of
https://github.com/GTNewHorizons/GTNH-Actions-Workflows.git
synced 2025-08-29 06:40:10 +02:00
more robust logic
This commit is contained in:
parent
c041acf5a7
commit
fa10d52e7e
27
.github/workflows/optimize-images.yml
vendored
27
.github/workflows/optimize-images.yml
vendored
@ -17,20 +17,28 @@ jobs:
|
|||||||
|
|
||||||
- name: Optimize PNG files
|
- name: Optimize PNG files
|
||||||
run: |
|
run: |
|
||||||
find . -type f -name "*.png" ! -path "./.git/*" -exec optipng -o7 -np {} +
|
find . -type f -name "*.png" ! -path "./.git/*" -exec optipng -o7 -nc {} +
|
||||||
|
|
||||||
|
- name: Check for changes
|
||||||
|
id: git-diff
|
||||||
|
run: |
|
||||||
|
if [[ -n "$(git status --porcelain)" ]]; then
|
||||||
|
echo "changed=true"
|
||||||
|
else
|
||||||
|
echo "changed=false"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Check for changes
|
- name: Check for changes
|
||||||
run: |
|
run: |
|
||||||
if [[ -n "$(git status --porcelain)" ]]; then
|
if [[ -n "$(git status --porcelain)" ]]; then
|
||||||
echo "Everything is already correctly compressed."
|
echo "needs_compression=true" >> "$GITHUB_OUTPUT"
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
echo "Some files aren't correctly compressed."
|
echo "needs_compression=false" >> "$GITHUB_OUTPUT"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
- name: Create Pull Request if Needed
|
- name: Create Pull Request if Needed
|
||||||
if: ${{ failure() && github.event_name == 'pull_request' && !github.event.pull_request.draft }}
|
if: ${{ steps.check_changes.outputs.needs_compression == 'true' && github.event_name == 'pull_request' && !github.event.pull_request.draft }}
|
||||||
run: |
|
run: |
|
||||||
git config user.name "GitHub GTNH Actions"
|
git config user.name "GitHub GTNH Actions"
|
||||||
git config user.email "<>"
|
git config user.email "<>"
|
||||||
@ -44,10 +52,13 @@ jobs:
|
|||||||
--body "Automatic image compression, applies to PR #${{ github.event.pull_request.number }}" \
|
--body "Automatic image compression, applies to PR #${{ github.event.pull_request.number }}" \
|
||||||
2>&1 | tee pr-message.log || true
|
2>&1 | tee pr-message.log || true
|
||||||
gh pr comment "${PR_BRANCH}" -F pr-message.log || true
|
gh pr comment "${PR_BRANCH}" -F pr-message.log || true
|
||||||
shell:
|
shell: bash # ensures set -eo pipefail
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
PR_BRANCH: ${{ github.head_ref }}
|
PR_BRANCH: ${{ github.head_ref }}
|
||||||
FIXED_BRANCH: ${{ github.head_ref }}-image-compression
|
FIXED_BRANCH: ${{ github.head_ref }}-image-compression
|
||||||
|
- name: Fail if there was compressed files
|
||||||
|
if: ${{ steps.check_changes.outputs.needs_compression == 'true' }}
|
||||||
|
run: |
|
||||||
|
exit 1
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user