DO_NOT_MERGE: test #46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | |
} | |
} | |
}); |