Skip to content

Commit 5c7228d

Browse files
New run matlab command binary (#25)
* use new RMC binary
1 parent 5d721a1 commit 5c7228d

File tree

7 files changed

+101
-42
lines changed

7 files changed

+101
-42
lines changed

package-lock.json

Lines changed: 20 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/setupdeps.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
#!/bin/bash
22

3-
RMC_URL='https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v0/run-matlab-command.zip'
3+
RMC_BASE_URL='https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v1'
4+
SUPPORTED_OS=('win64' 'maci64' 'glnxa64')
45

56
# Create dist directory if it doesn't already exist
67
DISTDIR="$(pwd)/dist/bin"
78
mkdir -p $DISTDIR
89

910
# Download and extract in a temporary directory
10-
WORKINGDIR=$(mktemp -d -t rmc_build)
11+
WORKINGDIR=$(mktemp -d -t rmc_build.XXXXXX)
1112
cd $WORKINGDIR
12-
wget -O bin.zip $RMC_URL
13-
unzip -qod bin bin.zip
1413

15-
mv -f bin/* $DISTDIR/
14+
wget -O "$WORKINGDIR/license.txt" "$RMC_BASE_URL/license.txt"
15+
wget -O "$WORKINGDIR/thirdpartylicenses.txt" "$RMC_BASE_URL/thirdpartylicenses.txt"
1616

17+
for os in ${SUPPORTED_OS[@]}
18+
do
19+
if [[ $os == 'win64' ]] ; then
20+
bin_ext='.exe'
21+
else
22+
bin_ext=''
23+
fi
24+
mkdir -p "$WORKINGDIR/$os"
25+
wget -O "$WORKINGDIR/$os/run-matlab-command$bin_ext" "$RMC_BASE_URL/$os/run-matlab-command$bin_ext"
26+
done
27+
28+
mv -f ./* "$DISTDIR/"
1729
rm -rf $WORKINGDIR

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export { matlab };
1111
*/
1212
async function run() {
1313
const platform = process.platform;
14+
const architecture = process.arch;
1415
const workspaceDir = process.cwd();
1516
const command = core.getInput("command");
1617

@@ -21,7 +22,7 @@ async function run() {
2122
});
2223

2324
await core.group("Run command", async () => {
24-
await matlab.runCommand(helperScript, platform, exec.exec);
25+
await matlab.runCommand(helperScript, platform, architecture, exec.exec);
2526
});
2627
}
2728

src/matlab.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ export async function generateScript(workspaceDir: string, command: string): Pro
4747
*
4848
* @param hs HelperScript pointing to the script containing the command
4949
* @param platform Operating system of the runner (e.g., "win32" or "linux")
50+
* @param architecture Architecture of the runner (e.g., "x64")
5051
* @param fn ExecFn that will execute a command on the runner
5152
*/
52-
export async function runCommand(hs: HelperScript, platform: string, fn: ExecFn): Promise<void> {
53-
const rmcPath = getRunMATLABCommandScriptPath(platform);
53+
export async function runCommand(hs: HelperScript, platform: string, architecture: string, fn: ExecFn): Promise<void> {
54+
const rmcPath = getRunMATLABCommandScriptPath(platform, architecture);
5455
await fs.chmod(rmcPath, 0o777);
5556

5657
const rmcArg = script.cdAndCall(hs.dir, hs.command);
@@ -65,9 +66,31 @@ export async function runCommand(hs: HelperScript, platform: string, fn: ExecFn)
6566
* Get the path of the script containing RunMATLABCommand for the host OS.
6667
*
6768
* @param platform Operating system of the runner (e.g., "win32" or "linux")
68-
*/
69-
export function getRunMATLABCommandScriptPath(platform: string): string {
70-
const ext = platform === "win32" ? "bat" : "sh";
71-
const rmcPath = path.join(__dirname, "bin", `run_matlab_command.${ext}`);
69+
* @param architecture Architecture of the runner (e.g., "x64")
70+
*/
71+
export function getRunMATLABCommandScriptPath(platform: string, architecture: string): string {
72+
if (architecture != "x64") {
73+
throw new Error(`This action is not supported on ${platform} runners using the ${architecture} architecture.`);
74+
}
75+
let ext;
76+
let platformDir;
77+
switch (platform) {
78+
case "win32":
79+
ext = ".exe";
80+
platformDir = "win64";
81+
break;
82+
case "darwin":
83+
ext = "";
84+
platformDir = "maci64";
85+
break;
86+
case "linux":
87+
ext = "";
88+
platformDir = "glnxa64";
89+
break;
90+
default:
91+
throw new Error(`This action is not supported on ${platform} runners using the ${architecture} architecture.`);
92+
}
93+
const rmcPath = path.join(__dirname, "bin", platformDir, `run-matlab-command${ext}`);
7294
return rmcPath;
95+
7396
}

src/matlab.unit.test.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("script generation", () => {
5858
describe("run command", () => {
5959
const helperScript = { dir: "/home/sweet/home", command: "disp('hello, world');" };
6060
const platform = "win32";
61+
const architecture = "x64"
6162

6263
it("ideally works", async () => {
6364
const chmod = jest.spyOn(fs, "chmod");
@@ -66,7 +67,7 @@ describe("run command", () => {
6667
chmod.mockResolvedValue(undefined);
6768
execFn.mockResolvedValue(0);
6869

69-
const actual = matlab.runCommand(helperScript, platform, execFn);
70+
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
7071
await expect(actual).resolves.toBeUndefined();
7172
});
7273

@@ -76,7 +77,7 @@ describe("run command", () => {
7677

7778
chmod.mockRejectedValue(null);
7879

79-
const actual = matlab.runCommand(helperScript, platform, execFn);
80+
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
8081
await expect(actual).rejects.toBeDefined();
8182
expect(chmod).toHaveBeenCalledTimes(1);
8283
expect(execFn).not.toHaveBeenCalled();
@@ -89,7 +90,7 @@ describe("run command", () => {
8990
chmod.mockResolvedValue(undefined);
9091
execFn.mockRejectedValue(null);
9192

92-
const actual = matlab.runCommand(helperScript, platform, execFn);
93+
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
9394
await expect(actual).rejects.toBeDefined();
9495
expect(chmod).toHaveBeenCalledTimes(1);
9596
expect(execFn).toHaveBeenCalledTimes(1);
@@ -102,23 +103,44 @@ describe("run command", () => {
102103
chmod.mockResolvedValue(undefined);
103104
execFn.mockResolvedValue(1);
104105

105-
const actual = matlab.runCommand(helperScript, platform, execFn);
106+
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
106107
await expect(actual).rejects.toBeDefined();
107108
expect(chmod).toHaveBeenCalledTimes(1);
108109
expect(execFn).toHaveBeenCalledTimes(1);
109110
});
110111
});
111112

112113
describe("ci helper path", () => {
113-
const testCase = (platform: string, ext: string) => {
114+
const platform = "linux"
115+
const architecture = "x64"
116+
const testExtension = (platform: string, ext: string) => {
114117
it(`considers the appropriate script on ${platform}`, () => {
115-
const actualPath = matlab.getRunMATLABCommandScriptPath(platform);
118+
const actualPath = matlab.getRunMATLABCommandScriptPath(platform, architecture);
116119
const actualExt = path.extname(actualPath);
117120
expect(actualExt).toMatch(ext);
118121
});
119122
};
120123

121-
testCase("win32", "bat");
122-
testCase("darwin", "sh");
123-
testCase("linux", "sh");
124+
const testDirectory = (platform: string, subdirectory: string) => {
125+
it(`considers the appropriate script on ${platform}`, () => {
126+
const actualPath = matlab.getRunMATLABCommandScriptPath(platform, architecture);
127+
expect(actualPath).toContain(subdirectory);
128+
});
129+
};
130+
131+
testExtension("win32", "exe");
132+
testExtension("darwin", "");
133+
testExtension("linux", "");
134+
135+
testDirectory("win32", "win64");
136+
testDirectory("darwin", "maci64");
137+
testDirectory("linux", "glnxa64");
138+
139+
it("errors on unsupported platform", () => {
140+
expect(() => matlab.getRunMATLABCommandScriptPath('sunos',architecture)).toThrow();
141+
})
142+
143+
it("errors on unsupported architecture", () => {
144+
expect(() => matlab.getRunMATLABCommandScriptPath(platform, 'x86')).toThrow();
145+
})
124146
});

src/script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @returns MATLAB command.
99
*/
1010
export function cdAndCall(dir: string, command: string): string {
11-
return `cd('${pathToCharVec(dir)}'); ${command}`;
11+
return `cd('${pathToCharVec(dir)}');${command}`;
1212
}
1313

1414
/**

src/script.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("call generation", () => {
77
// I know what your thinking
88
const testDir = String.raw`C:\Users\you\You're Documents`;
99
const testCommand = "disp('hello world')";
10-
const expectedString = String.raw`cd('C:\Users\you\You''re Documents'); ${testCommand}`;
10+
const expectedString = String.raw`cd('C:\Users\you\You''re Documents');${testCommand}`;
1111

1212
expect(script.cdAndCall(testDir, testCommand)).toMatch(expectedString);
1313
});

0 commit comments

Comments
 (0)