|
| 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. |
1 | 8 | name: Compress Images
|
2 | 9 |
|
3 | 10 | on:
|
|
7 | 14 | - "**.jpeg"
|
8 | 15 | - "**.png"
|
9 | 16 | - "**.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' |
10 | 28 |
|
11 | 29 | jobs:
|
12 | 30 | 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 | + |
15 | 36 | name: calibreapp/image-actions
|
16 | 37 | 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 | +
|
17 | 44 | steps:
|
18 | 45 | - name: Clone repository
|
19 | 46 |
|
|
24 | 51 | uses: calibreapp/image-actions@main # Their latest tag is > 4 years old and the README says to use main
|
25 | 52 | with:
|
26 | 53 | githubToken: ${{ secrets.GITHUB_TOKEN }}
|
| 54 | + # For non-Pull Requests, run in compressOnly mode and we'll PR after. |
| 55 | + compressOnly: ${{ github.event_name != 'pull_request' }} |
| 56 | + |
| 57 | + # If it's not a Pull Request then commit any changes as a new PR. |
| 58 | + - name: Create Pull Request |
| 59 | + if: | |
| 60 | + github.event_name != 'pull_request' && |
| 61 | + steps.calibre.outputs.markdown != '' |
| 62 | +
|
| 63 | + run: gh pr create -B image_compress -H master --title 'Auto Compress Images' --body ${{ steps.calibre.outputs.markdown }} |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments