Skip to content

Commit 5d4cfc1

Browse files
Merge pull request #12 from precise-alloy/code-ql
Add GitHub code quality pipeline
2 parents a94f298 + fe21e7b commit 5d4cfc1

5 files changed

Lines changed: 168 additions & 2 deletions

File tree

.github/codeql/codeql-config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: regressify-codeql
2+
3+
queries:
4+
- uses: security-extended
5+
- uses: security-and-quality
6+
7+
paths:
8+
- src
9+
10+
paths-ignore:
11+
- src/**/*.d.ts
12+
- src/**/*.js

.github/workflows/code-quality.yml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
name: Code Quality
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- release
8+
9+
push:
10+
branches:
11+
- master
12+
- release
13+
14+
schedule:
15+
- cron: '17 5 * * 1'
16+
17+
workflow_dispatch:
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
dependency-review:
28+
if: github.event_name == 'pull_request'
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: read
32+
pull-requests: read
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v5
36+
37+
- name: Review dependency changes
38+
uses: actions/dependency-review-action@v4
39+
with:
40+
fail-on-severity: high
41+
license-check: false
42+
43+
unit-quality:
44+
if: github.event_name != 'schedule'
45+
name: Unit Quality (Node ${{ matrix.node-version }})
46+
timeout-minutes: 20
47+
runs-on: ubuntu-latest
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
node-version:
52+
- 22.x
53+
- 24.x
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v5
57+
58+
- name: Set up Node.js
59+
uses: actions/setup-node@v5
60+
with:
61+
node-version: ${{ matrix.node-version }}
62+
cache: npm
63+
64+
- name: Install dependencies
65+
run: npm ci
66+
67+
- name: Type-check source
68+
run: npm run typecheck
69+
70+
- name: Run unit tests with coverage gate
71+
run: npm run test:ci
72+
73+
- name: Build package
74+
if: matrix.node-version == '24.x'
75+
run: npm run build
76+
77+
- name: Upload coverage artifact
78+
if: always() && matrix.node-version == '24.x' && hashFiles('coverage/**/*') != ''
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: coverage-node-${{ matrix.node-version }}
82+
path: coverage
83+
84+
- name: Publish coverage summary
85+
if: always() && matrix.node-version == '24.x' && hashFiles('coverage/coverage-summary.json') != ''
86+
shell: bash
87+
run: |
88+
node <<'EOF'
89+
const fs = require('node:fs');
90+
91+
const summaryPath = 'coverage/coverage-summary.json';
92+
const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8')).total;
93+
const metrics = ['lines', 'functions', 'statements', 'branches'];
94+
const rows = metrics.map((metric) => {
95+
const value = summary[metric]?.pct ?? 0;
96+
return `| ${metric} | ${value.toFixed(2)}% |`;
97+
});
98+
99+
const markdown = [
100+
'## Coverage Summary',
101+
'',
102+
'| Metric | Coverage |',
103+
'| --- | ---: |',
104+
...rows,
105+
'',
106+
'Coverage thresholds are enforced by the test runner configuration.',
107+
'',
108+
].join('\n');
109+
110+
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, markdown);
111+
EOF
112+
113+
codeql:
114+
name: CodeQL (JavaScript/TypeScript)
115+
timeout-minutes: 20
116+
runs-on: ubuntu-latest
117+
permissions:
118+
actions: read
119+
contents: read
120+
security-events: write
121+
strategy:
122+
fail-fast: false
123+
matrix:
124+
language:
125+
- javascript
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v5
129+
130+
- name: Set up Node.js
131+
uses: actions/setup-node@v5
132+
with:
133+
node-version: '24.x'
134+
cache: npm
135+
136+
- name: Initialize CodeQL
137+
uses: github/codeql-action/init@v3
138+
with:
139+
languages: ${{ matrix.language }}
140+
build-mode: none
141+
config-file: ./.github/codeql/codeql-config.yml
142+
143+
- name: Install dependencies
144+
run: npm ci
145+
146+
- name: Build package
147+
run: npm run build
148+
149+
- name: Perform CodeQL analysis
150+
uses: github/codeql-action/analyze@v3
151+
with:
152+
category: /language:${{ matrix.language }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ src/**/*.d.ts
66
src/**/*.map
77
*.tsbuildinfo
88
.states/
9-
visual_tests/
9+
visual_tests/
10+
coverage/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"scripts": {
1111
"build": "tsc --project tsconfig.json",
12+
"typecheck": "tsc --project tsconfig.json --noEmit",
1213
"install:browsers": "tsx src/index.ts install",
1314
"ref": "tsx src/index.ts ref",
1415
"approve": "tsx src/index.ts approve",

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineConfig({
88
exclude: ['node_modules/**', 'visual_tests/**'],
99
coverage: {
1010
provider: 'v8',
11-
reporter: ['text', 'html'],
11+
reporter: ['text', 'html', 'json-summary'],
1212
include: ['src/**/*.ts'],
1313
exclude: ['src/**/*.d.ts', 'src/index.ts', 'src/types.ts'],
1414
thresholds: {

0 commit comments

Comments
 (0)