From e7f40a15007d00dd8fda348d4e51d9d9a4e744ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kuna?= <1282324+codecalm@users.noreply.github.com> Date: Tue, 23 Dec 2025 00:59:53 +0100 Subject: [PATCH] Add 'validate-pr' script to package.json (#1443) --- .build/validate-icons.mjs | 63 +++++++++++++++++++ .../{validate-icons.yml => validate-pr.yml} | 25 ++++++-- package.json | 3 +- 3 files changed, 84 insertions(+), 7 deletions(-) rename .github/workflows/{validate-icons.yml => validate-pr.yml} (66%) diff --git a/.build/validate-icons.mjs b/.build/validate-icons.mjs index 501111ee5..2ccfb9a36 100644 --- a/.build/validate-icons.mjs +++ b/.build/validate-icons.mjs @@ -3,6 +3,7 @@ import fs from 'fs' import { basename } from 'path' import { HOME_DIR, ICONS_SRC_DIR, iconTemplate, parseMatter, types, getArgvs } from './helpers.mjs' import { join } from 'path' +import { execSync } from 'child_process' let error = false @@ -22,6 +23,28 @@ const getIconName = (icon) => { return icon.split('/').slice(-2).join('/') } +function getAddedIconsFromMain() { + try { + const output = execSync('git diff origin/main...HEAD --name-status', { encoding: 'utf-8' }) + const addedIcons = [] + + output.split('\n').forEach(line => { + if (line.startsWith('A\t')) { + const filePath = line.substring(2) + // Filter only SVG files from icons/outline/ or icons/filled/ directories + if (filePath.match(/^icons\/((outline|filled)\/.+\.svg)$/)) { + // add icon without icons/ prefix + addedIcons.push(filePath.replace(/^icons\//, '')) + } + } + }) + + return addedIcons + } catch (error) { + return [] + } +} + types.forEach(type => { const icons = globSync(join(ICONS_SRC_DIR, type, '*.svg')).sort() @@ -170,6 +193,46 @@ Object.entries(aliases).forEach(([type, replacers]) => { }) }) +const addedIcons = getAddedIconsFromMain() + +for (const icon of addedIcons) { + const iconPath = join(ICONS_SRC_DIR, icon) + + try { + const { data, content } = parseMatter(iconPath) + + if (data.unicode) { + console.log(`⛔️ Icon \`${icon}\` has unicode, but should not have it`) + error = true + } + + if (data.version) { + console.log(`⛔️ New icon \`${icon}\` has version, but should not have it`) + error = true + } + + if (!icon.match(/^[a-z0-9-]+$/)) { + console.log(`⛔️ New icon \`${icon}\` has invalid name`) + error = true + } + + // check if filled icon hasnt category + if (icon.match(/^filled\//) && data.category) { + console.log(`⛔️ New icon \`${icon}\` has category, but should not have it`) + error = true + } + + // check if filled icon has tags + if (icon.match(/^filled\//) && data.tags) { + console.log(`⛔️ New icon \`${icon}\` has tags, but should not have it`) + error = true + } + } catch (error) { + console.log(`⛔️ New icon \`${icon}\` has invalid metadata`) + error = true + } +} + if (error) { process.exit(1) } else { diff --git a/.github/workflows/validate-icons.yml b/.github/workflows/validate-pr.yml similarity index 66% rename from .github/workflows/validate-icons.yml rename to .github/workflows/validate-pr.yml index 1de129d65..145b595e6 100644 --- a/.github/workflows/validate-icons.yml +++ b/.github/workflows/validate-pr.yml @@ -1,4 +1,4 @@ -name: Validate icons +name: Validate PR on: [pull_request] @@ -6,11 +6,24 @@ permissions: pull-requests: write jobs: - validate: + validate-pr: if: github.repository == 'tabler/tabler-icons' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Add in progress comment + id: add-in-progress-comment + uses: thollander/actions-comment-pull-request@v3 + with: + comment-tag: validate + mode: upsert + message: | + 🔄 Icons are being validated... Please wait... + continue-on-error: true + - name: Use Node.js 20 uses: actions/setup-node@v3 with: @@ -44,8 +57,8 @@ jobs: continue-on-error: true - name: Comment PR - uses: thollander/actions-comment-pull-request@v2 + uses: thollander/actions-comment-pull-request@v3 with: - filePath: ./comment-markup.md - comment_tag: validate - mode: recreate + file-path: ./comment-markup.md + comment-tag: validate + mode: recreate \ No newline at end of file diff --git a/package.json b/package.json index 2844e526f..b39db5fc4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "build:sprite": "pnpm --filter @tabler/icons-sprite build", "build:webfont": "pnpm --filter @tabler/icons-webfont build", "update-readme": "node ./.build/update-readme.mjs", - "zip": "node ./.build/zip-files.mjs" + "zip": "node ./.build/zip-files.mjs", + "validate-pr": "node ./.build/validate-pr.mjs" }, "devDependencies": { "@11ty/eleventy": "^2.0.1",