Skip to content

Test MATLAB

Test MATLAB #1641

Workflow file for this run

name: Test MATLAB
on:
# Trigger the workflow on push or pull request
#push:
pull_request: # DANGEROUS! MUST be disabled for self-hosted runners!
# Trigger the workflow by cron. The default time zone of GitHub Actions is UTC.
schedule:
- cron: '0 16 * * *'
# Trigger the workflow manually
workflow_dispatch:
inputs:
git-ref:
description: Git Ref (Optional)
required: false
# Show the git ref in the workflow name if it is invoked manually.
run-name: ${{ github.event_name == 'workflow_dispatch' && format('Manual run {0}', inputs.git-ref) || '' }}
jobs:
test:
name: Test MATLAB
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
# The matrix is the same as that of compile_mex.yml. We intend to test all supported combinations.
matrix:
os: [ubuntu-22.04, ubuntu-latest, macos-15-intel, windows-2022, windows-latest]
matlab: [R2020b, R2021a, R2021b, R2022a, R2022b, R2023a, R2023b, R2024a, R2024b, R2025a, R2025b, latest]
exclude:
# Below R2022a, MEX does not work on windows-latest due to the version of MS Visual Studio;
# R2022a/b should work according to the documentation of MathWorks and GitHub Actions, but
# they do not as of July 2025
- os: windows-2022
matlab: R2020b
- os: windows-2022
matlab: R2021a
- os: windows-2022
matlab: R2021b
- os: windows-2022
matlab: R2022a
- os: windows-2022
matlab: R2022b
- os: windows-latest
matlab: R2020b
- os: windows-latest
matlab: R2021a
- os: windows-latest
matlab: R2021b
- os: windows-latest
matlab: R2022a
- os: windows-latest
matlab: R2022b
steps:
- name: Set http.postBuffer and core.compression
# This is a workaround for random "early EOF" of checkout.
# See https://github.com/actions/checkout/issues/748, https://github.com/actions/checkout/issues/1379
if: startsWith(matrix.os, 'windows')
run: git config --global http.postBuffer 1048576000 && git config --global core.compression 0
- name: Run `sudo apt update`
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt update || true # Otherwise, free-disk-space or other actions relying on `apt` may fail
- name: Free disk space
uses: jlumbroso/free-disk-space@main
if: startsWith(matrix.os, 'ubuntu')
with:
# all of these default to true, but feel free to set to "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false # Important, or the runner may be shut down due to memory starvation.
- name: Clone Repository (Latest)
uses: actions/checkout@v6.0.2
if: github.event.inputs.git-ref == ''
with:
submodules: recursive
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
- name: Clone Repository (Custom Ref)
uses: actions/checkout@v6.0.2
if: github.event.inputs.git-ref != ''
with:
ref: ${{ github.event.inputs.git-ref }}
submodules: recursive
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
- name: Miscellaneous setup
run: bash .github/scripts/misc_setup
- name: Revise fmxapi.F90
shell: bash
run: |
cd matlab/mex_gateways/
$SEDI "s|\(.*maybe due to overflow.*$\)|\1\nwrite(*,*) 'x = ', x; write(*,*) 'x_dp = ', x_dp|" fmxapi.F90
cat fmxapi.F90
- name: Revise postprima.m
shell: bash
run: |
cd matlab/interfaces/private/
$SEDI "s/max(\[0, chist\]) > 0)/max(\[0, chist\]) > 0)\nprobinfo.raw_data\noutput\nchist/" postprima.m
cat postprima.m
- name: Decide gfortran version for MATLAB on Linux
if: startsWith(matrix.os, 'ubuntu')
run: |
GFVER=latest
# MATLAB R2021b- supports gfortran 9-
MATLAB_VERSION_NUMBER=$(echo "${{ matrix.matlab }}" | sed -e 's/R\([0-9]*\)\([ab]\)/\1/')
if [[ "${MATLAB_VERSION_NUMBER}" != "latest" && "${MATLAB_VERSION_NUMBER}" -le 2021 ]]; then
GFVER=9
fi
echo "GFVER=$GFVER"
echo "GFVER=$GFVER" >> $GITHUB_ENV
- name: Set up gfortran on Linux
if: startsWith(matrix.os, 'ubuntu')
uses: fortran-lang/setup-fortran@main
with:
compiler: gcc
version: ${{ env.GFVER }}
- name: Check gfortran version on Linux
if: startsWith(matrix.os, 'ubuntu')
run: which gcc && gcc --version && which gfortran && gfortran --version
- name: Decide the version of oneAPI to use on macOS and Windows
shell: bash
if: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'windows') }}
run: |
# Initialize ONEAPI_VERSION to "latest", causing the installer script to install the latest oneAPI.
ONEAPI_VERSION="latest"
# On Windows. the latest oneAPI supported by MATLAB R2023a/b and R2024a/b is 2023 and 2024,
# respectively. Thus we set ONEAPI_VERSION to the following. If matrix.matlab is "latest",
# then ONEAPI_VERSION will be "latest".
if [[ "${{ matrix.os }}" == windows* ]]; then
ONEAPI_VERSION=$(echo "${{ matrix.matlab }}" | sed -e 's/R\([0-9]*\)\([ab]\)/\1/')
fi
echo "ONEAPI_VERSION=$ONEAPI_VERSION" >> $GITHUB_ENV
echo "ONEAPI_VERSION:" $ONEAPI_VERSION
- name: Install Intel oneAPI on macOS
if: startsWith(matrix.os, 'macos')
run: bash .github/scripts/install_oneapi_macos.sh $ONEAPI_VERSION
- name: Install Intel oneAPI on Windows
if: startsWith(matrix.os, 'windows')
run: cmd.exe "/K" '".github\scripts\install_oneapi_windows.bat %ONEAPI_VERSION%"'
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2.6.1
with:
release: ${{ matrix.matlab }}
cache: true
products: Parallel_Computing_Toolbox
- name: Conduct the test
if: ${{ !(runner.os == 'macOS' && runner.arch == 'X64') }}
uses: matlab-actions/run-command@v2.4.0
with:
command: |
cd matlab/tests; testprima_ex();
- name: Conduct the test; treat timeout as SUCCESS (exit 0). Only for macOS on Intel.
if: ${{ runner.os == 'macOS' && runner.arch == 'X64' }}
uses: equipez/run-matlab-command@v2
with:
timelimit: 320m
command: |
cd matlab/tests; testprima_ex();