Skip to content

Commit 96ddbe5

Browse files
committed
update ci
1 parent 1a777e2 commit 96ddbe5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6343
-735
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: MATLAB formatting
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "src/**"
7+
- "tests/**"
8+
push:
9+
paths:
10+
- "src/**"
11+
- "tests/**"
12+
13+
jobs:
14+
format-check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up MATLAB
20+
uses: matlab-actions/setup-matlab@v2
21+
22+
- name: Install MBeautifier
23+
run: |
24+
git clone https://github.com/davidvarga/MBeautifier.git
25+
mkdir -p ci/MBeautifier
26+
cp -r MBeautifier/* ci/MBeautifier/
27+
28+
- name: Create formatting script
29+
run: |
30+
cat > ci/format_check.m << 'EOF'
31+
function format_check()
32+
% Add MBeautifier to path
33+
addpath(fullfile('ci', 'MBeautifier'));
34+
35+
% Initialize MBeautifier
36+
addpath(genpath(fullfile('ci', 'MBeautifier')));
37+
38+
% Get all MATLAB files
39+
srcFiles = dir('src/**/*.m');
40+
testFiles = dir('tests/**/*.m');
41+
allFiles = [srcFiles; testFiles];
42+
43+
% Check formatting
44+
hasFormatIssues = false;
45+
for i = 1:length(allFiles)
46+
file = fullfile(allFiles(i).folder, allFiles(i).name);
47+
fprintf('Checking formatting for %s\n', file);
48+
49+
% Read original file
50+
fid = fopen(file, 'r');
51+
if fid == -1
52+
error('Could not open file: %s', file);
53+
end
54+
originalText = fread(fid, '*char')';
55+
fclose(fid);
56+
57+
% Format the text
58+
formattedText = MBeautify.formatText(originalText);
59+
60+
% Compare
61+
if ~strcmp(originalText, formattedText)
62+
hasFormatIssues = true;
63+
fprintf(' Formatting issues found\n');
64+
else
65+
fprintf(' No formatting issues\n');
66+
end
67+
end
68+
69+
% For CI demonstration purposes, don't fail the build
70+
if hasFormatIssues
71+
fprintf('\nFormatting issues found, but CI will continue\n');
72+
fprintf('Run MBeautifier locally to fix formatting issues\n');
73+
else
74+
fprintf('\nNo formatting issues found\n');
75+
end
76+
end
77+
EOF
78+
79+
- name: Run formatting check
80+
uses: matlab-actions/run-command@v2
81+
with:
82+
command: addpath('ci'); format_check

.github/workflows/matlab-lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: MATLAB lint
2+
3+
on:
4+
push:
5+
paths:
6+
- "src/**"
7+
- "tests/**"
8+
pull_request:
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up MATLAB
17+
uses: matlab-actions/setup-matlab@v2
18+
19+
- name: Run MATLAB Code Analyzer
20+
uses: matlab-actions/run-command@v2
21+
with:
22+
command: ci.lint
23+
24+
- name: Upload lint log (optional)
25+
if: always()
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: matlab-lint-log
29+
path: ci/lint.log
30+
if-no-files-found: ignore

.github/workflows/matlab-tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: MATLAB tests
2+
3+
on:
4+
push:
5+
paths:
6+
- "src/**"
7+
- "tests/**"
8+
pull_request:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up MATLAB
17+
uses: matlab-actions/setup-matlab@v2
18+
19+
- name: Run tests
20+
uses: matlab-actions/run-tests@v2
21+
with:
22+
source-folder: src
23+
select-by-folder: tests
24+
test-results-junit: test-results/results.xml
25+
code-coverage-cobertura: coverage/coverage.xml
26+
27+
- name: Upload test reports
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: matlab-test-and-coverage
31+
path: |
32+
test-results
33+
coverage/coverage.xml

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"plugins": ["prettier-plugin-matlab"],
3+
"printWidth": 100,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"endOfLine": "lf"
7+
}

ci/MBeautifier

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit cff447fee76e52ee0fcc4959c0ec3507a9ea514b

ci/format_matlab_code.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function format_matlab_code()
2+
% FORMAT_MATLAB_CODE Format MATLAB code using MBeautifier
3+
%
4+
% This function formats all MATLAB files in the src/ and tests/ directories
5+
% using MBeautifier. It requires MBeautifier to be installed in ci/MBeautifier.
6+
%
7+
% To use:
8+
% 1. Clone MBeautifier: git clone https://github.com/davidvarga/MBeautifier.git ci/MBeautifier
9+
% 2. Run this script: matlab -batch "addpath('ci'); format_matlab_code"
10+
11+
% Add MBeautifier to path
12+
addpath(fullfile('ci', 'MBeautifier'));
13+
14+
% Initialize MBeautifier
15+
addpath(genpath(fullfile('ci', 'MBeautifier')));
16+
17+
% Get all MATLAB files
18+
srcFiles = dir('src/**/*.m');
19+
testFiles = dir('tests/**/*.m');
20+
allFiles = [srcFiles; testFiles];
21+
22+
% Format files
23+
fprintf('Formatting %d MATLAB files...\n', length(allFiles));
24+
for i = 1:length(allFiles)
25+
file = fullfile(allFiles(i).folder, allFiles(i).name);
26+
fprintf('Formatting %s\n', file);
27+
28+
% Format the file
29+
MBeautify.formatFile(file, file);
30+
end
31+
32+
fprintf('\nDone! All files formatted.\n');
33+
end

ci/lint.log

Whitespace-only changes.

ci/lint.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function lint
2+
% Lint MATLAB code using Code Analyzer.
3+
folders = {'src','tests'};
4+
% Ignore common issues that are less critical for CI
5+
% CABE: Cyclomatic complexity warnings
6+
% ACABE: Anonymous function cyclomatic complexity
7+
% NASGU: Value assigned but not used
8+
% ASGLU: Value assigned but not used (variable)
9+
% INUSD: Input argument might be unused
10+
% NCHKE: Use NARGOUTCHK without ERROR
11+
% NCHKN: Use NARGINCHK without ERROR
12+
% CAXIS: caxis is not recommended, use clim instead
13+
% DATST: datestr is not recommended
14+
% TNOW1: now is not recommended
15+
% FNCOLND: Consider explicitly defining the array
16+
% USENS: Explicitly initialize this variable
17+
ignoreIDs = {
18+
'CABE';
19+
'ACABE';
20+
'NASGU';
21+
'ASGLU';
22+
'INUSD';
23+
'NCHKE';
24+
'NCHKN';
25+
'CAXIS';
26+
'DATST';
27+
'TNOW1';
28+
'FNCOLND';
29+
'USENS'
30+
};
31+
logFile = fullfile('ci','lint.log');
32+
if ~exist('ci','dir')
33+
mkdir('ci');
34+
end
35+
fid = fopen(logFile,'w');
36+
37+
hasIssues = false;
38+
for f = 1:numel(folders)
39+
if ~isfolder(folders{f})
40+
continue;
41+
end
42+
S = dir(fullfile(folders{f},'**','*.m'));
43+
for k = 1:numel(S)
44+
file = fullfile(S(k).folder,S(k).name);
45+
% Add more flags if desired
46+
msgs = checkcode(file,'-cyc','-id','-struct');
47+
if ~isempty(ignoreIDs)
48+
msgs = msgs(~ismember({msgs.id},ignoreIDs));
49+
end
50+
for m = 1:numel(msgs)
51+
hasIssues = true;
52+
line = sprintf('%s:%d:%d: %s [%s]\n', file, msgs(m).line, msgs(m).column, msgs(m).message, msgs(m).id);
53+
fprintf('%s', line);
54+
fprintf(fid, '%s', line);
55+
end
56+
end
57+
end
58+
59+
fclose(fid);
60+
if hasIssues
61+
error('Code Analyzer found issues. See ci/lint.log.');
62+
end
63+
end

0 commit comments

Comments
 (0)