Skip to content

Fix images

Fix images #7

Workflow file for this run

name: Convert & normalize media (convert-media.pl)
on:
push:
paths:
- "**/*.png"
- "**/*.jpg"
- "**/*.jpeg"
- "**/*.jpe"
- "**/*.gif"
- "**/*.bmp"
- "**/*.tif"
- "**/*.tiff"
- "**/*.webp"
- "**/*.avif"
- "**/*.heic"
- "**/*.heif"
- "**/*.mp3"
- "**/*.wav"
- "**/*.flac"
- "**/*.aac"
- "**/*.m4a"
- "**/*.wma"
- "**/*.mp4"
- "**/*.m4v"
- "**/*.mov"
- "**/*.mkv"
- "**/*.webm"
- "**/*.avi"
- "**/*.mpg"
- "**/*.mpeg"
- "**/*.ogg"
- "**/*.oga"
- "**/*.ogv"
- "**/*.opus"
- "**/*.html"
- "**/*.htm"
- "scripts/convert-media.pl"
- ".github/workflows/convert-media.yml"
pull_request:
paths:
- "**/*.png"
- "**/*.jpg"
- "**/*.jpeg"
- "**/*.jpe"
- "**/*.gif"
- "**/*.bmp"
- "**/*.tif"
- "**/*.tiff"
- "**/*.webp"
- "**/*.avif"
- "**/*.heic"
- "**/*.heif"
- "**/*.mp3"
- "**/*.wav"
- "**/*.flac"
- "**/*.aac"
- "**/*.m4a"
- "**/*.wma"
- "**/*.mp4"
- "**/*.m4v"
- "**/*.mov"
- "**/*.mkv"
- "**/*.webm"
- "**/*.avi"
- "**/*.mpg"
- "**/*.mpeg"
- "**/*.ogg"
- "**/*.oga"
- "**/*.ogv"
- "**/*.opus"
- "**/*.html"
- "**/*.htm"
- "scripts/convert-media.pl"
- ".github/workflows/convert-media.yml"
# Allow manual runs from the Actions tab
workflow_dispatch: {}
permissions:
contents: write
jobs:
convert_media:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
defaults:
run:
shell: bash
steps:
- name: Checkout (push)
if: github.event_name == 'push'
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout (pull_request HEAD)
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Detect needs (images/media)
id: detect
run: |
set -euo pipefail
has_images=false
has_media=false
# Raster images that the script handles (ICO/SVG intentionally excluded)
git ls-files | grep -E '\.(png|jpe?g|jpe|gif|bmp|tiff?|webp|avif|heic|heif)$' -m1 >/dev/null 2>&1 && has_images=true || true
# Local media candidates (audio/video) handled by ffprobe/ffmpeg in the script
git ls-files | grep -E '\.(ogg|oga|ogv|mp3|wav|flac|aac|m4a|mp4|m4v|mov|mkv|webm|avi|mpg|mpeg)$' -m1 >/dev/null 2>&1 && has_media=true || true
echo "has_images=$has_images" >> "$GITHUB_OUTPUT"
echo "has_media=$has_media" >> "$GITHUB_OUTPUT"
echo "Detected: images=$has_images media=$has_media"
- name: Install minimal apt dependencies
run: |
set -euo pipefail
declare -a pkgs=()
pkgs+=(perl)
if [[ "${{ steps.detect.outputs.has_images }}" == "true" ]]; then
pkgs+=(imagemagick)
fi
if [[ "${{ steps.detect.outputs.has_media }}" == "true" ]]; then
pkgs+=(ffmpeg)
fi
# If nothing detected, still succeed quickly
if [[ "${#pkgs[@]}" -gt 0 ]]; then
sudo apt-get update
sudo apt-get install -y "${pkgs[@]}"
fi
# Print versions for sanity (best-effort)
(magick -version 2>/dev/null || convert -version 2>/dev/null) | head -n 1 || true
ffmpeg -version | head -n 1 || true
ffprobe -version | head -n 1 || true
perl -v | head -n 2 || true
- name: Run conversion script (apply)
env:
LANG: C.UTF-8
LC_ALL: C.UTF-8
run: |
set -euo pipefail
perl ./scripts/convert-media.pl --apply
- name: Commit & push changes (push event)
if: github.event_name == 'push'
run: |
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: normalize media assets"
git push
else
echo "No changes to commit."
fi
- name: Commit & push changes (PR from same repo)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
run: |
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: normalize media assets"
git push origin HEAD:${{ github.head_ref }}
else
echo "No changes to commit."
fi
- name: Fail if changes detected (PR from fork cannot be pushed)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
run: |
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
echo "PR from fork: cannot push changes back. Run the converter locally and commit."
git diff
exit 1
fi
echo "No conversion changes detected."