You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-32Lines changed: 40 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,60 +1,64 @@
1
1
# Action for Running MATLAB Commands
2
2
3
3
The [Run MATLAB Command](#run-matlab-command) action enables you to execute MATLAB® scripts, functions, and statements on a [GitHub®-hosted](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners) or [self-hosted](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners) runner:
4
+
4
5
- To use a GitHub-hosted runner, include the [Setup MATLAB](https://github.com/matlab-actions/setup-matlab/) action in your workflow to set up your preferred MATLAB release (R2021a or later) on the runner.
5
6
- To use a self-hosted runner, set up a computer with MATLAB on its path and register the runner with GitHub Actions. (On self-hosted UNIX® runners, you can also use the **Setup MATLAB** action instead of having MATLAB already installed.) The runner uses the topmost MATLAB release on the system path to execute your workflow.
6
7
7
8
## Examples
9
+
8
10
Use the **Run MATLAB Command** action to run MATLAB scripts, functions, and statements. You can use this action to flexibly customize your test run or add a step in MATLAB to your workflow.
9
11
10
12
### Run MATLAB Script
13
+
11
14
On a self-hosted runner that has MATLAB installed, run a script named `myscript.m` in the root of your repository. To run the script, specify the **Run MATLAB Command** action in your workflow.
12
15
13
16
```yaml
14
17
name: Run MATLAB Script
15
18
on: [push]
16
19
jobs:
17
-
my-job:
18
-
name: Run MATLAB Script
19
-
runs-on: self-hosted
20
-
steps:
21
-
- name: Check out repository
22
-
uses: actions/checkout@v6
23
-
- name: Run script
24
-
uses: matlab-actions/run-command@v3
25
-
with:
26
-
command: myscript
20
+
my-job:
21
+
name: Run MATLAB Script
22
+
runs-on: self-hosted
23
+
steps:
24
+
- name: Check out repository
25
+
uses: actions/checkout@v6
26
+
- name: Run script
27
+
uses: matlab-actions/run-command@v3
28
+
with:
29
+
command: myscript
27
30
```
28
31
29
32
### Run MATLAB Statements
33
+
30
34
Using the latest release of MATLAB on a GitHub-hosted runner, run your MATLAB statements. To set up the latest release of MATLAB on the runner, specify the [Setup MATLAB](https://github.com/matlab-actions/setup-matlab/) action in your workflow. To run the statements, specify the **Run MATLAB Command** action.
When you define a workflow using the [Setup MATLAB](https://github.com/matlab-actions/setup-matlab/) action, you need a [MATLAB batch licensing token](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/alternates/non-interactive/MATLAB-BATCH.md#matlab-batch-licensing-token) if your project is private or if your workflow uses transformation products, such as MATLAB Coder™ and MATLAB Compiler™. Batch licensing tokens are strings that enable MATLAB to start in noninteractive environments. You can request a token by submitting the [MATLAB Batch Licensing Pilot](https://www.mathworks.com/support/batch-tokens.html) form.
55
+
56
+
When you define a workflow using the [Setup MATLAB](https://github.com/matlab-actions/setup-matlab/) action, you need a [MATLAB batch licensing token](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/alternates/non-interactive/MATLAB-BATCH.md#matlab-batch-licensing-token) if your project is private or if your workflow uses transformation products, such as MATLAB Coder™ and MATLAB Compiler™. Batch licensing tokens are strings that enable MATLAB to start in noninteractive environments. You can request a token by submitting the [MATLAB Batch Licensing Pilot](https://www.mathworks.com/support/batch-tokens.html) form.
53
57
54
58
To use a MATLAB batch licensing token:
55
59
56
60
1. Set the token as a secret. For more information about secrets, see [Using secrets in GitHub Actions](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
57
-
2. Map the secret to an environment variable named `MLM_LICENSE_TOKEN` in your workflow.
61
+
2. Map the secret to an environment variable named `MLM_LICENSE_TOKEN` in your workflow.
58
62
59
63
For example, use the latest release of MATLAB on a GitHub-hosted runner to run a script named `myscript.m` in your private project. To set up the latest release of MATLAB on the runner, specify the **Setup MATLAB** action in your workflow. To run the script, specify the **Run MATLAB Command** action. In this example, `MyToken` is the name of the secret that holds the batch licensing token.
60
64
@@ -79,29 +83,33 @@ jobs:
79
83
```
80
84
81
85
## Run MATLAB Command
86
+
82
87
When you define your workflow in the `.github/workflows` directory of your repository, specify the **Run MATLAB Command** action as `matlab-actions/run-command@v3`. The action requires an input and also accepts an optional input.
83
88
84
-
Input | Description
85
-
------------------------- | ---------------
86
-
`command` | <p>(Required) Script, function, or statement to execute. If the value of `command` is the name of a MATLAB script or function, do not specify the file extension. If you specify more than one script, function, or statement, use a comma or semicolon to separate them.</p><p>MATLAB exits with exit code 0 if the specified script, function, or statement executes successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, which causes the action to fail. To fail the action in certain conditions, use the [`assert`](https://www.mathworks.com/help/matlab/ref/assert.html) or [`error`](https://www.mathworks.com/help/matlab/ref/error.html) function.</p><p>**Example:** `command: myscript`<br/>**Example:** `command: results = runtests, assertSuccess(results);`</p>
87
-
`startup-options` | <p>(Optional) MATLAB startup options, specified as a list of options separated by spaces. For more information about startup options, see [Commonly Used Startup Options](https://www.mathworks.com/help/matlab/matlab_env/commonly-used-startup-options.html).</p><p>Using this input to specify the `-batch` or `-r` option is not supported.</p><p>**Example:** `startup-options: -nojvm`<br/>**Example:** `startup-options: -nojvm -logfile output.log`</p>
| `command` | <p>(Required) Script, function, or statement to execute. If the value of `command` is the name of a MATLAB script or function, do not specify the file extension. If you specify more than one script, function, or statement, use a comma or semicolon to separate them.</p><p>MATLAB exits with exit code 0 if the specified script, function, or statement executes successfully without error. Otherwise, MATLAB terminates with a nonzero exit code, which causes the action to fail. To fail the action in certain conditions, use the [`assert`](https://www.mathworks.com/help/matlab/ref/assert.html) or [`error`](https://www.mathworks.com/help/matlab/ref/error.html) function.</p><p>**Example:** `command: myscript`<br/>**Example:** `command: results = runtests, assertSuccess(results);`</p> |
92
+
| `startup-options` | <p>(Optional) MATLAB startup options, specified as a list of options separated by spaces. For more information about startup options, see [Commonly Used Startup Options](https://www.mathworks.com/help/matlab/matlab_env/commonly-used-startup-options.html).</p><p>Using this input to specify the `-batch` or `-r` option is not supported.</p><p>**Example:** `startup-options: -nojvm`<br/>**Example:** `startup-options: -nojvm -logfile output.log`</p> |
88
93
89
94
When you use this action, all of the required files must be on the MATLAB search path. If your script or function is not in the root of your repository, you can use the [`addpath`](https://www.mathworks.com/help/matlab/ref/addpath.html), [`cd`](https://www.mathworks.com/help/matlab/ref/cd.html), or [`run`](https://www.mathworks.com/help/matlab/ref/run.html) function to put it on the path. For example, to run `myscript.m` in a folder named `myfolder` located in the root of the repository, you can specify `command` like this:
90
95
91
96
`command: addpath("myfolder"), myscript`
92
97
93
98
## Notes
94
-
* By default, when you use the **Run MATLAB Command** action, the root of your repository serves as the MATLAB startup folder. To run your MATLAB commands using a different folder, specify the `-sd` startup option or the `cd` command in the action.
95
-
* In MATLAB R2019a and later, the **Run MATLAB Command** action uses the `-batch` option to start MATLAB noninteractively. MATLAB settings do not persist across different MATLAB sessions launched with the `-batch` option. To run code that requires the same settings, use a single action.
96
-
* When you use the **Run MATLAB Command** action, you execute third-party code that is licensed under separate terms.
99
+
100
+
- By default, when you use the **Run MATLAB Command** action, the root of your repository serves as the MATLAB startup folder. To run your MATLAB commands using a different folder, specify the `-sd` startup option or the `cd` command in the action.
101
+
- In MATLAB R2019a and later, the **Run MATLAB Command** action uses the `-batch` option to start MATLAB noninteractively. MATLAB settings do not persist across different MATLAB sessions launched with the `-batch` option. To run code that requires the same settings, use a single action.
102
+
- When you use the **Run MATLAB Command** action, you execute third-party code that is licensed under separate terms.
97
103
98
104
## See Also
105
+
99
106
- [Action for Running MATLAB Builds](https://github.com/matlab-actions/run-build/)
100
107
- [Action for Running MATLAB Tests](https://github.com/matlab-actions/run-tests/)
101
108
- [Action for Setting Up MATLAB](https://github.com/matlab-actions/setup-matlab/)
102
109
- [Continuous Integration with MATLAB and Simulink](https://www.mathworks.com/solutions/continuous-integration.html)
103
110
104
111
## Feedback and Support
112
+
105
113
If you encounter a product licensing issue, consider requesting a MATLAB batch licensing token to use in your workflow. For more information, see [Use MATLAB Batch Licensing Token](#use-matlab-batch-licensing-token).
106
114
107
115
If you have an enhancement request or other feedback about this action, create an issue on the [Issues](https://github.com/matlab-actions/run-command/issues) page.
Copy file name to clipboardExpand all lines: devel/contributing.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,3 +13,32 @@ Familiarize yourself with the best practices for [releasing and maintaining GitH
13
13
Changes should be made on a new branch. The new branch should be merged to the main branch via a pull request. Ensure that all of the CI pipeline checks and tests have passed for your changes.
14
14
15
15
After the pull request has been approved and merged to main, follow the Github process for [creating a new release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository). The release must follow semantic versioning (ex: vX.Y.Z). This will kick off a new pipeline execution, and the action will automatically be published to the GitHub Actions Marketplace if the pipeline finishes successfully. Check the [GitHub Marketplace](https://github.com/marketplace/actions/setup-matlab) and check the major version in the repository (ex: v1 for v1.0.0) to ensure that the new semantically versioned tag is available.
16
+
17
+
## Adding a Pre-Commit Hook
18
+
19
+
You can run all CI checks before each commit by adding a pre-commit hook. To do so, navigate to the repository root folder and run the following commands:
20
+
21
+
_bash (Linux/macOS)_
22
+
23
+
```sh
24
+
echo'#!/bin/sh'> .git/hooks/pre-commit
25
+
echo'npm run ci'>> .git/hooks/pre-commit
26
+
chmod +x .git/hooks/pre-commit
27
+
```
28
+
29
+
_Command Prompt (Windows)_
30
+
31
+
```cmd
32
+
echo #!/bin/sh > .git\hooks\pre-commit
33
+
echo npm run ci >> .git\hooks\pre-commit
34
+
```
35
+
36
+
_PowerShell (Windows)_
37
+
38
+
```pwsh
39
+
Set-Content .git\hooks\pre-commit '#!/bin/sh'
40
+
Add-Content .git\hooks\pre-commit 'npm run ci'
41
+
```
42
+
43
+
> **Note:**
44
+
> Git hooks are not version-controlled, so you need to set up this hook for each fresh clone of the repository.
0 commit comments