SVGO Action
Automatically run SVGO with GitHub Actions.
Usage
Install the Action
Create a Workflow file (e.g.: .github/workflows/optimize.yml
, see Creating a
Workflow file) with the workflow below - or check out the examples for
various complete workflows. You can also check what the Action does for each
on
event and what the Action outputs for subsequent steps.
name: Optimize
on:
# Comment the next line if you *don't* want the Action to run on Pull Requests.
pull_request:
# Uncomment the next line if you want the Action to run on pushes.
# push:
# Uncomment the next 2 lines if you want the Action to run on a schedule.
# schedule:
# - cron: '0 * * * 1' # See https://crontab.guru/
# Uncomment one of the next 2 lines if you want to manually trigger the Action.
# repository_dispatch:
# workflow_dispatch:
jobs:
svgs:
name: SVGs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Uncomment the next 2 lines to select a branch for on schedule or dispatch.
# with:
# ref: main
- uses: ericcornelissen/svgo-action@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Note: This grants access to the GITHUB_TOKEN
so the Action can make calls to
GitHub's rest API. This is only needed for pull_request
and push
events.
Configure the Action
The following inputs are available when using the SVGO Action.
Name | Description | Default | Documentation |
---|---|---|---|
dry-run |
Prevent the Action from writing changes | false |
docs |
ignore |
globs of SVGs that should be ignored | "" |
docs |
repo-token |
A GitHub token (secrets.GITHUB_TOKEN ) |
"" |
docs |
strict |
Fail on non-critical errors | false |
docs |
svgo-config |
The path of the SVGO configuration file | "svgo.config.js" |
docs |
svgo-version |
The version of SVGO to use | 2 |
docs |
To configure the Action you simply set a value for any of the above in the Workflow file. For example:
- uses: ericcornelissen/svgo-action@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
dry-run: true
ignore: do/not/optimize/**/
strict: false
svgo-config: path/to/svgo-config.js
svgo-version: 2
Advanced Usage
Limit Runs
Even though this Action won't do anything if a push or Pull Request does not
touch any SVGs, you may want the Action to run only when an SVG has actually
changed. To do this you can change the Workflow file that uses this Action to be
triggered only when SVGs change. Update the value of pull_request
and/or
push
as follows:
Warning This will cause the entire Workflow to be run only when an SVG changes. Jobs that should run for every push or Pull Request must be specified in a separate Workflow file.
on:
pull_request:
paths:
- "**.svg"
push:
paths:
- "**.svg"
Token Permissions
The minimum required permissions needed to run this Action are:
permissions:
contents: read
# Uncomment the next line if you're using the Action on Pull Requests
# pull-requests: read
# Or use `read-all` to allow reading in all scopes (recommended for open source)
permissions: read-all