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
39 changes: 20 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions scripts/setupdeps.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#!/bin/bash

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

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

# Download and extract in a temporary directory
WORKINGDIR=$(mktemp -d -t rmc_build)
WORKINGDIR=$(mktemp -d -t rmc_build.XXXXXX)
cd $WORKINGDIR
wget -O bin.zip $RMC_URL
unzip -qod bin bin.zip

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

for os in ${SUPPORTED_OS[@]}
do
if [[ $os == 'win64' ]] ; then
bin_ext='.exe'
else
bin_ext=''
fi
mkdir -p "$WORKINGDIR/$os"
wget -O "$WORKINGDIR/$os/run-matlab-command$bin_ext" "$RMC_BASE_URL/$os/run-matlab-command$bin_ext"
done

mv -f ./* "$DISTDIR/"
rm -rf $WORKINGDIR
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { matlab };
*/
async function run() {
const platform = process.platform;
const architecture = process.arch;
const workspaceDir = process.cwd();
const command = core.getInput("command");

Expand All @@ -21,7 +22,7 @@ async function run() {
});

await core.group("Run command", async () => {
await matlab.runCommand(helperScript, platform, exec.exec);
await matlab.runCommand(helperScript, platform, architecture, exec.exec);
});
}

Expand Down
35 changes: 29 additions & 6 deletions src/matlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export async function generateScript(workspaceDir: string, command: string): Pro
*
* @param hs HelperScript pointing to the script containing the command
* @param platform Operating system of the runner (e.g., "win32" or "linux")
* @param architecture Architecture of the runner (e.g., "x64")
* @param fn ExecFn that will execute a command on the runner
*/
export async function runCommand(hs: HelperScript, platform: string, fn: ExecFn): Promise<void> {
const rmcPath = getRunMATLABCommandScriptPath(platform);
export async function runCommand(hs: HelperScript, platform: string, architecture: string, fn: ExecFn): Promise<void> {
const rmcPath = getRunMATLABCommandScriptPath(platform, architecture);
await fs.chmod(rmcPath, 0o777);

const rmcArg = script.cdAndCall(hs.dir, hs.command);
Expand All @@ -65,9 +66,31 @@ export async function runCommand(hs: HelperScript, platform: string, fn: ExecFn)
* Get the path of the script containing RunMATLABCommand for the host OS.
*
* @param platform Operating system of the runner (e.g., "win32" or "linux")
*/
export function getRunMATLABCommandScriptPath(platform: string): string {
const ext = platform === "win32" ? "bat" : "sh";
const rmcPath = path.join(__dirname, "bin", `run_matlab_command.${ext}`);
* @param architecture Architecture of the runner (e.g., "x64")
*/
export function getRunMATLABCommandScriptPath(platform: string, architecture: string): string {
if (architecture != "x64") {
throw new Error(`This action is not supported on ${platform} runners using the ${architecture} architecture.`);
}
let ext;
let platformDir;
switch (platform) {
case "win32":
ext = ".exe";
platformDir = "win64";
break;
case "darwin":
ext = "";
platformDir = "maci64";
break;
case "linux":
ext = "";
platformDir = "glnxa64";
break;
default:
throw new Error(`This action is not supported on ${platform} runners using the ${architecture} architecture.`);
}
const rmcPath = path.join(__dirname, "bin", platformDir, `run-matlab-command${ext}`);
return rmcPath;

}
40 changes: 31 additions & 9 deletions src/matlab.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("script generation", () => {
describe("run command", () => {
const helperScript = { dir: "/home/sweet/home", command: "disp('hello, world');" };
const platform = "win32";
const architecture = "x64"

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

const actual = matlab.runCommand(helperScript, platform, execFn);
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
await expect(actual).resolves.toBeUndefined();
});

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

chmod.mockRejectedValue(null);

const actual = matlab.runCommand(helperScript, platform, execFn);
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
await expect(actual).rejects.toBeDefined();
expect(chmod).toHaveBeenCalledTimes(1);
expect(execFn).not.toHaveBeenCalled();
Expand All @@ -89,7 +90,7 @@ describe("run command", () => {
chmod.mockResolvedValue(undefined);
execFn.mockRejectedValue(null);

const actual = matlab.runCommand(helperScript, platform, execFn);
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
await expect(actual).rejects.toBeDefined();
expect(chmod).toHaveBeenCalledTimes(1);
expect(execFn).toHaveBeenCalledTimes(1);
Expand All @@ -102,23 +103,44 @@ describe("run command", () => {
chmod.mockResolvedValue(undefined);
execFn.mockResolvedValue(1);

const actual = matlab.runCommand(helperScript, platform, execFn);
const actual = matlab.runCommand(helperScript, platform, architecture, execFn);
await expect(actual).rejects.toBeDefined();
expect(chmod).toHaveBeenCalledTimes(1);
expect(execFn).toHaveBeenCalledTimes(1);
});
});

describe("ci helper path", () => {
const testCase = (platform: string, ext: string) => {
const platform = "linux"
const architecture = "x64"
const testExtension = (platform: string, ext: string) => {
it(`considers the appropriate script on ${platform}`, () => {
const actualPath = matlab.getRunMATLABCommandScriptPath(platform);
const actualPath = matlab.getRunMATLABCommandScriptPath(platform, architecture);
const actualExt = path.extname(actualPath);
expect(actualExt).toMatch(ext);
});
};

testCase("win32", "bat");
testCase("darwin", "sh");
testCase("linux", "sh");
const testDirectory = (platform: string, subdirectory: string) => {
it(`considers the appropriate script on ${platform}`, () => {
const actualPath = matlab.getRunMATLABCommandScriptPath(platform, architecture);
expect(actualPath).toContain(subdirectory);
});
};

testExtension("win32", "exe");
testExtension("darwin", "");
testExtension("linux", "");

testDirectory("win32", "win64");
testDirectory("darwin", "maci64");
testDirectory("linux", "glnxa64");

it("errors on unsupported platform", () => {
expect(() => matlab.getRunMATLABCommandScriptPath('sunos',architecture)).toThrow();
})

it("errors on unsupported architecture", () => {
expect(() => matlab.getRunMATLABCommandScriptPath(platform, 'x86')).toThrow();
})
});
2 changes: 1 addition & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @returns MATLAB command.
*/
export function cdAndCall(dir: string, command: string): string {
return `cd('${pathToCharVec(dir)}'); ${command}`;
return `cd('${pathToCharVec(dir)}');${command}`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/script.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("call generation", () => {
// I know what your thinking
const testDir = String.raw`C:\Users\you\You're Documents`;
const testCommand = "disp('hello world')";
const expectedString = String.raw`cd('C:\Users\you\You''re Documents'); ${testCommand}`;
const expectedString = String.raw`cd('C:\Users\you\You''re Documents');${testCommand}`;

expect(script.cdAndCall(testDir, testCommand)).toMatch(expectedString);
});
Expand Down