mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-06 08:00:05 +00:00
Add testing for telemetry in local dist assets
This commit is contained in:
36
.github/workflows/ci-dist-telemetry-scan.yaml
vendored
Normal file
36
.github/workflows/ci-dist-telemetry-scan.yaml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: 'CI: Dist Telemetry Scan'
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches-ignore: [wip/*, draft/*, temp/*]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
scan:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Build project
|
||||
run: pnpm build
|
||||
|
||||
- name: Scan dist for telemetry references
|
||||
run: pnpm test:dist
|
||||
@@ -45,6 +45,7 @@
|
||||
"stylelint": "stylelint --cache '{apps,packages,src}/**/*.{css,vue}'",
|
||||
"test:browser": "pnpm exec nx e2e",
|
||||
"test:browser:local": "cross-env PLAYWRIGHT_LOCAL=1 pnpm test:browser",
|
||||
"test:dist": "tsx scripts/verify-dist-no-telemetry.ts",
|
||||
"test:unit": "nx run test",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"typecheck:desktop": "nx run @comfyorg/desktop-ui:typecheck",
|
||||
|
||||
57
scripts/verify-dist-no-telemetry.ts
Normal file
57
scripts/verify-dist-no-telemetry.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { readFile, stat } from 'node:fs/promises'
|
||||
import { extname, resolve } from 'node:path'
|
||||
import { glob } from 'glob'
|
||||
|
||||
type Pattern = {
|
||||
label: string
|
||||
regex: RegExp
|
||||
}
|
||||
|
||||
const distDir = resolve('dist')
|
||||
const ignoredExtensions = new Set(['.map', '.svg'])
|
||||
const telemetryPatterns: Pattern[] = [
|
||||
{ label: 'GTM container', regex: /GTM-[A-Z0-9]+/i },
|
||||
{ label: 'GTM script', regex: /gtm\.js/i },
|
||||
{ label: 'Google Tag Manager', regex: /googletagmanager/i },
|
||||
{ label: 'dataLayer', regex: /\bdataLayer\b/ }
|
||||
]
|
||||
|
||||
const distStats = await stat(distDir).catch(() => null)
|
||||
if (!distStats?.isDirectory()) {
|
||||
console.error('dist directory not found. Run pnpm build first.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const files = await glob('dist/**/*', { nodir: true })
|
||||
const violations: Array<{
|
||||
file: string
|
||||
hits: Array<{ label: string; match: string }>
|
||||
}> = []
|
||||
|
||||
for (const file of files) {
|
||||
const extension = extname(file).toLowerCase()
|
||||
if (ignoredExtensions.has(extension)) continue
|
||||
|
||||
const content = (await readFile(file)).toString('utf8')
|
||||
const hits = telemetryPatterns
|
||||
.map((pattern) => {
|
||||
const match = content.match(pattern.regex)
|
||||
return match ? { label: pattern.label, match: match[0] } : null
|
||||
})
|
||||
.filter((hit): hit is { label: string; match: string } => hit !== null)
|
||||
|
||||
if (hits.length > 0) {
|
||||
violations.push({ file, hits })
|
||||
}
|
||||
}
|
||||
|
||||
if (violations.length > 0) {
|
||||
console.error('Telemetry references found in dist assets:')
|
||||
for (const violation of violations) {
|
||||
const formattedHits = violation.hits
|
||||
.map((hit) => `${hit.label} (${hit.match})`)
|
||||
.join(', ')
|
||||
console.error(`- ${violation.file}: ${formattedHits}`)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
Reference in New Issue
Block a user