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
0 commit comments