Skip to content

Commit f8c7a05

Browse files
Add matlab-batch and --skip-activation (#40)
* skips ematlab activation if MATHWORKS env vars are set * added matlab-batch install
1 parent 46e7daa commit f8c7a05

File tree

8 files changed

+70
-9
lines changed

8 files changed

+70
-9
lines changed

src/ematlab.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ export function addToPath() {
1616
}
1717
core.addPath(path.join(root, "bin"));
1818
}
19+
20+
export function skipActivationFlag(env: NodeJS.ProcessEnv): string {
21+
return (env.MATHWORKS_TOKEN !== undefined && env.MATHWORKS_ACCOUNT !== undefined)? "--skip-activation": "";
22+
}

src/ematlab.unit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@ describe("ephemeral matlab", () => {
2929
it("rejects when root file does not exist", async () => {
3030
expect(() => ematlab.addToPath()).toThrow();
3131
});
32+
33+
it("adds --skip-activation flag if env vars are set", async () => {
34+
let env = {"MATHWORKS_ACCOUNT": "janedoe@mathworks.com", "MATHWORKS_TOKEN": "token123456"};
35+
let flag = ematlab.skipActivationFlag(env);
36+
expect(flag).toEqual("--skip-activation")
37+
})
38+
39+
it("doesn't add --skip-activation flag if env vars are not set", async () => {
40+
let env = {};
41+
let flag = ematlab.skipActivationFlag(env);
42+
expect(flag).toEqual("")
43+
})
3244
});

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright 2020 The MathWorks, Inc.
1+
// Copyright 2020-2022 The MathWorks, Inc.
22

33
import * as core from "@actions/core";
4+
import * as ematlab from "./ematlab";
45
import * as install from "./install";
56

67
/**
@@ -9,8 +10,8 @@ import * as install from "./install";
910
export async function run() {
1011
const platform = process.platform;
1112
const release = core.getInput("release");
12-
13-
return install.install(platform, release);
13+
const skipActivationFlag = ematlab.skipActivationFlag(process.env);
14+
return install.install(platform, release, skipActivationFlag);
1415
}
1516

1617
run().catch((e) => {

src/install.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as core from "@actions/core";
44
import properties from "./properties.json";
55
import * as script from "./script";
66
import * as ematlab from "./ematlab";
7+
import * as matlabBatch from "./matlabBatch";
78

89
export default install;
910

@@ -16,7 +17,7 @@ export default install;
1617
* @param platform Operating system of the runner (e.g., "win32" or "linux").
1718
* @param release Release of MATLAB to be set up (e.g., "latest" or "R2020a").
1819
*/
19-
export async function install(platform: string, release: string) {
20+
export async function install(platform: string, release: string, skipActivationFlag: string) {
2021
// Install runtime system dependencies for MATLAB on Linux
2122
if (platform === "linux") {
2223
await core.group("Preparing system for MATLAB", () =>
@@ -30,9 +31,17 @@ export async function install(platform: string, release: string) {
3031
.downloadAndRunScript(platform, properties.ephemeralInstallerUrl, [
3132
"--release",
3233
release,
34+
skipActivationFlag,
3335
])
3436
.then(ematlab.addToPath)
3537
);
3638

39+
const batchInstallDir = matlabBatch.installDir(platform);
40+
41+
await core.group("Setting up matlab-batch", () =>
42+
script
43+
.downloadAndRunScript(platform, properties.matlabBatchInstallerUrl, [batchInstallDir])
44+
.then(() => core.addPath(batchInstallDir))
45+
)
3746
return;
3847
}

src/install.unit.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 The MathWorks, Inc.
1+
// Copyright 2020-2022 The MathWorks, Inc.
22

33
import * as core from "@actions/core";
44
import * as install from "./install";
@@ -21,7 +21,8 @@ describe("install procedure", () => {
2121
// they can be held static for these unit tests
2222
const platform = "linux";
2323
const release = "latest";
24-
const doInstall = () => install.install(platform, release);
24+
const skipActivationFlag = ""
25+
const doInstall = () => install.install(platform, release, skipActivationFlag);
2526

2627
beforeEach(() => {
2728
downloadAndRunScriptMock = script.downloadAndRunScript as jest.Mock;
@@ -32,15 +33,19 @@ describe("install procedure", () => {
3233
(core.group as jest.Mock).mockImplementation(async (_, func) => {
3334
return func();
3435
});
36+
(core.addPath as jest.Mock).mockImplementation(async (_) => {
37+
return;
38+
});
3539
});
3640

3741
it("ideally works", async () => {
3842
downloadAndRunScriptMock.mockResolvedValue(undefined);
3943
addToPathMock.mockResolvedValue(undefined);
4044

4145
await expect(doInstall()).resolves.toBeUndefined();
42-
expect(downloadAndRunScriptMock).toHaveBeenCalledTimes(2);
46+
expect(downloadAndRunScriptMock).toHaveBeenCalledTimes(3);
4347
expect(addToPathMock).toHaveBeenCalledTimes(1);
48+
expect(core.addPath).toHaveBeenCalledTimes(1);
4449
});
4550

4651
it("rejects when the download fails", async () => {
@@ -76,8 +81,8 @@ describe("install procedure", () => {
7681
downloadAndRunScriptMock.mockResolvedValue(undefined);
7782
addToPathMock.mockResolvedValue(undefined);
7883

79-
await expect(install.install(os, release)).resolves.toBeUndefined();
80-
expect(downloadAndRunScriptMock).toHaveBeenCalledTimes(1);
84+
await expect(install.install(os, release, skipActivationFlag)).resolves.toBeUndefined();
85+
expect(downloadAndRunScriptMock).toHaveBeenCalledTimes(2);
8186
expect(addToPathMock).toHaveBeenCalledTimes(1);
8287
});
8388
});

src/matlabBatch.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2022 The MathWorks, Inc.
2+
3+
import path from "path";
4+
5+
export function installDir(platform: string) {
6+
let batchInstallDir : string;
7+
if (platform === "win32") {
8+
batchInstallDir = path.join("C:","Program Files", "matlab-batch");
9+
} else {
10+
batchInstallDir = path.join("/","opt","matlab-batch");
11+
}
12+
return batchInstallDir
13+
}

src/matlabBatch.unit.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2022 The MathWorks, Inc.
2+
3+
import * as matlabBatch from "./matlabBatch";
4+
5+
describe("matlab-batch", () => {
6+
const testCase = (platform: string, subdirectory: string) => {
7+
it(`sets correct install directory for ${platform}`, async () => {
8+
const installDir = matlabBatch.installDir(platform);
9+
expect(installDir).toContain(subdirectory);
10+
})
11+
};
12+
13+
testCase("win32", 'Program Files');
14+
testCase("darwin", "opt");
15+
testCase("linux", "opt");
16+
})

src/properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"matlabBatchInstallerUrl": "https://ssd.mathworks.com/supportfiles/ci/matlab-batch/v0/install.sh",
23
"matlabDepsUrl": "https://ssd.mathworks.com/supportfiles/ci/matlab-deps/v0/install.sh",
34
"ephemeralInstallerUrl": "https://ssd.mathworks.com/supportfiles/ci/ephemeral-matlab/v0/ci-install.sh"
45
}

0 commit comments

Comments
 (0)