Add 'validate-pr' script to package.json (#1443)
This commit is contained in:
parent
67ede20ca5
commit
e7f40a1500
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue