-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (82 loc) · 2.92 KB
/
coverage.yaml
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Coverage
permissions:
contents: write
pull-requests: write
on:
push:
branches:
- main
pull_request:
jobs:
PullRequestComment:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# - name: Download coverage artifact
# uses: actions/download-artifact@v4
# with:
# name: coverage-unified
- name: Get changed files
uses: tj-actions/changed-files@v45
id: changed-files
- name: Install lcov-parse
run: npm install lcov-parse
- name: Report comment for PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const lcovParse = require('lcov-parse');
const lcovFile = fs.readFileSync('./lcov.info', 'utf8');
lcovParse(lcovFile, async (err, data) => {
if (err) {
console.error('Error parsing lcov file:', err);
return;
}
const { data: diff } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
mediaType: {
format: 'diff'
}
});
const lines = diff.split('\n');
let currentFile = '';
let lineNumber = 0;
for (const line of lines) {
if (line.startsWith('+++')) {
currentFile = line.substring(6);
lineNumber = 0;
} else if (line.startsWith('@@')) {
const match = line.match(/@@ -\d+,\d+ \+(\d+),/);
if (match) {
lineNumber = parseInt(match[1]) - 1;
}
} else if (line.startsWith('+') && !line.startsWith('+++')) {
lineNumber++;
const fileData = data.find(f => f.file === currentFile);
if (fileData) {
const lineData = fileData.lines.details.find(l => l.line === lineNumber);
if (lineData && lineData.hit === 0) {
await github.rest.pulls.createReviewComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: 'This line is not covered by tests.',
commit_id: context.payload.pull_request.head.sha,
path: currentFile,
line: lineNumber
});
}
}
} else if (!line.startsWith('-')) {
lineNumber++;
}
}
});