Skip to content

Resize Images

Resize Images #3

Workflow file for this run

name: Resize Images
# A weekly run to resize images that changed in the last week
on:
schedule:
- cron: "0 9 * * 1" # every Monday at 09:00 UTC
workflow_dispatch:
jobs:
resize-images:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history to compare with last week
- name: Get changed image files from last week
id: changed-files
run: |
# Find all image files that changed since last Monday
CHANGED_IMAGES=$(git log --since="7 days ago" --name-only --pretty="" \
-- '*.jpg' '*.jpeg' '*.png' '*.JPG' '*.JPEG' '*.PNG' | sort -u | tr '\n' ' ')
echo "changed_images=$CHANGED_IMAGES" >> $GITHUB_OUTPUT
echo "Changed images: $CHANGED_IMAGES"
# Set a flag if any images were changed
if [ -n "$CHANGED_IMAGES" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Install ImageMagick
run: sudo apt-get update && sudo apt-get install -y imagemagick
- name: Run tools/resize_images.sh on changed files
if: steps.changed-files.outputs.has_changes == 'true'
run: |
# Pass the changed image files to the resize script
bash tools/resize_images.sh ${{ steps.changed-files.outputs.changed_images }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
if: steps.changed-files.outputs.has_changes == 'true' && success()
with:
commit-message: Resize images changed in the last week
title: Resize images changed in the last week
body: |
Resize images that were modified in the last week (Monday to Monday)
Changed files: ${{ steps.changed-files.outputs.changed_images }}
Triggered by workflow run ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Auto-generated by create-pull-request: https://github.com/peter-evans/create-pull-request
branch: resize-images
base: main