A GitHub action to optimize PNG files that were created/modified in a pull request.
Created
November 16, 2023 04:56
-
-
Save jdanyow/d2db983bc769168fad755cf1c556fb43 to your computer and use it in GitHub Desktop.
Optimize PNGs using GitHub actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Optimize PNGs | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
format: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: Optimize PNGs | |
env: | |
GH_TOKEN: ${{ github.token }} | |
PR_NUMBER: ${{ github.event.number }} | |
run: | | |
PNGS=$(gh pr view $PR_NUMBER --json files --jq '.files.[].path | select(endswith(".png"))') | |
if [ -z "$PNGS" ]; then | |
echo "No PNGs found" | |
exit 0 | |
fi | |
sudo apt-get install -y optipng | |
echo $PNGS | xargs optipng -nc -nb -o7 | |
- name: Commit changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: Optimize PNGs | |
branch: ${{ github.head_ref }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment