ci: add coverage trend monitoring
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
name: Coverage Report
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
report:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Generate coverage
|
||||||
|
run: |
|
||||||
|
npm run test:unit -- --coverage
|
||||||
|
node scripts/coverage-trend.js > coverage-metrics.json
|
||||||
|
|
||||||
|
- name: Upload metrics
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: coverage-metrics
|
||||||
|
path: coverage-metrics.json
|
||||||
|
|
||||||
|
- name: Comment coverage on PR
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
uses: actions/github-script@v7
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const fs = require('fs');
|
||||||
|
const metrics = JSON.parse(fs.readFileSync('coverage-metrics.json', 'utf8'));
|
||||||
|
|
||||||
|
const comment = `## Coverage Report
|
||||||
|
|
||||||
|
- Statements: ${metrics.statements}%
|
||||||
|
- Branches: ${metrics.branches}%
|
||||||
|
- Functions: ${metrics.functions}%
|
||||||
|
- Lines: ${metrics.lines}%
|
||||||
|
|
||||||
|
Generated at: ${metrics.timestamp}`;
|
||||||
|
|
||||||
|
github.rest.issues.createComment({
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: comment
|
||||||
|
});
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const coverageFilePath = path.join(__dirname, '..', 'coverage', 'coverage-final.json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!fs.existsSync(coverageFilePath)) {
|
||||||
|
console.error('Coverage file not found:', coverageFilePath);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const coverage = JSON.parse(fs.readFileSync(coverageFilePath, 'utf8'));
|
||||||
|
|
||||||
|
const metrics = {
|
||||||
|
statements: coverage.total.statements.pct,
|
||||||
|
branches: coverage.total.branches.pct,
|
||||||
|
functions: coverage.total.functions.pct,
|
||||||
|
lines: coverage.total.lines.pct,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(JSON.stringify(metrics, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error reading coverage:', error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user