DO_NOT_MERGE: test #61
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: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
jobs: | |
Linux: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: ['8.3'] | |
type: ['cli', 'zts'] | |
distro: ['bookworm'] | |
outputs: | |
matrix: ${{ toJson(matrix) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build container | |
run: | | |
docker compose build --pull --no-cache --build-arg PLATFORM="linux/amd64" --build-arg IMAGE="php" --build-arg TAG="${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }}" | |
- name: Test with gcov | |
run: | | |
docker compose run -v "$(pwd)/ext:/ext" --rm shell /bin/sh -c 'pskel test gcov && lcov --capture --directory "/ext" --output-file "/ext/lcov.info" --exclude "/usr/local/include/*" --exclude "third_party/*" && lcov --list "/ext/lcov.info"' | |
- name: Upload coverage to artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-${{ matrix.version }}-${{ matrix.type }}-${{ matrix.distro }} | |
path: ${{ github.workspace }}/ext/lcov.info | |
Coverage: | |
needs: [Linux] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download coverage artifacts | |
uses: actions/download-artifact@v4 | |
- name: Merge coverages | |
run: | | |
sudo apt-get install -y "lcov" | |
LCOV_FILES="$(find . -name "lcov.info")" | |
CMD="$(which "lcov")" | |
for LCOV_FILE in ${LCOV_FILES}; do | |
CMD+=" -a ${LCOV_FILE}" | |
done | |
CMD+=" -o lcov.info" | |
echo "Merging coverages: ${LCOV_FILES}" | |
${CMD} | |
- name: Report coverage | |
uses: k1LoW/octocov-action@v1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
config: .github/octocov.yml | |
- name: Upload coverage to artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-unified | |
path: ${{ github.workspace }}/lcov.info | |
PullRequestReviewForUncoveredLines: | |
needs: [Coverage] | |
if: github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download coverage artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage-unified | |
- name: Report comment for PR | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
function parseLcovInfo(filename) { | |
console.log(`Parsing LCOV file: ${filename}`); | |
const content = fs.readFileSync(filename, 'utf8'); | |
const lines = content.split('\n'); | |
const uncoveredLines = {}; | |
let currentFile = ''; | |
for (const line of lines) { | |
if (line.startsWith('SF:')) { | |
currentFile = line.substring(3).trim(); | |
} else if (line.startsWith('DA:')) { | |
const [lineNo, hits] = line.substring(3).trim().split(',').map(Number); | |
if (hits === 0) { | |
if (!uncoveredLines[currentFile]) { | |
uncoveredLines[currentFile] = []; | |
} | |
uncoveredLines[currentFile].push(lineNo); | |
} | |
} | |
} | |
console.log('Parsed uncovered lines:', uncoveredLines); | |
return uncoveredLines; | |
} | |
function groupConsecutiveLines(lines) { | |
if (lines.length === 0) return []; | |
lines.sort((a, b) => a - b); | |
const groups = []; | |
let currentGroup = [lines[0]]; | |
for (let i = 1; i < lines.length; i++) { | |
if (lines[i] === lines[i-1] + 1) { | |
currentGroup.push(lines[i]); | |
} else { | |
groups.push(currentGroup); | |
currentGroup = [lines[i]]; | |
} | |
} | |
groups.push(currentGroup); | |
return groups; | |
} | |
async function createReviewForUncoveredLines(uncoveredLines) { | |
const { owner, repo } = context.repo; | |
const pull_number = context.issue.number; | |
console.log(`Creating review for PR #${pull_number}`); | |
const { data: files } = await github.rest.pulls.listFiles({ | |
owner, | |
repo, | |
pull_number, | |
}); | |
console.log('Files in PR:', files.map(f => f.filename)); | |
const comments = []; | |
for (const file of files) { | |
const filename = '/' + file.filename; | |
if (uncoveredLines[filename]) { | |
console.log(`Processing file: ${filename}`); | |
const groups = groupConsecutiveLines(uncoveredLines[filename]); | |
for (const group of groups) { | |
const startLine = group[0]; | |
const endLine = group[group.length - 1]; | |
console.log(`Commenting on lines ${startLine}-${endLine}`); | |
const commentBody = `Lines ${startLine}-${endLine} are not covered by tests.`; | |
const comment = { | |
path: filename, | |
body: commentBody, | |
line: endLine, | |
side: 'RIGHT', | |
}; | |
if (startLine !== endLine) { | |
comment.start_line = startLine; | |
} | |
comments.push(comment); | |
} | |
} | |
} | |
console.log('Comments to be created:', comments); | |
if (comments.length > 0) { | |
try { | |
const response = await github.rest.pulls.createReview({ | |
owner, | |
repo, | |
pull_number, | |
event: 'COMMENT', | |
body: 'Review for uncovered lines', | |
comments, | |
}); | |
console.log('Review created successfully'); | |
} catch (error) { | |
console.error('Error creating review:', error); | |
if (error.response) { | |
console.error('Response status:', error.response.status); | |
console.error('Response data:', error.response.data); | |
} | |
} | |
} else { | |
console.log('No comments to create'); | |
} | |
} | |
const uncoveredLines = parseLcovInfo('lcov.info'); | |
await createReviewForUncoveredLines(uncoveredLines); |