From 65faaf0095c86939fc2325ad802df4822915e658 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Mon, 16 Dec 2024 10:41:10 +0100 Subject: [PATCH 1/2] Use main branch from calibreapp/image-actions Signed-off-by: yubiuser --- .github/workflows/calibreapp-image-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/calibreapp-image-actions.yml b/.github/workflows/calibreapp-image-actions.yml index b02224a62..02c9126c2 100644 --- a/.github/workflows/calibreapp-image-actions.yml +++ b/.github/workflows/calibreapp-image-actions.yml @@ -19,6 +19,6 @@ jobs: uses: actions/checkout@v4.2.2 - name: Compress Images - uses: calibreapp/image-actions@1.1.0 # TODO: if they start using a tag like v1, switch to that + uses: calibreapp/image-actions@main # Their latest tag is > 4 years old and the README says to use main with: githubToken: ${{ secrets.GITHUB_TOKEN }} From 6b4363254112778e3d1507f2043d1a31712b0ec9 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Mon, 16 Dec 2024 11:06:12 +0100 Subject: [PATCH 2/2] Run image action also on schedule an open PR if images change Signed-off-by: yubiuser --- .../workflows/calibreapp-image-actions.yml | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/.github/workflows/calibreapp-image-actions.yml b/.github/workflows/calibreapp-image-actions.yml index 02c9126c2..2cf521775 100644 --- a/.github/workflows/calibreapp-image-actions.yml +++ b/.github/workflows/calibreapp-image-actions.yml @@ -1,3 +1,10 @@ +# 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: @@ -7,13 +14,33 @@ on: - '**.jpeg' - '**.png' - '**.webp' + push: + branches: + - master + paths: + - '**.jpg' + - '**.jpeg' + - '**.png' + - '**.webp' + workflow_dispatch: + schedule: + - cron: '00 23 * * 0' jobs: build: - # Only run on Pull Requests within the same repository, and not from forks. - if: github.event.pull_request.head.repo.full_name == github.repository + # The job needs to be able to pull the code and create a pull request. + permissions: + contents: read # for actions/checkout + pull-requests: write # to create pull request + name: calibreapp/image-actions runs-on: ubuntu-latest + + if: | + github.repository == 'pi-hole/docs' && + (github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name == github.repository) + steps: - name: Checkout Repo uses: actions/checkout@v4.2.2 @@ -22,3 +49,15 @@ jobs: uses: calibreapp/image-actions@main # Their latest tag is > 4 years old and the README says to use 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' }} + + # If it's not a Pull Request then commit any changes as a new PR. + - name: Create Pull Request + if: | + github.event_name != 'pull_request' && + steps.calibre.outputs.markdown != '' + + run: gh pr create -B image_compress -H master --title 'Auto Compress Images' --body ${{ steps.calibre.outputs.markdown }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}