Skip to content

Commit 6b43632

Browse files
committed
Run image action also on schedule an open PR if images change
Signed-off-by: yubiuser <[email protected]>
1 parent 65faaf0 commit 6b43632

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

.github/workflows/calibreapp-image-actions.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Image Actions will run in the following scenarios:
2+
# - on Pull Requests containing images (not including forks)
3+
# - on pushing of images to `main` (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:
@@ -7,13 +14,33 @@ on:
714
- '**.jpeg'
815
- '**.png'
916
- '**.webp'
17+
push:
18+
branches:
19+
- master
20+
paths:
21+
- '**.jpg'
22+
- '**.jpeg'
23+
- '**.png'
24+
- '**.webp'
25+
workflow_dispatch:
26+
schedule:
27+
- cron: '00 23 * * 0'
1028

1129
jobs:
1230
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
31+
# The job needs to be able to pull the code and create a pull request.
32+
permissions:
33+
contents: read # for actions/checkout
34+
pull-requests: write # to create pull request
35+
1536
name: calibreapp/image-actions
1637
runs-on: ubuntu-latest
38+
39+
if: |
40+
github.repository == 'pi-hole/docs' &&
41+
(github.event_name != 'pull_request' ||
42+
github.event.pull_request.head.repo.full_name == github.repository)
43+
1744
steps:
1845
- name: Checkout Repo
1946
uses: actions/[email protected]
@@ -22,3 +49,15 @@ jobs:
2249
uses: calibreapp/image-actions@main # Their latest tag is > 4 years old and the README says to use main
2350
with:
2451
githubToken: ${{ secrets.GITHUB_TOKEN }}
52+
# For non-Pull Requests, run in compressOnly mode and we'll PR after.
53+
compressOnly: ${{ github.event_name != 'pull_request' }}
54+
55+
# If it's not a Pull Request then commit any changes as a new PR.
56+
- name: Create Pull Request
57+
if: |
58+
github.event_name != 'pull_request' &&
59+
steps.calibre.outputs.markdown != ''
60+
61+
run: gh pr create -B image_compress -H master --title 'Auto Compress Images' --body ${{ steps.calibre.outputs.markdown }}
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)