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

[INFRA] MATLAB test automation #43

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
af934b4
Add common tools for MATLAB and Python testing
Remi-Gau Apr 7, 2022
20e6fd9
add smoke tests matlab
Remi-Gau Apr 7, 2022
918091b
add matlab test automation
Remi-Gau Apr 7, 2022
aee01dc
add matlab test demo automation
Remi-Gau Apr 7, 2022
faba452
add expected data and an assert to system test
Remi-Gau Apr 7, 2022
b886a8b
rename test file
Remi-Gau Apr 7, 2022
04508a5
add documentation
Remi-Gau Apr 7, 2022
b9df9f2
lint
Remi-Gau Apr 7, 2022
0eff103
remove unneeded upload coverage artefact from CI workflow
Remi-Gau Apr 7, 2022
3ab086b
run tests matlab demos with CRON job on 1rt and 15th of every month
Remi-Gau Apr 7, 2022
ef3920e
add assert on value of R2
Remi-Gau Apr 7, 2022
8284581
add doc in CI yml and scripts
Remi-Gau Apr 7, 2022
61cfe71
fix typo
Remi-Gau Apr 7, 2022
bd5d8fa
add matlab tests badge to README
Remi-Gau Apr 7, 2022
956da88
add matlab demo badge to README
Remi-Gau Apr 7, 2022
9def9a2
run demos with MOxUnit in CI so that demo2 is run even if demo1 fails
Remi-Gau Apr 8, 2022
c4530c3
force demos to fail to make sure this is picked by CI
Remi-Gau Apr 8, 2022
10161f0
add a check log to try to show workflow as failed
Remi-Gau Apr 8, 2022
f569dd6
remove forced errors in demo and reset to run demos bimonthly
Remi-Gau Apr 8, 2022
26389af
add doc on running tests and demos in CI
Remi-Gau Apr 8, 2022
56807a6
miss_hit lint CI code
Remi-Gau Apr 8, 2022
07da5c3
add miss hit and linting documentation
Remi-Gau Apr 8, 2022
1908552
add pre-commit doc
Remi-Gau Apr 8, 2022
70d205e
update contributors doc
Remi-Gau Apr 8, 2022
731ac95
add doc on generating and chekcing test data
Remi-Gau Apr 8, 2022
a312579
update repo map
Remi-Gau Apr 8, 2022
b35bec6
switch to using png image in doc
Remi-Gau Apr 8, 2022
ca40488
try testing different os and matlab version
Remi-Gau Apr 8, 2022
882cf8e
only run tests on ubuntu latest with matlab 2020a
Remi-Gau Apr 8, 2022
4ae81fd
Update .github/workflows/run_tests_matlab.yaml
Remi-Gau Apr 12, 2022
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
23 changes: 23 additions & 0 deletions .github/workflows/miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# miss_hit configuration
# for matlab linting and static analysis
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)

project_root

octave: false

line_length: 100

suppress_rule: "copyright_notice"

tab_width: 2

# snake_case
regex_script_name: "[a-zA-Z]+(_[a-zA-Z0-9]*)*"
regex_function_name: "[a-zA-Z]+(_[a-zA-Z0-9]*)*"

metric "cnest": limit 4
metric "file_length": limit 500
metric "cyc": limit 10
metric "parameters": limit 5
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
54 changes: 54 additions & 0 deletions .github/workflows/run_demos_matlab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: MATLAB demos

# Uses the cron schedule for github actions
#
# will run at 00H00 run on the 1 and 15 of every month
#
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#scheduled-events
#
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC): * means all
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT): * means all
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
#
# - cron "0 0 1,15 * *"

on:
schedule:
- cron: "0 0 1,15 * *"

jobs:
demos:
runs-on: ubuntu-20.04

steps:
- name: Install MATLAB
uses: matlab-actions/setup-matlab@v1.0.1
with:
release: R2020a

- name: Shallow clone GLMsingle
uses: actions/checkout@v3
with:
submodules: true
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/run-command@v1.0.1
with:
command:
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run run_demos_ci;

- name: Check logs
run: |
cat test_report.log | grep 0
11 changes: 11 additions & 0 deletions .github/workflows/run_tests_ci.m
Original file line number Diff line number Diff line change
@@ -0,0 +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();

cd(root_dir);
run run_tests();
68 changes: 68 additions & 0 deletions .github/workflows/run_tests_matlab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: MATLAB tests

# Installs
# - MATLAB github action
# - MOXunit
# - MOcov
# Get test data
# cd into .github/workflows
# run .github/workflows/tests_matlab.m
# If tests pass, uploads coverage to codecov

on:
push:
# TODO only run on master branch on push
branches: ["main"]
pull_request:
branches: ["*"]

jobs:
tests:

strategy:
matrix:
os: [ubuntu-latest] # "macos-latest" or "windows-latest" don't work (yet?)
matlab-version: ["R2020a"] # add more versions if needed: "R2021a"
fail-fast: false # Don't cancel all jobs if one fails
Comment on lines +22 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we ever wanted to test on different OS or matlab version this could simply be changed in there.

Currently Matlab github actions only support linux.


runs-on: ${{ matrix.os }}

steps:
- name: Install MATLAB ${{ matrix.matlab-version }}
uses: matlab-actions/setup-matlab@v1.0.1
with:
release: ${{ matrix.matlab-version }}

- name: Shallow clone GLMsingle
uses: actions/checkout@v3
with:
submodules: true
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: Download data
run: make tests/data/nsdcoreexampledataset.mat

- name: Run tests
uses: matlab-actions/run-command@v1.0.1
with:
command:
cd(fullfile(getenv('GITHUB_WORKSPACE'), '.github', 'workflows'));
run run_tests_ci;

- name: Check logs
run: |
cat test_report.log | grep 0
bash <(curl -s https://codecov.io/bash)

- name: Code coverage
uses: codecov/codecov-action@v1
with:
file: coverage.xml # optional
flags: matlab # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
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
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#
# vscode files
.vscode/

# test related
tests/outputs/

# data folder
# data folders
data/

# example output folders
Expand All @@ -13,6 +15,9 @@ figures/
report.html
##*.png

# pyenv
Pipfile

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -54,6 +59,7 @@ pip-delete-this-directory.txt
htmlcov/
.tox/
.coverage
coverage_html
.coverage.*
.cache
nosetests.xml
Expand Down Expand Up @@ -153,4 +159,3 @@ codegen/

# Octave session info
octave-workspace

7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-yaml
Loading