Skip to content

Commit

Permalink
Merge pull request #45 from steveoh/patch-1
Browse files Browse the repository at this point in the history
docs: clarify the docs
  • Loading branch information
benschwarz committed Jan 28, 2020
2 parents fe910a9 + c2f1618 commit 737ceea
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Image Actions automatically compress JPEG, PNG and WebP images in GitHub Pull Re
- Runs in [GitHub Actions](https://github.com/features/actions)
- Built by web performance experts at [Calibre](https://calibreapp.com/); a performance monitoring platform

_image actions in action_
![Preview of image-actions Pull Request comment](https://user-images.githubusercontent.com/924/62024579-e1470d00-b218-11e9-8655-693ea42ba0f7.png)

## Add Image Actions to your repository
## Installation

1. Open or create the `.github/workflows/calibreapp-image-actions.yml` file.
2. Paste in the following:
Create the `.github/workflows/calibreapp-image-actions.yml` file with the following configuration

```yml
name: Compress images
Expand All @@ -32,16 +32,14 @@ jobs:
githubToken: ${{ secrets.GITHUB_TOKEN }}
```

The `GITHUB_TOKEN` secret is [automatically generated by GitHub](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret). This automatic token is [scoped only to the repository that is currently running the action.](https://help.github.com/en/articles/virtual-environments-for-github-actions#token-permissions)
_The `GITHUB_TOKEN` secret is [automatically generated by GitHub](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret). This automatic token is [scoped only to the repository that is currently running the action.](https://help.github.com/en/articles/virtual-environments-for-github-actions#token-permissions)_

## Configure Image Actions
## Configuration

By default, you probably don’t need to configure `image-actions`.
However, if you’d like to ignore specific file paths, or change image compression options, read on.

Change the configuration options by adding arguments to the action:
### Default Settings

```yml
...
- name: Compress Images
uses: calibreapp/image-actions@master
with:
Expand All @@ -53,28 +51,60 @@ Change the configuration options by adding arguments to the action:
# No spaces allowed
```

Previous versions of image-actions used `.github/config/image-actions.yml` for configuration.
If you're still using that configuration method we suggest that you update it.
If you would like to modify the defaults, update the `.github/workflows/calibreapp-image-actions.yml` file by adding arguments to the action:

- [jpegQuality](http://sharp.pixelplumbing.com/en/stable/api-output/#jpeg): Number, integer 1-100, default 80 stroed in a string
- [pngQuality](http://sharp.pixelplumbing.com/en/stable/api-output/#png): Number, integer 1-100, default 80 stored in a string
- [webpQuality](http://sharp.pixelplumbing.com/en/stable/api-output/#webp): Number, integer 1-100, default 80 stored in a string
- `ignorePaths`: a comma separated string with [globbing](https://www.npmjs.com/package/glob) 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](http://sharp.pixelplumbing.com) `toFormat` method._

- The above configuration is what `image-actions` uses by default
- The `jpegQuality`, `pngQuality` and `webpQuality` config keys will be delivered directly into [sharp’s](http://sharp.pixelplumbing.com) `toFormat`. ([JPEG options](http://sharp.pixelplumbing.com/en/stable/api-output/#jpeg), [PNG options](http://sharp.pixelplumbing.com/en/stable/api-output/#png), [Webp options](http://sharp.pixelplumbing.com/en/stable/api-output/#webp))
- `ignorePaths` allows for path globbing [see the glob package for more details](https://www.npmjs.com/package/glob)
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](#migration-legacy-configuration) below.

## Running the action only when images are changed
### 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`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onpushpull_requestpaths) workflow configuration:
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`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onpushpull_requestpaths) workflow configuration:

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

The above workflow will only run when `jpg`, `png` or `webp` files are changed.
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

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

Update your configuration to match the following

```yml
- 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

Expand Down

0 comments on commit 737ceea

Please sign in to comment.