Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/bat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
node-version: 24
- name: Perform npm tasks
run: npm run ci
- uses: actions/upload-artifact@v5
- uses: actions/upload-artifact@v7
with:
name: built-action
path: |
Expand All @@ -28,11 +28,11 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-14]
steps:
- uses: actions/download-artifact@v5
- uses: actions/download-artifact@v8
with:
name: built-action
- name: Perform 'setup-matlab'
uses: matlab-actions/setup-matlab@v2
uses: matlab-actions/setup-matlab@v3
with:
products: MATLAB_Test
- name: Greet the world in style
Expand All @@ -50,7 +50,7 @@ jobs:
- name: Run MATLAB statement with quotes 1
uses: ./
with:
command: "eval(\"a = 1+2\"), assert(a == 3); eval('b = 3+4'), assert(b == 7);"
command: 'eval("a = 1+2"), assert(a == 3); eval(''b = 3+4''), assert(b == 7);'
- name: Run MATLAB statement with quotes 2
uses: ./
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
git add package.json package-lock.json
git commit -m "[skip ci] Bump $VERSION"
git push origin HEAD:main

# Now carry on, business as usual
- name: Perform npm tasks
run: npm run ci
Expand Down Expand Up @@ -61,15 +61,15 @@ jobs:

# Get the commit of the tag you just released
commitHash=$(git rev-list -n 1 $longVersion)

# Delete the old major and minor version tags locally
git tag -d $majorVersion || true
git tag -d $minorVersion || true

# Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above
git tag -f $majorVersion $commitHash
git tag -f $minorVersion $commitHash

# Force push the new minor version tag to overwrite the old tag remotely
echo "Pushing new tags"
git push -f origin $longVersion
Expand Down
72 changes: 40 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
# Action for Running MATLAB Commands

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:

- 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.
- 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.

## Examples

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.

### Run MATLAB Script

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.

```yaml
name: Run MATLAB Script
on: [push]
jobs:
my-job:
name: Run MATLAB Script
runs-on: self-hosted
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Run script
uses: matlab-actions/run-command@v3
with:
command: myscript
my-job:
name: Run MATLAB Script
runs-on: self-hosted
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Run script
uses: matlab-actions/run-command@v3
with:
command: myscript
```

### Run MATLAB Statements

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.

```yaml
name: Run MATLAB Statements
on: [push]
jobs:
my-job:
name: Run MATLAB Statements
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
- name: Run statements
uses: matlab-actions/run-command@v3
with:
command: results = runtests, assertSuccess(results);
my-job:
name: Run MATLAB Statements
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
- name: Run statements
uses: matlab-actions/run-command@v3
with:
command: results = runtests, assertSuccess(results);
```


### Use MATLAB Batch Licensing Token
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.

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.

To use a MATLAB batch licensing token:

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).
2. Map the secret to an environment variable named `MLM_LICENSE_TOKEN` in your workflow.
2. Map the secret to an environment variable named `MLM_LICENSE_TOKEN` in your workflow.

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.

Expand All @@ -79,29 +83,33 @@ jobs:
```

## Run MATLAB Command

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.

Input | Description
------------------------- | ---------------
`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>
`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>
| Input | Description |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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> |
| `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> |

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:

`command: addpath("myfolder"), myscript`

## Notes
* 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.
* 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.
* When you use the **Run MATLAB Command** action, you execute third-party code that is licensed under separate terms.

- 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.
- 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.
- When you use the **Run MATLAB Command** action, you execute third-party code that is licensed under separate terms.

## See Also

- [Action for Running MATLAB Builds](https://github.com/matlab-actions/run-build/)
- [Action for Running MATLAB Tests](https://github.com/matlab-actions/run-tests/)
- [Action for Setting Up MATLAB](https://github.com/matlab-actions/setup-matlab/)
- [Continuous Integration with MATLAB and Simulink](https://www.mathworks.com/solutions/continuous-integration.html)

## Feedback and Support

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).

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.
Expand Down
29 changes: 29 additions & 0 deletions devel/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,32 @@ Familiarize yourself with the best practices for [releasing and maintaining GitH
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.

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.

## Adding a Pre-Commit Hook

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:

_bash (Linux/macOS)_

```sh
echo '#!/bin/sh' > .git/hooks/pre-commit
echo 'npm run ci' >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
```

_Command Prompt (Windows)_

```cmd
echo #!/bin/sh > .git\hooks\pre-commit
echo npm run ci >> .git\hooks\pre-commit
```

_PowerShell (Windows)_

```pwsh
Set-Content .git\hooks\pre-commit '#!/bin/sh'
Add-Content .git\hooks\pre-commit 'npm run ci'
```

> **Note:**
> Git hooks are not version-controlled, so you need to set up this hook for each fresh clone of the repository.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
},
],
},
extensionsToTreatAsEsm: ['.ts'],
extensionsToTreatAsEsm: [".ts"],
transformIgnorePatterns: ["node_modules/(?!(@actions)/)"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
Expand Down
Loading
Loading