forked from MHKiT-Software/MHKiT-MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Code Compatibility Reporting (MHKiT-Software#112)
* Feature: Add runner for code compatibility report Documentation: https://www.mathworks.com/help/matlab/ref/codecompatibilityreport.html Output is displayed and parsed. If "Error" is found is the Severity column, exit status 1 is returned. Planning to add a separate GitHub action that runs this report only. * Actions: Initial test of code compatibility report * Actions: Remove unnecessary steps from code compatibility --------- Co-authored-by: Andrew Simms <[email protected]>
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: MHKiT-MATLAB Code Compatibility Test | ||
|
||
on: | ||
push: | ||
branches: [master, develop] | ||
pull_request: | ||
branches: [master, develop] | ||
|
||
jobs: | ||
main: | ||
strategy: | ||
fail-fast: false | ||
|
||
matrix: | ||
os: [macos-latest, ubuntu-latest, windows-latest] | ||
python-version: [3.8, 3.9, "3.10", 3.11] | ||
matlab-version: [R2021b, R2022a, R2022b, R2023a, R2023b] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Check out MHKiT-MATLAB | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up MATLAB | ||
uses: matlab-actions/setup-matlab@v2-beta | ||
with: | ||
release: ${{ matrix.matlab-version }} | ||
|
||
- name: Build file to run code compatability report | ||
shell: bash | ||
run: echo "version, | ||
addpath(genpath('mhkit')), | ||
results = runCodeCompatibilityReport()" >> run.m | ||
|
||
- name: Echo runner for code compatibility report | ||
shell: bash | ||
run: cat run.m | ||
|
||
- name: Run code compatibility report | ||
uses: matlab-actions/run-command@v1 | ||
with: | ||
command: run | ||
startup-options: -noFigureWindows |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function results = runCodeCompatibilityReport() | ||
% Find source code folder | ||
this_filename = mfilename('fullpath'); | ||
this_folder = fileparts(this_filename); | ||
sourceCodeFolder = fileparts(this_folder); | ||
|
||
% Generate MATLAB code compatibility report | ||
r = analyzeCodeCompatibility(sourceCodeFolder, 'IncludeSubfolders', true); | ||
|
||
% Print code compatability report | ||
display("MHKiT MATLAB Code Compatibility Report"); | ||
display(r.Recommendations); | ||
|
||
% Search for error string in the `Severity` column. If found exit with status code 1 to indicate to the test runner that ther | ||
error_string = 'Error'; | ||
severity_array = r.Recommendations.Severity; | ||
|
||
% Convert categorical array to cell array of strings | ||
severity_cell_array = cellstr(severity_array); | ||
|
||
% Sanitize error string | ||
sanitized_error_string = lower(strtrim(error_string)); | ||
|
||
% Sanitize each element in the array using cellfun | ||
sanitized_severity_array = cellfun(@(x) lower(strtrim(x)), severity_cell_array, 'UniformOutput', false); | ||
|
||
if any(strcmp(sanitized_severity_array, sanitized_error_string)) | ||
disp(['Code Compatability Failure: Found "', error_string, '". in the MHKiT-MATLAB code compatability report. See above output for details.']); | ||
exit(1); | ||
else | ||
disp('Success: MHKiT-MATLAB Code Compatability Analysis did not find errors!'); | ||
exit(0); | ||
end | ||
|
||
|
||
results = runCodeCompatibilityReport(); | ||
|
||
end |