Let the CI Worry About Image Compression

GitHub Actions is essentially a configurable automation layer for your repository. It can trigger any script you need—builds, tests, deployments—and you can stitch together third-party tasks from the marketplace into a pipeline. One useful chore to offload is image optimization, ensuring no unoptimized asset ever slips into your branch.

Calibre’s image-actions is a ready-made action for this job. Before you use it, check that Actions is turned on for the repository itself—many organizations enable it on a per-repo basis rather than org-wide.

The action is configured in its own file at ./github/workflows/optimize-images.yml. Keeping it isolated from other workflows makes sense for two reasons: this one only runs on pull request pushes, so its trigger doesn’t overlap with workflows tied to other events, and the separated file mirrors the usage pattern in the action’s docs.

name: Optimize images
on: pull_request
jobs:
  build:
    name: calibreapp/image-actions
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master

      - name: Compress Images
        uses: calibreapp/image-actions@master
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}

Once the workflow is in place, a run appears on every pull request:

When it succeeds, the bot drops a comment on the PR with a breakdown of what it compressed:

The action also commits the optimized files straight back into the branch. That means if you keep working on the same pull request, you’ll need to pull the changes down and push again before you can push any further commits.

You can inspect that automatic commit to see exactly what changed:

The commit preview in Git Tower.

That makes it safe to merge with confidence:

Sure, running a compressor locally isn’t a hard task. But having it handled automatically on every PR removes a recurring manual step. You’re trading a bit of CI complexity for permanently streamlined image assets—a worthwhile swap.