Skip to content

Auto Compress Images #3286

Auto Compress Images

Auto Compress Images #3286

# This Action will run in the following scenarios:
# - on Pull Requests containing images (not including forks)
# - on pushing of images to `main` (for forks)
# - on demand (https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/)
# - at 11 PM every Sunday if anything gets missed with any of the above scenarios
# For Pull Requests, the images are added to the PR.
# For other scenarios, a new PR will be opened if any images are compressed.
name: Compress images
on:
pull_request:
types:
- opened
- synchronize
paths:
- "**.jpg"
- "**.jpeg"
- "**.png"
- "**.webp"
- "**.avif"
push:
branches:
- main
paths:
- "**.jpg"
- "**.jpeg"
- "**.png"
- "**.webp"
- "**.avif"
workflow_dispatch:
schedule:
- cron: "00 23 * * 0"
concurrency:
group: compress-images-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: calibreapp/image-actions
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
# Only run on main repo and on PRs that match the main repo.
# Skip when the bot's own compression commit re-triggers this workflow
# (synchronize + bot actor) to break the infinite loop. Safe for
# bot-authored PRs (e.g. GTN imports) because those trigger as
# 'opened', not 'synchronize'.
if: |
github.repository == 'galaxyproject/galaxy-hub' &&
(github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name == github.repository) &&
!(github.event_name == 'pull_request' && github.event.action == 'synchronize' && startsWith(github.actor, 'galaxy-hub-bot'))
steps:
- name: Checkout Branch
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ secrets.HUB_BOT_APP_CLIENT_ID }}
private-key: ${{ secrets.HUB_BOT_APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-metadata: read
- name: Compress Images
id: calibre
uses: calibreapp/image-actions@1.5.0
with:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
webpQuality: '90'
# Non-PR events need compress-only mode so create-pull-request can publish the result.
compressOnly: ${{ github.event_name != 'pull_request' }}
- name: Create Pull Request
# If it's not a Pull Request then commit any changes as a new PR.
if: |
github.event_name != 'pull_request' &&
steps.calibre.outputs.markdown != ''
uses: peter-evans/create-pull-request@v8
with:
token: ${{ steps.app-token.outputs.token }}
title: Auto Compress Images
branch: action_compress_images
commit-message: Compress Images
body: ${{ steps.calibre.outputs.markdown }}