Skip to content

Commit

Permalink
Merge pull request #13024 from newrelic/tabatha/images-workflow2
Browse files Browse the repository at this point in the history
Create image check workflow
  • Loading branch information
tabathadelane committed May 12, 2023
2 parents 0a52a58 + c9c7af0 commit 4a7227b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/check-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Check images

on:
workflow_dispatch:
schedule:
- cron: '0 17 * * 2' # 9AM PST (5PM UTC) on Tuesday mornings

env:
BOT_NAME: nr-opensource-bot
BOT_EMAIL: opensource+bot@newrelic.com

jobs:
check-images:
name: Convert or delete
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
ref: develop
persist-credentials: false

- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Remove unused images
run: yarn remove-unused-images

- name: Convert images to WEBP
run: yarn convert-to-webp -g

- name: Commit changes
id: commit-changes
run: |
git config --local user.email "${{ env.BOT_EMAIL }}"
git config --local user.name "${{ env.BOT_NAME }}"
git add .src/images
git commit -m 'chore: remove unused images & convert to webp'
echo "commit=true" >> $GITHUB_OUTPUT
- name: Push Commit
if: steps.commit-changes.outputs.commit == 'true'
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.DEVEX_OPENSOURCE_BOT_TOKEN }}
branch: develop
11 changes: 6 additions & 5 deletions scripts/convertPNGs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ const stagedFiles = (
const imgExtensions = ['jpg', 'jpeg', 'png'];
const imgRegex = new RegExp(`\.(?:${imgExtensions.join('|')})$`);

const stagedImages = stagedFiles.filter((file) =>
imgRegex.test(file.toLocaleLowerCase())
);
const stagedImages = stagedFiles
.filter((file) => imgRegex.test(file.toLocaleLowerCase()))
.filter((file) => !/favicon.png$/.test(file));
const stagedMDs = stagedFiles.filter((file) =>
/\.mdx?$/.test(file.toLocaleLowerCase())
);

const allImages = await glob(`**/*.{${imgExtensions.join(',')}}`);
const allImages = await glob(`**/*.{${imgExtensions.join(',')}}`, {
ignore: ['**/favicon.png', 'node_modules/**'],
});
const allMDsAndJSs = await glob('src/**/*.{md,mdx,js}');

const imagesToConvert = runGlobally ? allImages : stagedImages;
Expand Down

0 comments on commit 4a7227b

Please sign in to comment.