Optimize images on pull requests (#25377)
* Add two images * two more images * Run optimize images on pull requests * Update optimize-images-pull-request.yml * Add more images * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Optimize images * Update optimize-images-pull-request.yml * Remove images * Delete optimize-images.yml * Update optimize-images-pull-request.yml * Update optimize-images-pull-request.yml * Move in place Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
44
.github/workflows/optimize-images.yml
vendored
44
.github/workflows/optimize-images.yml
vendored
@@ -6,28 +6,47 @@ name: Optimize images
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '45 17 * * 2' # Run Tuesdays at 17:45 UTC / 9:45 PST
|
||||
pull_request:
|
||||
paths:
|
||||
- '**/*.png'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
optimize-images:
|
||||
if: github.repository == 'github/docs-internal'
|
||||
optimize-images-on-pr:
|
||||
if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repo
|
||||
- name: Check out repo on head ref
|
||||
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
|
||||
- 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 the Optipng package
|
||||
run: find . -name '*.png' -print0 | xargs -0 optipng -nx
|
||||
- name: Run optipng on new or changed images
|
||||
run: |
|
||||
set -e # exit when any command fails
|
||||
|
||||
- name: Make a branch, commit, push, and pull request
|
||||
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 $GITHUB_HEAD_REF $GITHUB_BASE_REF
|
||||
|
||||
echo "Run optipng on pngs in from the diff"
|
||||
git diff --name-only -z $GITHUB_HEAD_REF $GITHUB_BASE_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` ]]
|
||||
@@ -36,10 +55,6 @@ jobs:
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Make a new branch"
|
||||
BRANCH="optimize-images-$(date +'%Y%m%d%H%M%S')"
|
||||
git checkout -b $BRANCH
|
||||
|
||||
echo "Make a commit"
|
||||
git config user.name github-actions
|
||||
git config user.email github-actions@github.com
|
||||
@@ -47,9 +62,6 @@ jobs:
|
||||
git commit --message="Optimize images"
|
||||
|
||||
echo "Push up changes"
|
||||
git push --set-upstream origin $BRANCH
|
||||
|
||||
echo "Open a pull request"
|
||||
gh pr create --title "Optimize images" --body "Optimize images"
|
||||
git push
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
Reference in New Issue
Block a user