Skip to content

Commit 7f304e2

Browse files
committed
Run image action also on schedule an open PR if images change
Signed-off-by: yubiuser <github@yubiuser.dev>
1 parent 9e182eb commit 7f304e2

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed
Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
1+
# Image Actions will run in the following scenarios:
2+
# - on Pull Requests containing images (not including forks)
3+
# - on pushing of images to `master` (for forks)
4+
# - on demand (https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/)
5+
# - at 11 PM every Sunday in anything gets missed with any of the above scenarios
6+
# For Pull Requests, the images are added to the PR.
7+
# For other scenarios, a new PR will be opened if any images are compressed.
18
name: Compress Images
29

310
on:
411
pull_request:
512
paths:
6-
- "**.jpg"
7-
- "**.jpeg"
8-
- "**.png"
9-
- "**.webp"
13+
- '**.jpg'
14+
- '**.jpeg'
15+
- '**.png'
16+
- '**.webp'
17+
- '**.avif'
18+
push:
19+
branches:
20+
- master
21+
paths:
22+
- '**.jpg'
23+
- '**.jpeg'
24+
- '**.png'
25+
- '**.webp'
26+
- '**.avif'
27+
workflow_dispatch:
28+
schedule:
29+
- cron: '00 23 * * 0'
1030

1131
jobs:
1232
build:
13-
# Only run on Pull Requests within the same repository, and not from forks.
14-
if: github.event.pull_request.head.repo.full_name == github.repository
33+
# The job needs to be able to pull the code and create a pull request.
34+
permissions:
35+
contents: read # for actions/checkout
36+
pull-requests: write # to create pull request
37+
1538
name: calibreapp/image-actions
1639
runs-on: ubuntu-latest
40+
41+
if: |
42+
github.repository == 'pi-hole/docs' &&
43+
(github.event_name != 'pull_request' ||
44+
github.event.pull_request.head.repo.full_name == github.repository)
45+
1746
steps:
1847
- name: Clone repository
1948
uses: actions/checkout@v5.0.0
@@ -24,3 +53,15 @@ jobs:
2453
uses: calibreapp/image-actions@1.4.1 # TODO: if they start using a tag like v1, switch to that
2554
with:
2655
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
# For non-Pull Requests, run in compressOnly mode and we'll PR after.
57+
compressOnly: ${{ github.event_name != 'pull_request' }}
58+
59+
# If it's not a Pull Request then commit any changes as a new PR.
60+
- name: Create Pull Request
61+
if: |
62+
github.event_name != 'pull_request' &&
63+
steps.calibre.outputs.markdown != ''
64+
65+
run: gh pr create -B image_compress -H master --title 'Auto Compress Images' --body ${{ steps.calibre.outputs.markdown }}
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)