Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codecov.yml #2407

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,41 @@ jobs:
name: test-report
path: test_results.txt

# Parse Test Results and Comment on PR
# Parse Test Results and Comment on PR using regex
- name: Parse Test Results and Comment on PR
uses: actions/github-script@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs');
const xml2js = require('xml2js');
const parser = new xml2js.Parser({ explicitArray: true });

const xml = fs.readFileSync('CodeCovTestResults.xml', 'utf8');
parser.parseString(xml, function (err, result) {
if (err) {
console.error('Failed to parse XML:', err);
return;
}

const testSuite = result.testsuites.testsuite[0];
const summary = `Test Results: Passed: ${testSuite.$.tests - testSuite.$.failures - testSuite.$.skipped}, Failed: ${testSuite.$.failures}, Skipped: ${testSuite.$.skipped}`;

let details = '';
if (testSuite.$.failures > 0) {
details = '\n\nFailed Tests:\n';
testSuite.testcase.forEach(test => {
if (test.error) {
details += `* ${test.$.name}: ${test.error[0].$.message}\n`;
}
});
}
// Extract data using regex
const passedRegex = /tests="(\d+)" failures="(\d+)" errors="(\d+)" skipped="(\d+)"/;
const matches = passedRegex.exec(xml);
const totalTests = matches[1];
const failures = matches[2];
const errors = matches[3];
const skipped = matches[4];

let summary = `Test Results: Passed: ${totalTests - failures - skipped}, Failed: ${failures}, Errors: ${errors}, Skipped: ${skipped}`;

// Find failed tests
const failedTestsRegex = /<testcase classname="[^"]*" name="([^"]+)"[^>]*>\s*<error[^>]*>([^<]*)<\/error>/g;
let failedTestDetails = '';
let match;
while ((match = failedTestsRegex.exec(xml)) !== null) {
failedTestDetails += `\n* ${match[1]}: ${match[2]}`;
}

if (failedTestDetails.length > 0) {
summary += `\n\nFailed Tests:${failedTestDetails}`;
}

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary + details
});
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});
Loading