-
Notifications
You must be signed in to change notification settings - Fork 536
73 lines (64 loc) · 2.27 KB
/
codescan.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 }}