Skip to content

Run tests

Run tests #910

Workflow file for this run

# Run and publish MATLAB tests with coverage across multiple MATLAB versions
name: Run tests
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
push:
branches:
- main
paths-ignore:
- "*.md"
- "*.codespellrc"
- ".github/**"
- "!.github/workflows/run_tests.yml"
- "docs/**"
workflow_dispatch:
inputs:
test_all_matlab_releases:
description: 'Run test matrix with all matlab releases (true) or only latest MATLAB release (false)'
required: true
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
set_matrix:
name: Set test matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
latest_matlab_version: ${{ steps.set-matrix.outputs.latest_matlab_version }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set matrix
id: set-matrix
run: |
# Load the matrix configuration and extract latest version
latest_matlab_version=$(yq '.[-1].matlab-version' .github/workflows/configurations/matlab_release_matrix_strategy.yml)
# Determine whether to use full matrix of MATLAB releases or just
# latest MATLAB release
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.test_all_matlab_releases }}" == "true" ]]; then
use_full_matrix=true
echo "Workflow dispatch with full matrix for all MATLAB releases"
elif [[ "${{ github.event_name }}" != "workflow_dispatch" && "${{ github.event_name }}" != "pull_request" ]]; then
use_full_matrix=true
echo "Push event - using full matrix"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" != "true" ]]; then
use_full_matrix=true
echo "Non-draft PR - using full matrix"
else
use_full_matrix=false
echo "Using latest MATLAB release only"
fi
# Create the appropriate matrix based on the decision
if [[ "$use_full_matrix" == "true" ]]; then
# Create matrix with all MATLAB releases
matrix=$(yq -o=json '{"include": .}' .github/workflows/configurations/matlab_release_matrix_strategy.yml | tr -d '\n')
else
# Create matrix with only the latest MATLAB release
matrix=$(yq -o=json '.[-1:] | {"include": .}' .github/workflows/configurations/matlab_release_matrix_strategy.yml | tr -d '\n')
fi
# Assign `matrix` and `latest_matlab_version` as outputs of this job
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo "latest_matlab_version=$latest_matlab_version" >> $GITHUB_OUTPUT
run_tests:
name: Run MATLAB tests (${{ matrix.matlab-version }})
needs: set_matrix
runs-on: ubuntu-latest
env:
USE_CACHE: ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == true }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set_matrix.outputs.matrix) }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Configure python env
run: |
python -m pip install -U pip
pip install -r +tests/requirements.txt
python -m pip list
echo "HDF5_PLUGIN_PATH=$(python -c "import hdf5plugin; print(hdf5plugin.PLUGINS_PATH)")" >> "$GITHUB_ENV"
echo $( python -m pip show nwbinspector | grep ^Location: | awk '{print $2}' )
- name: Install MATLAB
uses: matlab-actions/setup-matlab@v2
if: always()
with:
release: ${{ matrix.matlab-version }}
cache: ${{ env.USE_CACHE }}
- name: Run tests
uses: matlab-actions/run-command@v2
with:
command: |
setenv("SKIP_PYNWB_COMPATIBILITY_TEST_FOR_TUTORIALS", ...
num2str(${{ matrix.skip-pynwb-compatibilty-test-for-tutorial }}))
pyenv("ExecutionMode", "OutOfProcess");
results = assertSuccess(nwbtest('ReportOutputFolder', '.'));
assert(~isempty(results), 'No tests ran');
- name: Upload JUnit results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.matlab-version }}
path: testResults.xml
retention-days: 1
- name: Upload coverage results
if: always() && matrix.matlab-version == needs.set_matrix.outputs.latest_matlab_version
uses: actions/upload-artifact@v4
with:
name: test-coverage-${{ matrix.matlab-version }}
path: ./coverage.xml
publish_junit:
name: Publish JUnit test results
runs-on: ubuntu-latest
if: always()
needs: [run_tests]
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Retrieve result files
uses: actions/download-artifact@v4
with:
pattern: test-results-*
merge-multiple: true
- name: Publish test results
uses: mikepenz/action-junit-report@v4
with:
report_paths: 'testResults*.xml'
publish_coverage:
name: Publish Cobertura test coverage
runs-on: ubuntu-latest
needs: [run_tests, set_matrix]
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Retrieve code coverage files
uses: actions/download-artifact@v4
with:
name: test-coverage-${{ needs.set_matrix.outputs.latest_matlab_version }}
- name: Publish on coverage results on Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage*.xml
name: codecov-matnwb
verbose: true