|
| 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. |
1 | 8 | name: Compress Images |
2 | 9 |
|
3 | 10 | on: |
4 | 11 | pull_request: |
5 | 12 | 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' |
10 | 30 |
|
11 | 31 | jobs: |
12 | 32 | 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 | + |
15 | 38 | name: calibreapp/image-actions |
16 | 39 | 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 | +
|
17 | 46 | steps: |
18 | 47 | - name: Clone repository |
19 | 48 | uses: actions/checkout@v5.0.0 |
|
24 | 53 | uses: calibreapp/image-actions@1.4.1 # TODO: if they start using a tag like v1, switch to that |
25 | 54 | with: |
26 | 55 | 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