Skip to content

Commit

Permalink
run demos with MOxUnit in CI so that demo2 is run even if demo1 fails
Browse files Browse the repository at this point in the history
run test demi CI set up through yml

undo refactoring

fix function name

make sure demos run locally

use same approach to run tests and demos in CI

use similar calls for both tests and demos in CI
  • Loading branch information
Remi-Gau committed Apr 8, 2022
1 parent 956da88 commit 9def9a2
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 18 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/run_demos.m

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/run_demos_ci.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
% run demos with moxunit in github CI

root_dir = getenv('GITHUB_WORKSPACE');

% MOxUnit and MOcov need to be in the matlab path
addpath(fullfile(root_dir, 'MOcov', 'MOcov'));
cd(fullfile(root_dir, 'MOxUnit', 'MOxUnit'));
run moxunit_set_path();

% add glm single to path
cd(root_dir)
setup();

this_folder = fileparts(mfilename('fullpath'));
test_folder = this_folder;
success = moxunit_runtests(test_folder, '-verbose', '-recursive');

if success
system('echo 0 > test_report.log');
else
system('echo 1 > test_report.log');
end
15 changes: 11 additions & 4 deletions .github/workflows/run_demos_matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ name: MATLAB demos
on:
schedule:
- cron: "0 0 1,15 * *"
push:
# TODO only run on master branch on push
branches: ["*"]

jobs:
demos:
Expand All @@ -29,18 +32,22 @@ jobs:
- name: Install MATLAB
uses: matlab-actions/[email protected]
with:
# MATLAB release to set up R2020a
release: R2020a

- name: Shallow clone GLMsingle
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
fetch-depth: 0 # 0 means we only get the last commit, not the whole git history

- name: Install Moxunit and MOcov
run: |
git clone https://github.com/MOxUnit/MOxUnit.git --depth 1
git clone https://github.com/MOcov/MOcov.git --depth 1
- name: Run commands
uses: matlab-actions/[email protected]
with:
command:
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run run_demos;
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run run_demos_ci;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
% run tests with code coverage via the run_tests scripts in the root folder.

root_dir = getenv('GITHUB_WORKSPACE');

% MOxUnit and MOcov need to be in the matlab path
addpath(fullfile(root_dir, 'MOcov', 'MOcov'));
cd(fullfile(root_dir, 'MOxUnit', 'MOxUnit'));
run moxunit_set_path();

% adds GLM single to the path and runs all the tests
cd(fullfile(root_dir));
setup();
cd(root_dir)
run run_tests();
6 changes: 3 additions & 3 deletions .github/workflows/run_tests_matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ jobs:
- name: Download data
run: make tests/data/nsdcoreexampledataset.mat

- name: Run commands
- name: Run tests
uses: matlab-actions/[email protected]
with:
command:
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run tests_matlab;
run run_tests_ci;

- name: Run tests
- name: Check logs
run: |
cat test_report.log | grep 0
bash <(curl -s https://codecov.io/bash)
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test_demos.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function test_suite = test_demos %#ok<*STOUT>

try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end

initTestSuite;

end

function test_demo1()

run(fullfile(root_dir(), 'matlab', 'examples', 'example1'));

end

function test_demo2()

run(fullfile(root_dir(), 'matlab', 'examples', 'example2'));

end

function value = root_dir()

value = getenv('GITHUB_WORKSPACE');

if isempty(value)
value = fullfile(fileparts(mfilename('fullpath')), '..', '..');
end

end
2 changes: 2 additions & 0 deletions run_tests.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function run_tests()

% run tests with code coverage

tic;

cd(fileparts(mfilename('fullpath')));
Expand Down

0 comments on commit 9def9a2

Please sign in to comment.