1
0
mirror of https://github.com/tabler/tabler-icons.git synced 2025-01-16 20:28:28 +01:00

Pull Request comments action (#1048)

* validate icons comment pr

* labeler

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* validate icons comment pr

* test icons

* validate icons comment pr

* rollbac invalid icons
This commit is contained in:
Paweł Kuna 2024-03-13 03:29:16 +01:00 committed by GitHub
parent d740ea68a3
commit 6174beca0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 20 deletions

View File

@ -6,8 +6,8 @@ import { join } from 'path'
let error = false
const outlineIconsNames = globSync(join(ICONS_SRC_DIR, 'outline/*.svg')).map(i => basename(i, '.svg')),
filledIconsNames = globSync(join(ICONS_SRC_DIR, 'filled/*.svg')).map(i => basename(i, '.svg')),
const outlineIconsNames = globSync(join(ICONS_SRC_DIR, 'outline/*.svg')).map(i => basename(i, '.svg')).sort(),
filledIconsNames = globSync(join(ICONS_SRC_DIR, 'filled/*.svg')).map(i => basename(i, '.svg')).sort(),
argvs = getArgvs(),
aliases = JSON.parse(fs.readFileSync(join(HOME_DIR, 'aliases.json'), 'utf-8'));
@ -17,19 +17,25 @@ const duplicateExists = (arr) => {
return new Set(arr).size !== arr.length
}
const getIconName = (icon) => {
//return last two parts of the path
return icon.split('/').slice(-2).join('/')
}
types.forEach(type => {
const icons = globSync(join(ICONS_SRC_DIR, type, '*.svg'))
const icons = globSync(join(ICONS_SRC_DIR, type, '*.svg')).sort()
icons.forEach((icon) => {
const iconContent = fs.readFileSync(icon, 'utf-8')
const iconContent = fs.readFileSync(icon, 'utf-8'),
iconName = getIconName(icon)
if (!iconContent.includes(iconTemplate(type))) {
console.log(`Icon ${icon} is not properly formatted`)
console.log(`⛔️ Icon \`${iconName}\` is not properly formatted`)
error = true
}
if (!iconContent.includes('<!--') || !iconContent.includes('-->')) {
console.log(`Icon ${icon} has no metadata`)
console.log(`⛔️ Icon \`${iconName}\` has no metadata`)
error = true
}
@ -38,40 +44,42 @@ types.forEach(type => {
if (data.unicode) {
if (unicodes.indexOf(data.unicode) !== -1) {
console.log(`Icon ${icon} has duplicate unicode "${data.unicode}"`)
console.log(`⛔️ Icon \`${iconName}\` has duplicate unicode \`${data.unicode}\``)
error = true
}
if (data.unicode.length !== 4) {
console.log(`Icon ${icon} has invalid unicode "${data.unicode}"`)
console.log(`⛔️ Icon \`${iconName}\` has invalid unicode \`${data.unicode}\``)
error = true
}
// check duplicates in tags
if (duplicateExists(data.tags || [])) {
console.log(`Icon ${icon} has duplicate tags`)
console.log(`⛔️ Icon \`${iconName}\` has duplicate tags`)
error = true
}
unicodes.push(data.unicode)
} else if (argvs.hard) {
console.log(`Icon ${icon} has no unicode`)
console.log(`⛔️ Icon \`${iconName}\` has no unicode`)
error = true
}
if (argvs.hard && !data.version) {
console.log(`Icon ${icon} has no version`)
console.log(`⛔️ Icon \`${iconName}\` has no version`)
error = true
}
} catch (e) {
console.log(`Icon ${icon} has invalid metadata`)
console.log(`⛔️ Icon \`${iconName}\` has invalid metadata`)
error = true
}
})
filledIconsNames.forEach((icon) => {
const iconName = getIconName(icon)
if (outlineIconsNames.indexOf(icon) === -1) {
console.log(`Icon ${icon} exists in filled version but doesn't exists in outline`)
console.log(`⛔️ Icon \`${iconName}\` exists in filled version but doesn't exists in outline`)
error = true
}
})
@ -79,9 +87,9 @@ types.forEach(type => {
// check aliases
Object.entries(aliases).forEach(([type, replacers]) => {
Object.entries(replacers).forEach(([icon, alias]) => {
if (!fs.existsSync(join(ICONS_SRC_DIR, type, `${alias}.svg`))) {
console.log(`Alias ${icon} for ${alias} in ${type} doesn't exists`)
Object.entries(replacers).forEach(([from, to]) => {
if (!fs.existsSync(join(ICONS_SRC_DIR, type, `${to}.svg`))) {
console.log(`⛔️ Alias \`${type}/${from}\` for \`${type}/${to}\` doesn't exists`)
error = true
}
})
@ -90,6 +98,6 @@ Object.entries(aliases).forEach(([type, replacers]) => {
if (error) {
process.exit(1)
} else {
console.log('All icons are valid!')
console.log('All icons are valid!')
process.exit(0)
}

View File

@ -40,7 +40,8 @@ jobs:
- name: Validate icons
id: validate
run: pnpm run --silent validate >> ./comment-markup.md
run: pnpm run --silent validate > ./comment-markup.md
continue-on-error: true
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2

View File

@ -12,7 +12,7 @@
},
"scripts": {
"dev": "eleventy --serve --watch",
"preview": "pnpm run validate && pnpm run build:preview",
"preview": "eleventy",
"build": "pnpm run update && pnpm run validate --hard && pnpm run optimize && pnpm run build:packages && pnpm run preview && pnpm run changelog-image && pnpm run zip && pnpm run update-readme",
"clean": "turbo run clean",
"test": "turbo run test",
@ -31,7 +31,6 @@
"generate-preview-stroke": "node ./.build/preview-stroke.mjs",
"validate": "node ./.build/validate-icons.mjs",
"release": "git pull && release-it --verbose",
"build:preview": "eleventy",
"build:copy": "rm -rf ./icons && mkdir ./icons && cp ./_site/tags.json tags.json && cp ./_site/icons/* ./icons/ && rm -rf ./_site/",
"build:packages": "pnpm run build:icons && pnpm run build:sprite && pnpm run build:react && pnpm run build:react-native && pnpm run build:preact && pnpm run build:solidjs && pnpm run build:svelte && pnpm run build:vue && pnpm run build:png && pnpm run build:pdf && pnpm run build:esp && pnpm run build:webfont",
"build:icons": "pnpm --filter @tabler/icons build",