Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
matlab-actions

GitHub Action

Setup MATLAB

v2.2.0

Setup MATLAB

matlab-actions

Setup MATLAB

Set up a specific version of MATLAB

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Setup MATLAB

uses: matlab-actions/setup-matlab@v2.2.0

Learn more about this action in matlab-actions/setup-matlab

Choose a version

Action for Setting Up MATLAB

The Setup MATLAB action enables you to run MATLAB® code and Simulink® models with a specific version of MATLAB. When you specify this action as part of your workflow, the action sets up your preferred MATLAB release (R2021a or later) on a Linux®, Windows®, or macOS runner. If you do not specify a release, the action sets up the latest release of MATLAB. As part of the setup process, the action prepends MATLAB to the PATH system environment variable.

Examples

Once you set up MATLAB on a runner, you can build and test your MATLAB project as part of your workflow. To execute code on the runner, include the Run MATLAB Build, Run MATLAB Tests, or Run MATLAB Command action in your workflow.

Run MATLAB Build on GitHub-Hosted Runner

Use a GitHub®-hosted runner to run a task and its depended-on tasks that are specified in a file named buildfile.m in the root of your repository. Because the "test" task in this example runs the tests authored using the MATLAB unit testing framework as well as Simulink Test™, you must set up Simulink and Simulink Test in addition to MATLAB. To run tasks using the MATLAB build tool, specify the Run MATLAB Build action in your workflow.

name: Run MATLAB Build on GitHub-Hosted Runner
on: [push]
jobs:
  my-job:
    name: Run MATLAB Build
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v2
        with:
          products: Simulink Simulink_Test
      - name: Run build
        uses: matlab-actions/run-build@v2
        with:
          tasks: test

Run MATLAB Tests on GitHub-Hosted Runner

Use a GitHub-hosted runner to run the tests in your MATLAB project and generate test results in JUnit-style XML format and code coverage results in Cobertura XML format. To run the tests and generate the artifacts, specify the Run MATLAB Tests action in your workflow.

name: Run MATLAB Tests on GitHub-Hosted Runner
on: [push]
jobs:
  my-job:
    name: Run MATLAB Tests and Generate Artifacts
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v2
      - name: Run tests and generate artifacts
        uses: matlab-actions/run-tests@v2
        with:
          test-results-junit: test-results/results.xml
          code-coverage-cobertura: code-coverage/coverage.xml

Run MATLAB Script on GitHub-Hosted Runner

Use a GitHub-hosted runner to run the commands in a file named myscript.m in the root of your repository. To run the script, specify the Run MATLAB Command action in your workflow.

name: Run MATLAB Script on GitHub-Hosted Runner
on: [push]
jobs:
  my-job:
    name: Run MATLAB Script
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v2
      - name: Run script
        uses: matlab-actions/run-command@v2
        with:
          command: myscript

Run MATLAB Build Across Different Platforms

The Setup MATLAB action supports the Linux, Windows, and macOS platforms. Define a matrix of job configurations to run a build using the MATLAB build tool on all the supported platforms. This workflow runs three jobs, one for each value in the variable os. For more information about matrices, see Using a matrix for your jobs.

name: Run MATLAB Build Across Different Platforms
on: [push]
jobs:
  my-job:
    name: Run MATLAB Build
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v2
      - name: Run build
        uses: matlab-actions/run-build@v2
        with:
          tasks: test

Set Up MATLAB

When you define your workflow in the .github/workflows directory of your repository, specify the Setup MATLAB action as matlab-actions/setup-matlab@v2. The action accepts optional inputs.

Input Description
release

(Optional) MATLAB release to set up. You can specify R2021a or a later release. By default, the value of release is latest, which corresponds to the latest release of MATLAB.

Example: release: R2023a
Example: release: latest

products

(Optional) Products to set up in addition to MATLAB, specified as a list of product names separated by spaces. You can specify products to set up most MathWorks® products and support packages. For example, products: Deep_Learning_Toolbox sets up Deep Learning Toolbox™ in addition to MATLAB.

The action uses MATLAB Package Manager (mpm) to set up products. For a list of supported products and their correctly formatted names, see Product Installation Options.

ℹ️ Note: If you use this input to set up transformation products, such as MATLAB Coder™ and MATLAB Compiler™, the action does not automatically license such products for you.

Example: products: Simulink
Example: products: Simulink Deep_Learning_Toolbox

cache

(Optional) Option to enable caching with GitHub® Actions, specified as false or true. By default, the value is false and the action does not store MATLAB and the specified products in a GitHub Actions cache for future use. For more information about caching with GitHub Actions, see Caching dependencies to speed up workflows.

Example: cache: true

Notes

When you use the Setup MATLAB action, you execute third-party code that is licensed under separate terms.

See Also

Contact Us

If you have any questions or suggestions, please contact MathWorks at continuous-integration@mathworks.com.