diff --git a/package-lock.json b/package-lock.json index 1bcb1a6..29c078b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4298,12 +4298,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { diff --git a/src/matlab.ts b/src/matlab.ts index 27f6d25..747e01f 100644 --- a/src/matlab.ts +++ b/src/matlab.ts @@ -125,9 +125,11 @@ export async function setupBatch(platform: string, architecture: string) { let matlabBatch: string = await tc.downloadTool(matlabBatchUrl); let cachedPath = await tc.cacheFile(matlabBatch, `matlab-batch${matlabBatchExt}`, "matlab-batch", "v1"); core.addPath(cachedPath); - const exitCode = await exec.exec(`chmod +x ${path.join(cachedPath, 'matlab-batch'+matlabBatchExt)}`); - if (exitCode !== 0) { - return Promise.reject(Error("Unable to make matlab-batch executable.")); + if (platform !== "win32") { + const exitCode = await exec.exec(`chmod +x ${path.join(cachedPath, 'matlab-batch'+matlabBatchExt)}`); + if (exitCode !== 0) { + return Promise.reject(Error("Unable to make matlab-batch executable.")); + } } return } diff --git a/src/mpm.ts b/src/mpm.ts index ca52bbf..5d3efec 100644 --- a/src/mpm.ts +++ b/src/mpm.ts @@ -2,6 +2,7 @@ import * as exec from "@actions/exec"; import * as tc from "@actions/tool-cache"; +import {rmRF} from "@actions/io"; import * as path from "path"; import * as matlab from "./matlab"; import properties from "./properties.json"; @@ -26,7 +27,6 @@ export async function setup(platform: string, architecture: string): Promise { + // Fully remove failed MATLAB installation for self-hosted runners + await rmRF(destination); + throw e; + }); if (exitCode !== 0) { + await rmRF(destination); return Promise.reject(Error(`Script exited with non-zero code ${exitCode}`)); } return diff --git a/src/mpm.unit.test.ts b/src/mpm.unit.test.ts index 3644b0e..37d2cf5 100644 --- a/src/mpm.unit.test.ts +++ b/src/mpm.unit.test.ts @@ -2,6 +2,7 @@ import * as exec from "@actions/exec"; import * as tc from "@actions/tool-cache"; +import * as io from "@actions/io"; import * as path from "path"; import * as mpm from "./mpm"; import * as script from "./script"; @@ -9,6 +10,7 @@ import * as script from "./script"; jest.mock("@actions/core"); jest.mock("@actions/exec"); jest.mock("@actions/tool-cache"); +jest.mock("@actions/io"); jest.mock("./script"); afterEach(() => { @@ -101,11 +103,13 @@ describe("setup mpm", () => { describe("mpm install", () => { let execMock: jest.Mock; + let rmRFMock: jest.Mock; const mpmPath = "mpm"; const releaseInfo = {name: "r2022b", version: "9.13.0", update: "", isPrerelease: false}; const mpmRelease = "r2022b"; beforeEach(() => { execMock = exec.exec as jest.Mock; + rmRFMock = io.rmRF as jest.Mock; }); it("works with multiline products list", async () => { @@ -161,10 +165,19 @@ describe("mpm install", () => { expect(execMock.mock.calls[0][1]).toMatchObject(expectedMpmArgs); }); - it("rejects on failed install", async () => { + it("rejects and cleans on mpm rejection", async () => { + const destination = "/opt/matlab"; + const products = ["MATLAB", "Compiler"]; + execMock.mockRejectedValue(1); + await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined(); + expect(rmRFMock).toHaveBeenCalledWith(destination); + }); + + it("rejects and cleans on failed install", async () => { const destination = "/opt/matlab"; const products = ["MATLAB", "Compiler"]; execMock.mockResolvedValue(1); await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined(); + expect(rmRFMock).toHaveBeenCalledWith(destination); }); });