Skip to content

Commit a474a8d

Browse files
Format and update actions (#93)
* Add format check and update CI to use setup-matlab@v3 * update contributing * use latest release of common-utils
1 parent dff3a99 commit a474a8d

8 files changed

Lines changed: 140 additions & 90 deletions

File tree

.github/workflows/bat.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
node-version: 24
1515
- name: Perform npm tasks
1616
run: npm run ci
17-
- uses: actions/upload-artifact@v5
17+
- uses: actions/upload-artifact@v7
1818
with:
1919
name: built-action
2020
path: |
@@ -28,11 +28,11 @@ jobs:
2828
matrix:
2929
os: [ubuntu-latest, windows-latest, macos-latest, macos-14]
3030
steps:
31-
- uses: actions/download-artifact@v5
31+
- uses: actions/download-artifact@v8
3232
with:
3333
name: built-action
3434
- name: Perform 'setup-matlab'
35-
uses: matlab-actions/setup-matlab@v2
35+
uses: matlab-actions/setup-matlab@v3
3636
with:
3737
products: MATLAB_Test
3838
- name: Greet the world in style
@@ -50,7 +50,7 @@ jobs:
5050
- name: Run MATLAB statement with quotes 1
5151
uses: ./
5252
with:
53-
command: "eval(\"a = 1+2\"), assert(a == 3); eval('b = 3+4'), assert(b == 7);"
53+
command: 'eval("a = 1+2"), assert(a == 3); eval(''b = 3+4''), assert(b == 7);'
5454
- name: Run MATLAB statement with quotes 2
5555
uses: ./
5656
with:

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
git add package.json package-lock.json
3333
git commit -m "[skip ci] Bump $VERSION"
3434
git push origin HEAD:main
35-
35+
3636
# Now carry on, business as usual
3737
- name: Perform npm tasks
3838
run: npm run ci
@@ -61,15 +61,15 @@ jobs:
6161
6262
# Get the commit of the tag you just released
6363
commitHash=$(git rev-list -n 1 $longVersion)
64-
64+
6565
# Delete the old major and minor version tags locally
6666
git tag -d $majorVersion || true
6767
git tag -d $minorVersion || true
68-
68+
6969
# Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above
7070
git tag -f $majorVersion $commitHash
7171
git tag -f $minorVersion $commitHash
72-
72+
7373
# Force push the new minor version tag to overwrite the old tag remotely
7474
echo "Pushing new tags"
7575
git push -f origin $longVersion

README.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,64 @@
11
# Action for Running MATLAB Commands
22

33
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+
45
- 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.
56
- 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.
67

78
## Examples
9+
810
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.
911

1012
### Run MATLAB Script
13+
1114
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.
1215

1316
```yaml
1417
name: Run MATLAB Script
1518
on: [push]
1619
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
2730
```
2831
2932
### Run MATLAB Statements
33+
3034
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.
3135
3236
```yaml
3337
name: Run MATLAB Statements
3438
on: [push]
3539
jobs:
36-
my-job:
37-
name: Run MATLAB Statements
38-
runs-on: ubuntu-latest
39-
steps:
40-
- name: Check out repository
41-
uses: actions/checkout@v6
42-
- name: Set up MATLAB
43-
uses: matlab-actions/setup-matlab@v3
44-
- name: Run statements
45-
uses: matlab-actions/run-command@v3
46-
with:
47-
command: results = runtests, assertSuccess(results);
40+
my-job:
41+
name: Run MATLAB Statements
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Check out repository
45+
uses: actions/checkout@v6
46+
- name: Set up MATLAB
47+
uses: matlab-actions/setup-matlab@v3
48+
- name: Run statements
49+
uses: matlab-actions/run-command@v3
50+
with:
51+
command: results = runtests, assertSuccess(results);
4852
```
4953
50-
5154
### Use MATLAB Batch Licensing Token
52-
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.
5357
5458
To use a MATLAB batch licensing token:
5559
5660
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.
5862

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

@@ -79,29 +83,33 @@ jobs:
7983
```
8084

8185
## Run MATLAB Command
86+
8287
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.
8388

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>
89+
| Input | Description |
90+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91+
| `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> |
8893

8994
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:
9095

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

9398
## 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.
97103

98104
## See Also
105+
99106
- [Action for Running MATLAB Builds](https://github.com/matlab-actions/run-build/)
100107
- [Action for Running MATLAB Tests](https://github.com/matlab-actions/run-tests/)
101108
- [Action for Setting Up MATLAB](https://github.com/matlab-actions/setup-matlab/)
102109
- [Continuous Integration with MATLAB and Simulink](https://www.mathworks.com/solutions/continuous-integration.html)
103110

104111
## Feedback and Support
112+
105113
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).
106114

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

devel/contributing.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,32 @@ Familiarize yourself with the best practices for [releasing and maintaining GitH
1313
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.
1414

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

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
},
1515
],
1616
},
17-
extensionsToTreatAsEsm: ['.ts'],
17+
extensionsToTreatAsEsm: [".ts"],
1818
transformIgnorePatterns: ["node_modules/(?!(@actions)/)"],
1919
moduleNameMapper: {
2020
"^(\\.{1,2}/.*)\\.js$": "$1",

0 commit comments

Comments
 (0)