Skip to content

Commit 683acc9

Browse files
nnoNikolaas N. Oosterhof
andauthored
BLD: support Matlab CI
* BLD: add workflow_dispatch * BLD: add matlab-ci * BLD: adapt tests to deal with absent statistics toolbox (CI) --------- Co-authored-by: Nikolaas N. Oosterhof <n.n.oosterhof@gmail.com>
1 parent d00647e commit 683acc9

18 files changed

Lines changed: 227 additions & 39 deletions

‎.github/workflows/CI_matlab.yml‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: CI matlab
3+
4+
# - Installs
5+
# - MATLAB github action
6+
# - MOcov
7+
# - checks out MOXunit
8+
# - Runs tests
9+
# - If tests pass, uploads coverage to codecov
10+
11+
# Controls when the action will run.
12+
# Triggers the workflow:
13+
# - on push for the master branch
14+
# - on pull request for all branches
15+
on:
16+
push:
17+
branches: [master]
18+
pull_request:
19+
branches: ['*']
20+
workflow_dispatch:
21+
22+
# cancel previous runs on the same branch / PR
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
29+
tests:
30+
31+
strategy:
32+
matrix:
33+
# Note that some older versions (e.g R2020a, R2020b...) may not be available on all OS
34+
matlab_version: [R2020b, R2022a, R2023b, R2025a]
35+
os: [ubuntu-latest, macos-latest, windows-latest]
36+
fail-fast: false # Don't cancel all jobs if one fails
37+
38+
runs-on: ${{ matrix.os }}
39+
40+
steps:
41+
# use matlab-actions/setup-matlab to setup a specific version of MATLAB
42+
# https://github.com/matlab-actions/setup-matlab
43+
- name: Install MATLAB
44+
uses: matlab-actions/setup-matlab@v2
45+
with:
46+
release: ${{ matrix.matlab_version }}
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
49+
- name: Install CoSMoMVPA
50+
uses: matlab-actions/run-command@v2
51+
with:
52+
command: cd('mvpa'); cosmo_set_path(); cd ..; savepath(); exit(0);
53+
54+
- name: Download MOxUnit, MOcov, MOdox
55+
run: |
56+
git clone https://github.com/MOxUnit/MOxUnit.git --depth 1
57+
git clone https://github.com/MOcov/MOcov.git --depth 1
58+
git clone https://github.com/MOdox/MOdox.git --depth 1
59+
- name: Install MOxUnit, MOcov, MOdox
60+
uses: matlab-actions/run-command@v2
61+
with:
62+
command: origin=pwd(); disp(pwd); dir; pp=[origin '/']; cd([pp 'MOxUnit/MOxUnit']); moxunit_set_path(); cd([pp 'MOcov/MOcov']); addpath(pwd); cd([pp 'MOdox/MOdox']); addpath(pwd); savepath(); disp('Path is now'); disp(path); cd(origin);
63+
64+
# use matlab-actions/setup-matlab to run a matlab command
65+
# https://github.com/matlab-actions/setup-matlab
66+
- name: Run tests
67+
uses: matlab-actions/run-command@v2
68+
with:
69+
command: result=cosmo_run_tests('-verbose', '-cover', 'mvpa', '-with_coverage', '-cover_xml_file', 'coverage.xml'); exit(~result);
70+
71+
- name: Code coverage
72+
uses: codecov/codecov-action@v5
73+
with:
74+
files: coverage.xml
75+
flags: ${{ matrix.os }}_matlab-${{ matrix.matlab_version }}
76+
name: codecov-matlab
77+
fail_ci_if_error: false
78+
token: ${{ secrets.CODECOV_TOKEN }}

‎.github/workflows/CI_octave.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
branches: [master]
1919
pull_request:
2020
branches: ['*']
21+
workflow_dispatch:
2122

2223
# cancel previous runs on the same branch / PR
2324
concurrency:

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.m~
55
*.bak
66
*.m_tmp
7+
*.asv
78
data
89
datadb
910
datadb.zip

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ gh-pages-repo:
267267
git push -f -u origin main; \
268268
echo "Done"
269269

270+
gh-pages: html gh-pages-repo
270271

271272
website: website-content website-sync
272273

‎mvpa/cosmo_check_external.m‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
% 'matlabcsvm'
2121
% 'svm' Either matlabsvm or libsvm
2222
% '@{name}' Matlab toolbox {name}
23+
% (fails if on Octave)
24+
% '#stats' Statistics functions
2325
% It can also be '-list', '-tic', '-toc',' or
2426
% '-cite'; see below for their meaning.
2527
% raise_ if true (the default), an error is raised if the
@@ -138,6 +140,23 @@
138140
if external(1) == '@'
139141
toolbox_name = external(2:end);
140142
is_ok = check_matlab_toolbox(toolbox_name, raise_);
143+
elseif external(1) == '#'
144+
% Special case for Continuous IntegrationI: On CI testing, the
145+
% Matlab statistics toolbox is not available. This means a lot of
146+
% tests must be skipped.
147+
%
148+
% For now it is assumed this is not an issue on Octave, although
149+
% the code *may* need to be adapted to better deal with cases where
150+
% Octave does not have the statistics package installed.
151+
toolbox_name = external(2:end);
152+
if ~strcmp(toolbox_name, 'stats')
153+
error('''#'' requires ''stats'' (CI Matlab case, FIXME?)');
154+
end
155+
156+
is_ok = ~cosmo_wtf('is_matlab') || ...
157+
(check_matlab_toolbox(toolbox_name, raise_) && ...
158+
~isempty(which('fcdf')));
159+
141160
elseif external(1) == '!'
142161
command_name = external(2:end);
143162
is_ok = check_which(command_name, raise_);
@@ -395,8 +414,8 @@
395414
'Article ID 156869, 9 pages.', ...
396415
'doi:10.1155/2011/156869'];
397416

398-
externals.eeglab.is_present = @() has('eeglab') ...
399-
&& has('pop_loadset');
417+
externals.eeglab.is_present = @() has('eeglab') && ...
418+
has('pop_loadset');
400419
externals.eeglab.is_recent = yes;
401420
externals.eeglab.label = 'EEGLAB toolbox';
402421
externals.eeglab.url = 'https://sccn.ucsd.edu/eeglab/';

‎mvpa/cosmo_dim_match.m‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
% the intersection of the individual masks.
3131
%
3232
% Examples:
33-
%
3433
% % in an fMRI dataset, get all features with the first voxel dimension
3534
% % between 5 and 10, inclusive
3635
% ds=cosmo_synthetic_dataset('type','fmri','size','huge');

‎mvpa/cosmo_meeg_senstype_collection.m‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138

139139
function sens_type_names = get_initial_sens_type_names()
140140
func_name = 'ft_senslabel';
141+
ignore_names = {'yokogawa208'};
142+
141143
if isempty(which(func_name))
142144
error('Cannot find ''%s'' in search path:\n %s', ...
143145
func_name, cosmo_strjoin(cosmo_wtf('path'), '\n '));
@@ -151,7 +153,8 @@
151153
last = find(d == -1, 1);
152154

153155
sens_types_cell = match(first:last);
154-
sens_type_names = cellfun(@(x)x{:}, sens_types_cell);
156+
sens_type_names = setdiff(cellfun(@(x)x{:}, sens_types_cell), ...
157+
ignore_names);
155158

156159
function senstypes = get_initial_senstypes(sens_type_names)
157160
senstypes = struct();

‎mvpa/cosmo_singleton_neighborhood.m‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
% % comparison correction using a clustering neighborhood defined
1717
% % by cosmo_singleton_neighborhood with cosmo_montecarlo_cluster_stat
1818
% %
19+
% % (This example requires statistics functions)
20+
% cosmo_skip_test_if_no_external('#stats');
21+
% %
1922
% nsubjects=10;
2023
% nrois=4;
2124
% ds=struct();

‎mvpa/cosmo_stat.m‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
% Examples:
5656
% % one-sample t-test
5757
% % make a simple dataset
58+
% %
59+
% % (This example requires statistics functions)
60+
% cosmo_skip_test_if_no_external('#stats');
61+
% %
5862
% ds=struct();
5963
% ds.samples=reshape(mod(1:7:(12*3*7),13)',[],3)-3;
6064
% ds.sa.targets=ones(12,1);
@@ -107,6 +111,10 @@
107111
% % one-way ANOVA
108112
% % each observation is independent and thus each chunk is unique;
109113
% % there are three conditions with four observations per condition
114+
% %
115+
% % (This example requires statistics functions)
116+
% cosmo_skip_test_if_no_external('#stats');
117+
% %
110118
% ds=struct();
111119
% ds.samples=reshape(mod(1:7:(12*3*7),13)',[],3)-3;
112120
% ds.sa.targets=repmat(1:3,1,4)';
@@ -131,6 +139,10 @@
131139
% % two-sample t-test
132140
% % each observation is independent and thus each chunk is unique;
133141
% % there are two conditions with four observations per condition
142+
% %
143+
% % (This example requires statistics functions)
144+
% cosmo_skip_test_if_no_external('#stats');
145+
% %
134146
% ds=struct();
135147
% ds.samples=reshape(mod(1:7:(12*3*7),13)',[],3)-3;
136148
% ds.sa.targets=repmat(1:2,1,6)';

‎tests/test_classify.m‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ function test_general_classifiers_strong_signal()
1313
% note: part of these checks are also implemented in
1414
% general_test_classifier (included below)
1515

16+
if cosmo_wtf('is_matlab')
17+
csvm_external = '!fitcsvm';
18+
else
19+
non_existing_external = '!';
20+
csvm_external = non_existing_external;
21+
end
22+
1623
cfy_cell = {{@cosmo_classify_lda, ''}, ...
1724
{@cosmo_classify_nn, ''}, ...
1825
{@cosmo_classify_naive_bayes, ''}, ...
1926
{@cosmo_classify_libsvm, 'libsvm'}, ...
2027
{@cosmo_classify_matlabsvm, 'matlabsvm'}, ...
21-
{@cosmo_classify_matlabcsvm, 'matlabcsvm'}};
28+
{@cosmo_classify_matlabcsvm, csvm_external}};
2229

2330
n_cfy = numel(cfy_cell);
2431

@@ -164,9 +171,10 @@ function test_general_classifiers_strong_signal()
164171

165172
cfy = @cosmo_classify_matlabcsvm;
166173
handle = get_predictor(cfy);
167-
if ~cosmo_check_external('matlabcsvm', false)
174+
if ~cosmo_check_external('matlabcsvm', false) || ...
175+
~cosmo_check_external('!fitcsvm', false)
168176
assert_throws_illegal_input_exceptions(cfy);
169-
assertExceptionThrown(handle, '');
177+
assertExceptionThrown(handle);
170178
notify_test_skipped('matlabcsvm');
171179
return
172180
end

0 commit comments

Comments
 (0)