Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove temporary geck fix, make sure chmod is not called on Windows #124

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions package-lock.json

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

8 changes: 5 additions & 3 deletions src/matlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 12 additions & 5 deletions src/mpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,7 +27,6 @@ export async function setup(platform: string, architecture: string): Promise<str
} else {
mpmUrl = properties.mpmRootUrl + "maca64/mpm";
}
await exec.exec(`sudo launchctl limit maxfiles 65536 200000`, undefined, {ignoreReturnCode: true}); // g3185941
break;
default:
return Promise.reject(Error(`This action is not supported on ${platform} runners using the ${architecture} architecture.`));
Expand All @@ -39,9 +39,11 @@ export async function setup(platform: string, architecture: string): Promise<str
let mpmDest = path.join(runner_temp, `mpm${ext}`);
let mpm: string = await tc.downloadTool(mpmUrl, mpmDest);

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

const exitCode = await exec.exec(mpmPath, mpmArguments);
const exitCode = await exec.exec(mpmPath, mpmArguments).catch(async e => {
// 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
Expand Down
15 changes: 14 additions & 1 deletion src/mpm.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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";

jest.mock("@actions/core");
jest.mock("@actions/exec");
jest.mock("@actions/tool-cache");
jest.mock("@actions/io");
jest.mock("./script");

afterEach(() => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
});
});