Skip to content

Commit 355bfb5

Browse files
itisAliRHarash77
andauthored
ci: stop image compression bot from self-triggering PR loops (#3996)
* ci(optimize-images): update image compression workflow - Add support for webp and avif image formats. - Upgrade calibreapp/image-actions to version 1.5.0. - Enhance concurrency settings for better performance. - Refine conditions for running on pull requests. * ci: use github token for PR image compression * fix(ci): prevent image compression loop with job-level actor check Replace GITHUB_TOKEN conditional switching with a simpler job-level if guard. The previous approach used GITHUB_TOKEN for PR runs, which prevented the loop but blocked required status checks (main.yml) from running on bot commits, making PRs unmergeable for non-admin contributors. The job now skips entirely when the bot's own compression commit re-triggers it (synchronize + bot actor), breaking the infinite loop. Bot-authored PRs (e.g. GTN imports) are unaffected because they trigger as 'opened', not 'synchronize'. Also adds: - persist-credentials: false (zizmor artipacked fix) - Scoped permissions on App token step (zizmor github-app fix) --------- Co-authored-by: Arash <arash77.kad@gmail.com>
1 parent 8196b4b commit 355bfb5

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

.github/workflows/optimize-images.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,67 @@
88
name: Compress images
99
on:
1010
pull_request:
11+
types:
12+
- opened
13+
- synchronize
1114
paths:
1215
- "**.jpg"
1316
- "**.jpeg"
1417
- "**.png"
18+
- "**.webp"
19+
- "**.avif"
1520
push:
1621
branches:
1722
- main
1823
paths:
1924
- "**.jpg"
2025
- "**.jpeg"
2126
- "**.png"
27+
- "**.webp"
28+
- "**.avif"
2229
workflow_dispatch:
2330
schedule:
2431
- cron: "00 23 * * 0"
32+
concurrency:
33+
group: compress-images-${{ github.event.pull_request.number || github.ref }}
34+
cancel-in-progress: true
2535
jobs:
2636
build:
2737
name: calibreapp/image-actions
2838
runs-on: ubuntu-latest
2939
permissions:
3040
contents: write
3141
pull-requests: write
32-
# Only run on main repo on and PRs that match the main repo.
42+
# Only run on main repo and on PRs that match the main repo.
43+
# Skip when the bot's own compression commit re-triggers this workflow
44+
# (synchronize + bot actor) to break the infinite loop. Safe for
45+
# bot-authored PRs (e.g. GTN imports) because those trigger as
46+
# 'opened', not 'synchronize'.
3347
if: |
3448
github.repository == 'galaxyproject/galaxy-hub' &&
3549
(github.event_name != 'pull_request' ||
36-
github.event.pull_request.head.repo.full_name == github.repository)
50+
github.event.pull_request.head.repo.full_name == github.repository) &&
51+
!(github.event_name == 'pull_request' && github.event.action == 'synchronize' && startsWith(github.actor, 'galaxy-hub-bot'))
3752
steps:
3853
- name: Checkout Branch
3954
uses: actions/checkout@v6
55+
with:
56+
persist-credentials: false
4057
- name: Generate GitHub App token
4158
id: app-token
4259
uses: actions/create-github-app-token@v3
4360
with:
4461
client-id: ${{ secrets.HUB_BOT_APP_CLIENT_ID }}
4562
private-key: ${{ secrets.HUB_BOT_APP_PRIVATE_KEY }}
63+
permission-contents: write
64+
permission-pull-requests: write
65+
permission-metadata: read
4666
- name: Compress Images
4767
id: calibre
48-
uses: calibreapp/image-actions@1.4.1
68+
uses: calibreapp/image-actions@1.5.0
4969
with:
5070
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
51-
# Attempt to prevent webp recompression by minimizing diff.
5271
webpQuality: '90'
53-
minPctChange: '2.5'
5472
# Non-PR events need compress-only mode so create-pull-request can publish the result.
5573
compressOnly: ${{ github.event_name != 'pull_request' }}
5674
- name: Create Pull Request

0 commit comments

Comments
 (0)