From 2d159d683b8eee31629d94a94e13d724db2c3c25 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 9 Apr 2022 18:49:34 -0700 Subject: [PATCH] chore: Add auto image compression action --- .../workflows/calibreapp-image-actions.yml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/calibreapp-image-actions.yml diff --git a/.github/workflows/calibreapp-image-actions.yml b/.github/workflows/calibreapp-image-actions.yml new file mode 100644 index 000000000..7c7759f97 --- /dev/null +++ b/.github/workflows/calibreapp-image-actions.yml @@ -0,0 +1,56 @@ +# Image Actions will run in the following scenarios: +# - on Pull Requests containing images (not including forks) +# - on pushing of images to `main` (for forks) +# - on demand (https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/) +# - at 11 PM every Sunday in anything gets missed with any of the above scenarios +# For Pull Requests, the images are added to the PR. +# For other scenarios, a new PR will be opened if any images are compressed. +name: Compress images +on: + pull_request: + paths: + - "**.jpg" + - "**.jpeg" + - "**.png" + - "**.webp" + push: + branches: + - main + paths: + - "**.jpg" + - "**.jpeg" + - "**.png" + - "**.webp" + workflow_dispatch: + schedule: + - cron: "00 20 * * 0" +jobs: + build: + name: calibreapp/image-actions + runs-on: ubuntu-latest + # Only run on main repo on and PRs that match the main repo. + if: | + github.repository == 'example/example_repo' && + (github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name == github.repository) + steps: + - name: Checkout Branch + uses: actions/checkout@v2 + - name: Compress Images + id: calibre + uses: calibreapp/image-actions@main + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + # For non-Pull Requests, run in compressOnly mode and we'll PR after. + compressOnly: ${{ github.event_name != 'pull_request' }} + - name: Create Pull Request + # If it's not a Pull Request then commit any changes as a new PR. + if: | + github.event_name != 'pull_request' && + steps.calibre.outputs.markdown != '' + uses: peter-evans/create-pull-request@v3 + with: + title: Auto Compress Images + branch-suffix: timestamp + commit-message: Compress Images + body: ${{ steps.calibre.outputs.markdown }}