diff --git a/.github/workflows/optimize-images.yml b/.github/workflows/optimize-images.yml new file mode 100644 index 000000000..ca9059240 --- /dev/null +++ b/.github/workflows/optimize-images.yml @@ -0,0 +1,64 @@ +name: Optimize Images + +on: + push: + branches: [main, prerelease] + paths: + - '**/*.png' + +permissions: + contents: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + OXIPNG_VERSION: "10.1.0" + +jobs: + optimize-png: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + fetch-depth: 0 + + - name: Install oxipng + env: + GH_TOKEN: ${{ github.token }} + run: | + mkdir -p "$RUNNER_TEMP/oxipng" + gh release download "v${OXIPNG_VERSION}" \ + --repo oxipng/oxipng \ + --pattern "*x86_64-unknown-linux-musl.tar.gz" \ + --output - | tar xz --strip-components=1 -C "$RUNNER_TEMP/oxipng" + + - name: Get changed PNG files + id: changed-pngs + uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5 + with: + files: '**/*.png' + separator: '\n' + + - name: Optimize PNGs + if: steps.changed-pngs.outputs.any_changed == 'true' + env: + ALL_CHANGED_FILES: ${{ steps.changed-pngs.outputs.all_changed_files }} + run: | + echo "$ALL_CHANGED_FILES" | while IFS= read -r file; do + if [ -f "$file" ]; then + echo "Optimizing: $file" + "$RUNNER_TEMP/oxipng/oxipng" -o 4 -i 0 --strip safe "$file" + fi + done + + - name: Commit optimized images + uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5 + with: + commit_message: "Optimize PNG images with oxipng" + commit_user_name: github-actions[bot] + commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com + commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + file_pattern: '**/*.png' diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index c450e4f77..d7a4f4c33 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -127,7 +127,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v46.0.5 + uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5 with: files: | # don't consider modifications on file used for includes for now.