Skip to content

Update codecov.yml #132

Update codecov.yml

Update codecov.yml #132

Workflow file for this run

name: MATLAB Tests and Code Coverage
on:
pull_request:
branches:
- '**'
jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout PR Code
uses: actions/checkout@v4
- name: Clone COBRA Toolbox
run: |
git clone -b develop https://github.com/opencobra/cobratoolbox.git cobratoolbox
- name: Run MATLAB Tests
run: |
matlab -batch "run('cobratoolbox/initCobraToolbox.m'); diary('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
# 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 xml = fs.readFileSync('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[^>]*>([^<]*)<\/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
});