1
0
mirror of synced 2025-12-30 03:01:36 -05:00
Files
docs/.github/workflows/optimize-images.yml
dependabot[bot] 5515db7171 Bump actions/checkout from 2.4.0 to 3.0.1 (#27016)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.0.1.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...dcd71f646680f2efd8db4afa5ad64fdcba30e748)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Robert Sese <rsese@github.com>
2022-04-20 12:04:00 -05:00

73 lines
2.2 KiB
YAML

name: Optimize images
# **What it does**: Optimize images.
# **Why we have it**: Reduce bandwidth needs.
# **Who does it impact**: Docs engineering.
on:
workflow_dispatch:
pull_request:
paths:
- '**/*.png'
permissions:
contents: write
pull-requests: write
jobs:
optimize-images-on-pr:
# We can't make commits on forks
if: github.repository == 'github/docs-internal'
runs-on: ubuntu-latest
steps:
- name: Check out repo on head ref
uses: actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748
with:
ref: ${{ github.head_ref }}
# Need to specify a PAT here because otherwise GITHUB_TOKEN is used
# by default. Workflows won't trigger in that case because actions
# performed with GITHUB_TOKEN don't trigger other workflows.
token: ${{ secrets.DOCUBOT_REPO_PAT }}
- name: Check out base ref
run: git fetch --no-tags --depth=1 origin $GITHUB_BASE_REF
- name: Install the Optipng package
run: sudo apt-get update && sudo apt-get -y install optipng
- name: Run optipng on new or changed images
run: |
set -e # exit when any command fails
echo "Ensure we can view $GITHUB_BASE_REF"
git checkout $GITHUB_BASE_REF
echo "Ensure we can view $GITHUB_HEAD_REF"
git checkout $GITHUB_HEAD_REF
echo "List the files that changed"
git diff --name-only --diff-filter=d $GITHUB_BASE_REF $GITHUB_HEAD_REF
echo "Run optipng on pngs in from the diff"
git diff --name-only -z --diff-filter=d $GITHUB_BASE_REF $GITHUB_HEAD_REF -- '*.png' | xargs -0 optipng -nx
- name: Make a commit and a push
run: |
echo "If there's no changes, exit"
if [[ ! `git status --porcelain` ]]
then
echo "No changes found"
exit 0
fi
echo "Make a commit"
git config user.name github-actions
git config user.email github-actions@github.com
git add "*.png"
git commit --message="Optimize images"
echo "Push up changes"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}