Skip to content

A Github Action that automatically compresses JPEGs, PNGs and WebPs in Pull Requests.

License

Notifications You must be signed in to change notification settings

andrzejkaszkowiak/image-actions

 
 

Repository files navigation

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"
    jpegProgressive: false
    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 stored 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
  • jpegProgressive: Boolean, true or false, default false
  • 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

About

A Github Action that automatically compresses JPEGs, PNGs and WebPs in Pull Requests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 84.7%
  • Dockerfile 12.5%
  • Shell 2.2%
  • Ruby 0.6%