Skip to content

Set up your GitHub Actions workflow with a specific version of MATLAB.

License

Notifications You must be signed in to change notification settings

matlab-actions/setup-matlab

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Action for Setting Up MATLAB on GitHub-Hosted Runner

Before you run MATLAB® code and Simulink® models on a GitHub®-hosted runner, first use the Setup MATLAB action. The action sets up the specified MATLAB release on a Linux® virtual machine. If you do not specify a release, the action sets up the latest release of MATLAB.

The Setup MATLAB action is not supported on self-hosted runners. Currently, it is available only for public projects. It does not set up transformation products, such as MATLAB Coder™ and MATLAB Compiler™.

Usage Examples

Once you set up MATLAB, 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 actions in your workflow.

Run MATLAB Build on GitHub-Hosted Runner

Set up a GitHub-hosted runner to run a specific task and its depended-on tasks that are specified in a file named buildfile.m in the root of your repository. To run tasks using the MATLAB build tool, include the Run MATLAB Build action in your workflow. This action is supported in MATLAB R2022b and later.

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@v3
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v1
      - name: Run build
        uses: matlab-actions/run-build@v1
        with:
          tasks: test

Run MATLAB Tests on GitHub-Hosted Runner

Set up a GitHub-hosted runner to run the tests in your MATLAB project and generate a JUnit test results report and a Cobertura code coverage report. To run the tests and generate the artifacts, include 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@v3
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v1
      - name: Run tests and generate artifacts
        uses: matlab-actions/run-tests@v1
        with:
          test-results-junit: test-results/results.xml
          code-coverage-cobertura: code-coverage/coverage.xml

Run MATLAB Script on GitHub-Hosted Runner

Set up a GitHub-hosted runner to run the commands in a file named myscript.m in the root of your repository. To run the script, include 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@v3
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v1
      - name: Run script
        uses: matlab-actions/run-command@v1
        with:
          command: myscript

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@v1. The action accepts an optional input.

Input Description
release (Optional) MATLAB release to set up. You can specify R2020a or a later release. If you do not specify release, the action sets up the latest release of MATLAB.
Example: R2022a

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 [email protected].