Skip to content

Commit

Permalink
chore: add workflow to check svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaroz committed Dec 18, 2024
1 parent c02e13d commit 7a7f5e5
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/combine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ jobs:

- name: yarn-install
run: |
yarn install
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
yarn install
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
- name: foundry-install
uses: foundry-rs/foundry-toolchain@v1
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/optimize-svg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: optimize-svg

on:
pull_request:
# Allows you to run this workflow manually
workflow_dispatch:

jobs:
combine:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || 'main' }}
token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/cache@v4
with:
path: |
**/node_modules
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}

- name: yarn-install
run: |
yarn install
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
- name: setup-node
uses: actions/setup-node@v3
with:
node-version: 16

- name: validate-optimize-svgs
run: |
node ./scripts/optimize-svg.js
44 changes: 44 additions & 0 deletions scripts/optimize-svg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fs from 'fs';
import path from 'path';

const directories = ['./chains', './deployments'];
const MAX_FILE_SIZE = 20 * 1024; // 20KBs

function isValidSvg(filePath) {
const fileName = path.basename(filePath);
const stats = fs.statSync(filePath);

if (!fileName.endsWith('logo.svg')) {
console.error(`Error: File does not end with 'logo.svg' -> ${filePath}`);
// process.exit(1); // Exit immediately if criteria is not met
}

if (stats.size > MAX_FILE_SIZE) {
console.error(`Error: File size exceeds 20KBs -> ${filePath}`);
// process.exit(1); // Exit immediately if criteria is not met
}
}

function findAndProcessSVGs(directory) {
const files = fs.readdirSync(directory);

files.forEach((file) => {
const fullPath = path.join(directory, file);
const stats = fs.statSync(fullPath);

if (stats.isDirectory()) {
findAndProcessSVGs(fullPath); // Recurse into subdirectories
} else if (path.extname(fullPath) === '.svg') {
isValidSvg(fullPath); // Validate file, exits on failure
}
});
}

directories.forEach((directory) => {
if (fs.existsSync(directory)) {
console.log(`Checking directory: ${directory}`);
findAndProcessSVGs(directory);
} else {
console.log(`Directory does not exist: ${directory}`);
}
});

0 comments on commit 7a7f5e5

Please sign in to comment.