Skip to content
calibreapp

GitHub Action

Image Actions

1.1.0 Latest version

Image Actions

calibreapp

Image Actions

Compresses Images for the Web

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Image Actions

uses: calibreapp/[email protected]

Learn more about this action in calibreapp/image-actions

Choose a version

Image Actions

Image Actions automatically compress JPEG, PNG and WebP images in GitHub Pull Requests.

  • Fast, efficient and near-lossless compression
  • Uses the best image compression algorithms available: mozjpeg and libvips
  • Configurable and extensible: use default settings or adapt to your needs
  • Runs in GitHub Actions
  • Built by web performance experts at Calibre; a performance monitoring platform

image actions in action Preview of image-actions Pull Request comment

Installation

Create the .github/workflows/calibreapp-image-actions.yml file with the following configuration

name: Compress 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 }}

The GITHUB_TOKEN secret is automatically generated by GitHub. This automatic token is scoped only to the repository that is currently running the action.

Configuration

Default Settings

...
- name: Compress Images
  uses: calibreapp/image-actions@master
  with:
    githubToken: ${{ secrets.GITHUB_TOKEN }}
    jpegQuality: "80"
    pngQuality: "80"
    webpQuality: "80"
    ignorePaths: "node_modules/**,build"
    # No spaces allowed

If you would like to modify the defaults, update the .github/workflows/calibreapp-image-actions.yml file by adding arguments to the action:

  • jpegQuality: Number, integer 1-100, default 80 stroed in a string
  • pngQuality: Number, integer 1-100, default 80 stored in a string
  • webpQuality: Number, integer 1-100, default 80 stored in a string
  • ignorePaths: a comma separated string with globbing support of paths to ignore when looking for images to compress

The jpegQuality, pngQuality and webpQuality config keys will be delivered directly into sharp’s toFormat method.

Previous versions of image-actions used .github/calibre/image-actions.yml for configuration. We suggest that you migrate to the newest configuration format by reading the migration steps below.

Running the action only when images are changed

image-actions is designed to run for each Pull Request. In some repositories, images are seldom updated. To run the action only when images have changed, use GitHub Action’s on.push.paths workflow configuration:

name: Compress images
on:
  pull_request:
    paths:
      - '**.jpg'
      - '**.png'
      - '**.webp'

The above workflow will only run on a pull request when jpg, png or webp files are changed.

Migrate legacy configuration

  • uses: docker://calibreapp/github-image-actions

    If your calibreapp-image-actions.yml file has a reference to docker:// or GITHUB_TOKEN like below

    - name: calibreapp/image-actions
       uses: docker://calibreapp/github-image-actions
       env:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    Update your configuration to match the following

    - name: Compress images
      uses: calibreapp/image-actions@master
      with:
        githubToken: ${{ secrets.GITHUB_TOKEN }}
  • .github/calibre/image-actions.yml

    If your repository uses .github/calibre/image-actions.yml for configuration, it should be moved into .github/workflows/calibreapp-image-actions.yml. Then delete the image-actions.yml file.

    ignorePaths is no longer an array and is now a comma separated list. eg: ignorePaths: "node_modules/**,bin"

Links and Resources