Skip to content
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/codescan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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 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')
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}"`,
)
}
} 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}"`,
)
}
}

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 }}