GitHub Action
Setup 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 system PATH environment variable.
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.
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, include 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
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, 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@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
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, 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@v4
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
- name: Run script
uses: matlab-actions/run-command@v2
with:
command: myscript
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 on 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
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. If you do not specify Example: |
products |
(Optional) Products to set up in addition to MATLAB, specified as a list of product names separated by spaces. You can specify The action uses MATLAB Package Manager ( ℹ️ 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: |
cache |
(Optional) Option to enable caching with GitHub® Actions, specified as Example: |
When you use the Setup MATLAB action, you execute third-party code that is licensed under separate terms.
- Action for Running MATLAB Builds
- Action for Running MATLAB Tests
- Action for Running MATLAB Commands
- Continuous Integration with MATLAB and Simulink
If you have any questions or suggestions, please contact MathWorks® at [email protected].