Skip to content

Code Scan

Code Scan #1010

Workflow file for this run

name: 'Code Scan'
on:
schedule:
- cron: '0 * * * *'
jobs:
codescan:
name: Scan the repository
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: npm i -g npm@^10.5.1
- name: Install dependencies
run: npm ci
- uses: actions/github-script@v7
id: file-counts
with:
script: |
const fg = require('fast-glob')
const fs = require('fs')
const path = require('path')
const files = await fg.glob(['packages/react/src/**/*.tsx', 'packages/react/src/**/*.module.css'], {
ignore: [
'**/__tests__/**',
'**/_*.tsx',
'**/*.figma.tsx',
'**/*.stories.tsx',
'**/*.test.tsx',
'**/CSSComponent/**',
'**/hooks/**',
'**/index.tsx',
'**/utils/**',
],
})
const metrics = []
for (const file of files) {
const content = fs.readFileSync(file, 'utf8')
const name = path.parse(file).name.replace('.module', '')
if (file.endsWith('.tsx')) {
const matched = content.match(/.`$([^`]*)^`$/gm)
if (matched) {
const count = matched.join('\n').split('\n').length
metrics.push(
`- type: "count"\n name: "primer.react.styled-system.count"\n value: ${count}\n tags:\n - "path:${file}"\n - "component:${name}"`,
)
}
} else {
const count = content.split('\n').length
metrics.push(
`- type: "count"\n name: "primer.react.css-module.count"\n value: ${count}\n tags:\n - "path:${file}"\n - "component:${name}"`,
)
}
}
core.setOutput('metrics', metrics.join('\n'))
- name: Build count
uses: masci/datadog@v1
with:
api-key: ${{ secrets.datadog_api_key }}
metrics: ${{ steps.file-counts.outputs.metrics }}