This GitHub Actions optimizes images in your repository. You will receive a pull request with optimized images. This Github Actions is inspired by ImgBot.
A pull request example:
name: imgcmp
on:
push:
branches:
- main
- master
jobs:
imgcmp:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: 9sako6/imgcmp@v2.0.4
with:
token: ${{ secrets.GITHUB_TOKEN }}Warning
- uses: 9sako6/imgcmp@master # NGDo not reference
mastersince that is the latest code and can be carrying breaking changes of the next major version.
If you want to run this action only once a week, please add the following lines.
name: imgcmp
on:
schedule:
- cron: "0 0 * * 1" # Weekly build
jobs:
imgcmp:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: 9sako6/imgcmp@v2.0.4
with:
token: ${{ secrets.GITHUB_TOKEN }}Then, you will receive a pull request with optimized images every Monday at 0:00.
| Name | Description | Required |
|---|---|---|
token |
GITHUB_TOKEN or a Personal access token (PAT). In a private repository, you have to use a PAT with enough permissions. See How to use a Personal Access Token. |
true |
paths-ignore-regexp |
Regular expression for images' paths you don't want to compress. | false |
imgcmp offers an ignore option. paths-ignore-regexp is regular expression for
images' paths you don't want to compress.
Example:
name: imgcmp
on:
push:
branches:
- main
- master
jobs:
imgcmp:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: 9sako6/imgcmp@v2.0.4
with:
token: ${{ secrets.GITHUB_TOKEN }}
paths-ignore-regexp: "(ignore/.*)|(public/.*)"| Name | Description |
|---|---|
pull-request-number |
A pull request number created by imgcmp. |
Step outputs can be accessed as in the following example.
- uses: 9sako6/imgcmp@v2.0.4
id: imgcmp
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check outputs
run: |
echo ${{ steps.imgcmp.outputs.pull-request-number }}- JPEG/JPG
- PNG
- GIF
- SVG
- WEBP
This bot uses these optimizers.
-m85: this will store the image with 85% quality
-o2: this sets the optimization level 2 (there is 0-7 optimization levels)
-O3: this sets the optimization level to Gifsicle's maximum
SVGO's default configuration will be used.
-q 75: cwebp's default optimization level
It took 34 sec to create the following PR.
Bug fixes.
- Skip actions when a tag is pushed (9sako6#333)
- Use tj-actions/branch-names actions to get a branch name (9sako6#311)
Bug fixes.
- truncate long messages (9sako6#272)
- Skip to create PR if there are small changes (9sako6#184)
- Add
pull-request-numberoutputs (9sako6#169)
Bug fixes.
- Fix the problem that actions fail when a trigger event is
pull_request(9sako6#99) - Fix the problem that actions fail when
paths-ignore-regexpis empty (9sako6#51)
There are breaking changes from version 1.0.1.
- Add
tokeninput (9sako6#26)GITHUB_TOKENoption inenvwas deleted.
- Add
paths-ignore-regexpinput (9sako6#26)IGNORED_FILESoption inenvwas deleted.
- Refactoring the pull request template (9sako6#26)
- Make it more maintainable...


