Skip to content

Commit e387fe0

Browse files
authored
Merge pull request #38 from matlab-actions/startupoptions
Add ability to pass MATLAB startup options
2 parents d0c1180 + 425b221 commit e387fe0

File tree

7 files changed

+1304
-1188
lines changed

7 files changed

+1304
-1188
lines changed

.github/workflows/bat.yml

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ jobs:
5555
uses: ./
5656
with:
5757
command: exp = getenv('GITHUB_WORKSPACE'), act = pwd, assert(strcmp(act, exp), strjoin({act exp}, '\n'));
58+
59+
- name: Run MATLAB statement with arguments
60+
uses: ./
61+
with:
62+
command: disp("Hello world!!")
63+
startup-options: -nojvm -nodesktop -logfile mylog.log
64+
65+
- name: Validate that previous command ran with arguments
66+
uses: ./
67+
with:
68+
command: assert(isfile("mylog.log"));
5869

5970
- run: echo 'onetyone = 11' > startup.m
6071
shell: bash

action.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The MathWorks, Inc.
1+
# Copyright 2020-2023 The MathWorks, Inc.
22

33
name: Run MATLAB Command
44
description: >-
@@ -8,6 +8,11 @@ inputs:
88
description: >-
99
Script, function, or statement to execute
1010
required: true
11+
startup-options:
12+
description: >-
13+
Startup options for MATLAB
14+
required: false
15+
default: ""
1116
runs:
1217
using: node16
1318
main: dist/index.js

package-lock.json

+1,260-1,181
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@types/node": "^15.12.4",
2929
"@types/uuid": "^8.3.0",
3030
"@vercel/ncc": "^0.28.6",
31-
"jest": "^27.0.5",
31+
"jest": "^27.5.1",
3232
"jest-circus": "^27.0.5",
3333
"prettier": "2.3.1",
3434
"ts-jest": "^27.0.3",

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async function run() {
1414
const architecture = process.arch;
1515
const workspaceDir = process.cwd();
1616
const command = core.getInput("command");
17+
const startupOpts = core.getInput("startup-options").split(" ");
1718

1819
const helperScript = await core.group("Generate script", async () => {
1920
const helperScript = await matlab.generateScript(workspaceDir, command);
@@ -22,7 +23,7 @@ async function run() {
2223
});
2324

2425
await core.group("Run command", async () => {
25-
await matlab.runCommand(helperScript, platform, architecture, exec.exec);
26+
await matlab.runCommand(helperScript, platform, architecture, exec.exec, startupOpts);
2627
});
2728
}
2829

src/matlab.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 The MathWorks, Inc.
1+
// Copyright 2020-2023 The MathWorks, Inc.
22

33
import { promises as fs } from "fs";
44
import * as os from "os";
@@ -50,13 +50,19 @@ export async function generateScript(workspaceDir: string, command: string): Pro
5050
* @param architecture Architecture of the runner (e.g., "x64")
5151
* @param fn ExecFn that will execute a command on the runner
5252
*/
53-
export async function runCommand(hs: HelperScript, platform: string, architecture: string, fn: ExecFn): Promise<void> {
53+
export async function runCommand(hs: HelperScript, platform: string, architecture: string, fn: ExecFn, args?: string[]): Promise<void> {
5454
const rmcPath = getRunMATLABCommandScriptPath(platform, architecture);
5555
await fs.chmod(rmcPath, 0o777);
5656

5757
const rmcArg = script.cdAndCall(hs.dir, hs.command);
5858

59-
const exitCode = await fn(rmcPath, [rmcArg]);
59+
let execArgs = [rmcArg];
60+
61+
if (args) {
62+
execArgs = execArgs.concat(args);
63+
}
64+
65+
const exitCode = await fn(rmcPath, execArgs);
6066
if (exitCode !== 0) {
6167
return Promise.reject(Error(`Exited with non-zero code ${exitCode}`));
6268
}

src/matlab.unit.test.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 The MathWorks, Inc.
1+
// Copyright 2020-2023 The MathWorks, Inc.
22

33
import { promises as fs } from "fs";
44
import * as path from "path";
@@ -71,6 +71,20 @@ describe("run command", () => {
7171
await expect(actual).resolves.toBeUndefined();
7272
});
7373

74+
it("ideally works with arguments", async () => {
75+
const chmod = jest.spyOn(fs, "chmod");
76+
const execFn = jest.fn();
77+
78+
chmod.mockResolvedValue(undefined);
79+
execFn.mockResolvedValue(0);
80+
81+
const actual = matlab.runCommand(helperScript, platform, architecture, execFn, ["-nojvm", "-logfile", "file"]);
82+
await expect(actual).resolves.toBeUndefined();
83+
expect(execFn.mock.calls[0][1][1]).toBe("-nojvm");
84+
expect(execFn.mock.calls[0][1][2]).toBe("-logfile");
85+
expect(execFn.mock.calls[0][1][3]).toBe("file");
86+
});
87+
7488
it("fails when chmod fails", async () => {
7589
const chmod = jest.spyOn(fs, "chmod");
7690
const execFn = jest.fn();

0 commit comments

Comments
 (0)