Update codecov.yml #133
Workflow file for this run
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: 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 | |
cobratoolbox/CodeCovTestResults.xml | |
# 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('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 | |
}); |