Skip to content

Commit 250e572

Browse files
authored
Merge pull request #124 from matlab-actions/self_hosted_support
Remove temporary geck fix, make sure chmod is not called on Windows
2 parents 7c1f1fb + b50a758 commit 250e572

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

package-lock.json

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

src/matlab.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ export async function setupBatch(platform: string, architecture: string) {
125125
let matlabBatch: string = await tc.downloadTool(matlabBatchUrl);
126126
let cachedPath = await tc.cacheFile(matlabBatch, `matlab-batch${matlabBatchExt}`, "matlab-batch", "v1");
127127
core.addPath(cachedPath);
128-
const exitCode = await exec.exec(`chmod +x ${path.join(cachedPath, 'matlab-batch'+matlabBatchExt)}`);
129-
if (exitCode !== 0) {
130-
return Promise.reject(Error("Unable to make matlab-batch executable."));
128+
if (platform !== "win32") {
129+
const exitCode = await exec.exec(`chmod +x ${path.join(cachedPath, 'matlab-batch'+matlabBatchExt)}`);
130+
if (exitCode !== 0) {
131+
return Promise.reject(Error("Unable to make matlab-batch executable."));
132+
}
131133
}
132134
return
133135
}

src/mpm.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as exec from "@actions/exec";
44
import * as tc from "@actions/tool-cache";
5+
import {rmRF} from "@actions/io";
56
import * as path from "path";
67
import * as matlab from "./matlab";
78
import properties from "./properties.json";
@@ -26,7 +27,6 @@ export async function setup(platform: string, architecture: string): Promise<str
2627
} else {
2728
mpmUrl = properties.mpmRootUrl + "maca64/mpm";
2829
}
29-
await exec.exec(`sudo launchctl limit maxfiles 65536 200000`, undefined, {ignoreReturnCode: true}); // g3185941
3030
break;
3131
default:
3232
return Promise.reject(Error(`This action is not supported on ${platform} runners using the ${architecture} architecture.`));
@@ -39,9 +39,11 @@ export async function setup(platform: string, architecture: string): Promise<str
3939
let mpmDest = path.join(runner_temp, `mpm${ext}`);
4040
let mpm: string = await tc.downloadTool(mpmUrl, mpmDest);
4141

42-
const exitCode = await exec.exec(`chmod +x "${mpm}"`);
43-
if (exitCode !== 0) {
44-
return Promise.reject(Error("Unable to set up mpm."));
42+
if (platform !== "win32") {
43+
const exitCode = await exec.exec(`chmod +x "${mpm}"`);
44+
if (exitCode !== 0) {
45+
return Promise.reject(Error("Unable to set up mpm."));
46+
}
4547
}
4648
return mpm
4749
}
@@ -65,8 +67,13 @@ export async function install(mpmPath: string, release: matlab.Release, products
6567
}
6668
mpmArguments = mpmArguments.concat("--products", ...parsedProducts);
6769

68-
const exitCode = await exec.exec(mpmPath, mpmArguments);
70+
const exitCode = await exec.exec(mpmPath, mpmArguments).catch(async e => {
71+
// Fully remove failed MATLAB installation for self-hosted runners
72+
await rmRF(destination);
73+
throw e;
74+
});
6975
if (exitCode !== 0) {
76+
await rmRF(destination);
7077
return Promise.reject(Error(`Script exited with non-zero code ${exitCode}`));
7178
}
7279
return

src/mpm.unit.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import * as exec from "@actions/exec";
44
import * as tc from "@actions/tool-cache";
5+
import * as io from "@actions/io";
56
import * as path from "path";
67
import * as mpm from "./mpm";
78
import * as script from "./script";
89

910
jest.mock("@actions/core");
1011
jest.mock("@actions/exec");
1112
jest.mock("@actions/tool-cache");
13+
jest.mock("@actions/io");
1214
jest.mock("./script");
1315

1416
afterEach(() => {
@@ -101,11 +103,13 @@ describe("setup mpm", () => {
101103

102104
describe("mpm install", () => {
103105
let execMock: jest.Mock;
106+
let rmRFMock: jest.Mock;
104107
const mpmPath = "mpm";
105108
const releaseInfo = {name: "r2022b", version: "9.13.0", update: "", isPrerelease: false};
106109
const mpmRelease = "r2022b";
107110
beforeEach(() => {
108111
execMock = exec.exec as jest.Mock;
112+
rmRFMock = io.rmRF as jest.Mock;
109113
});
110114

111115
it("works with multiline products list", async () => {
@@ -161,10 +165,19 @@ describe("mpm install", () => {
161165
expect(execMock.mock.calls[0][1]).toMatchObject(expectedMpmArgs);
162166
});
163167

164-
it("rejects on failed install", async () => {
168+
it("rejects and cleans on mpm rejection", async () => {
169+
const destination = "/opt/matlab";
170+
const products = ["MATLAB", "Compiler"];
171+
execMock.mockRejectedValue(1);
172+
await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined();
173+
expect(rmRFMock).toHaveBeenCalledWith(destination);
174+
});
175+
176+
it("rejects and cleans on failed install", async () => {
165177
const destination = "/opt/matlab";
166178
const products = ["MATLAB", "Compiler"];
167179
execMock.mockResolvedValue(1);
168180
await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined();
181+
expect(rmRFMock).toHaveBeenCalledWith(destination);
169182
});
170183
});

0 commit comments

Comments
 (0)