Update codecov.yml to use git actions #131
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 | |
# Parse Test Results and Comment on PR | |
- 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`; | |
} | |
}); | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: summary + details | |
}); | |
}); |