Compare commits
3 Commits
main
...
ishymko/co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de1af81601 | ||
|
|
f775336a43 | ||
|
|
e7c83e940b |
113
.github/workflows/coverage-experiment.yml
vendored
Normal file
113
.github/workflows/coverage-experiment.yml
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
name: Coverage Delta
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
compare-coverage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 24
|
||||
|
||||
- name: Checkout Main
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: main
|
||||
|
||||
- name: Install & Test (Main)
|
||||
run: |
|
||||
npm ci
|
||||
npm run coverage
|
||||
mv ./coverage/coverage-summary.json ./coverage-main-summary.json
|
||||
|
||||
- name: Checkout PR Branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
clean: true
|
||||
|
||||
- name: Install & Test (PR)
|
||||
run: |
|
||||
npm ci
|
||||
npm run coverage
|
||||
|
||||
- name: Report Coverage Delta
|
||||
uses: actions/github-script@v6
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
|
||||
const loadSummary = (path) => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(path, 'utf8'));
|
||||
} catch (error) {
|
||||
console.log(`Could not load ${path}: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const mainSummary = loadSummary('./coverage-main-summary.json');
|
||||
const prSummary = loadSummary('./coverage/coverage-summary.json');
|
||||
|
||||
if (!mainSummary || !prSummary) {
|
||||
core.setFailed('Could not load coverage summaries for comparison.');
|
||||
return;
|
||||
}
|
||||
|
||||
const metrics = ['lines', 'statements', 'functions', 'branches'];
|
||||
|
||||
const getPct = (summary, metric) => summary.total[metric].pct;
|
||||
|
||||
let markdown = `### 🧪 Code Coverage Delta\n\n`;
|
||||
markdown += `| Metric | Main | PR | Delta |\n`;
|
||||
markdown += `| :--- | :---: | :---: | :---: |\n`;
|
||||
|
||||
metrics.forEach(metric => {
|
||||
const oldPct = getPct(mainSummary, metric);
|
||||
const newPct = getPct(prSummary, metric);
|
||||
const diff = (newPct - oldPct).toFixed(2);
|
||||
|
||||
let icon = '';
|
||||
if (diff > 0) icon = '🟢';
|
||||
else if (diff < 0) icon = '🔴';
|
||||
else icon = '⚪️';
|
||||
|
||||
// Format with + sign for positive numbers
|
||||
const diffStr = diff > 0 ? `+${diff}%` : `${diff}%`;
|
||||
|
||||
markdown += `| **${metric}** | ${oldPct}% | ${newPct}% | ${icon} ${diffStr} |\n`;
|
||||
});
|
||||
|
||||
markdown += `\n_Generated by c8 and GitHub Actions_`;
|
||||
|
||||
const { owner, repo } = context.repo;
|
||||
const issue_number = context.issue.number;
|
||||
|
||||
const comments = await github.rest.issues.listComments({
|
||||
owner,
|
||||
repo,
|
||||
issue_number,
|
||||
});
|
||||
|
||||
const botComment = comments.data.find(c =>
|
||||
c.body.includes('### 🧪 Code Coverage Delta') &&
|
||||
c.user.type === 'Bot'
|
||||
);
|
||||
|
||||
if (botComment) {
|
||||
await github.rest.issues.updateComment({
|
||||
owner,
|
||||
repo,
|
||||
comment_id: botComment.id,
|
||||
body: markdown
|
||||
});
|
||||
} else {
|
||||
await github.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number,
|
||||
body: markdown
|
||||
});
|
||||
}
|
||||
@ -7,7 +7,7 @@ export default defineConfig({
|
||||
include: ['test/**/*.spec.ts'],
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['text', 'json', 'html'],
|
||||
reporter: ['text', 'json', 'html', 'json-summary'],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user