Skip to content

Commit

Permalink
Merge pull request #2409 from farid-zare/CI
Browse files Browse the repository at this point in the history
Update codecov.yml
  • Loading branch information
farid-zare authored Feb 3, 2025
2 parents 260f2b2 + da8d66e commit 2fa2868
Showing 1 changed file with 7 additions and 41 deletions.
48 changes: 7 additions & 41 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,17 @@ jobs:
- name: Run MATLAB Tests
run: |
matlab -batch "run('cobratoolbox/initCobraToolbox.m'); diary('test_results.txt'); run('cobratoolbox/test/testAll.m'); diary off;"
matlab -batch "run('cobratoolbox/initCobraToolbox.m'); diary('cobratoolbox/test_results.txt'); run('cobratoolbox/test/testAll.m'); diary off;"
- name: Upload Test Report
uses: actions/upload-artifact@v4
with:
name: test-report
path: |
test_results.txt
cobratoolbox/CodeCovTestResults.xml
path: cobratoolbox/test_results.txt # Correct path

# 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 }}
- name: Upload Coverage to Codecov
if: always()
uses: codecov/codecov-action@v3
with:
script: |
const fs = require('fs');
const xml = fs.readFileSync('cobratoolbox/CodeCovTestResults.xml', 'utf8');
// 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|failure)[^>]*>([^<]*)<\/(error|failure)>/g;
let failedTestDetails = '';
let match;
while ((match = failedTestsRegex.exec(xml)) !== null) {
failedTestDetails += `\n* ${match[1]}: ${match[3]}`;
}
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
});
files: cobratoolbox/CodeCovTestResults.xml # Correct path

0 comments on commit 2fa2868

Please sign in to comment.