Skip to content

Commit

Permalink
Add Code Compatibility Reporting (MHKiT-Software#112)
Browse files Browse the repository at this point in the history
* 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
simmsa and simmsa committed May 13, 2024
1 parent 98899c3 commit bb60c8c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/code_compatibility_report.yml
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
38 changes: 38 additions & 0 deletions mhkit/tests/runCodeCompatibilityReport.m
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

0 comments on commit bb60c8c

Please sign in to comment.