Add 'validate-pr' script to package.json (#1443)

This commit is contained in:
Paweł Kuna 2025-12-23 00:59:53 +01:00 committed by GitHub
parent 67ede20ca5
commit e7f40a1500
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 84 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import fs from 'fs'
import { basename } from 'path' import { basename } from 'path'
import { HOME_DIR, ICONS_SRC_DIR, iconTemplate, parseMatter, types, getArgvs } from './helpers.mjs' import { HOME_DIR, ICONS_SRC_DIR, iconTemplate, parseMatter, types, getArgvs } from './helpers.mjs'
import { join } from 'path' import { join } from 'path'
import { execSync } from 'child_process'
let error = false let error = false
@ -22,6 +23,28 @@ const getIconName = (icon) => {
return icon.split('/').slice(-2).join('/') 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 => { types.forEach(type => {
const icons = globSync(join(ICONS_SRC_DIR, type, '*.svg')).sort() 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) { if (error) {
process.exit(1) process.exit(1)
} else { } else {

View File

@ -1,4 +1,4 @@
name: Validate icons name: Validate PR
on: [pull_request] on: [pull_request]
@ -6,11 +6,24 @@ permissions:
pull-requests: write pull-requests: write
jobs: jobs:
validate: validate-pr:
if: github.repository == 'tabler/tabler-icons' if: github.repository == 'tabler/tabler-icons'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - 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 - name: Use Node.js 20
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
@ -44,8 +57,8 @@ jobs:
continue-on-error: true continue-on-error: true
- name: Comment PR - name: Comment PR
uses: thollander/actions-comment-pull-request@v2 uses: thollander/actions-comment-pull-request@v3
with: with:
filePath: ./comment-markup.md file-path: ./comment-markup.md
comment_tag: validate comment-tag: validate
mode: recreate mode: recreate

View File

@ -48,7 +48,8 @@
"build:sprite": "pnpm --filter @tabler/icons-sprite build", "build:sprite": "pnpm --filter @tabler/icons-sprite build",
"build:webfont": "pnpm --filter @tabler/icons-webfont build", "build:webfont": "pnpm --filter @tabler/icons-webfont build",
"update-readme": "node ./.build/update-readme.mjs", "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": { "devDependencies": {
"@11ty/eleventy": "^2.0.1", "@11ty/eleventy": "^2.0.1",