Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Code Compatibility Reporting #112

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading