Skip to content

Commit 5680241

Browse files
committed
Enhance MATLAB installation handling to ignore 'already installed' messages and update test cases accordingly
1 parent e9be3d3 commit 5680241

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

.github/workflows/bat.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ jobs:
9292
with:
9393
release: ${{ matrix.release }}
9494
products: ${{ matrix.products }}
95+
- name: Install additional products
96+
uses: ./
97+
with:
98+
release: ${{ matrix.release }}
99+
products: Image_Processing_Toolbox
100+
- name: Check additional product was installed
101+
uses: matlab-actions/run-command@v2
102+
with:
103+
command: assert(any(strcmp({ver().Name},'Image Processing Toolbox')))
95104
- name: Call setup MATLAB again with different release # should not error as in issue 130
96105
uses: ./
97106
with:

src/mpm.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,32 @@ export async function install(mpmPath: string, release: matlab.Release, products
7878
}
7979
mpmArguments = mpmArguments.concat("--products", ...parsedProducts);
8080

81-
const exitCode = await exec.exec(mpmPath, mpmArguments).catch(async e => {
82-
// Fully remove failed MATLAB installation for self-hosted runners
81+
let output = "";
82+
const options = {
83+
listeners: {
84+
stdout: (data: Buffer) => {
85+
const text = data.toString();
86+
output += text;
87+
process.stdout.write(text);
88+
},
89+
stderr: (data: Buffer) => {
90+
const text = data.toString();
91+
output += text;
92+
process.stderr.write(text);
93+
},
94+
},
95+
ignoreReturnCode: true,
96+
};
97+
98+
const exitCode = await exec.exec(mpmPath, mpmArguments, options).catch(async e => {
8399
await rmRF(destination);
84100
throw e;
85101
});
86-
if (exitCode !== 0) {
102+
103+
if (exitCode !== 0 && !output.toLowerCase().includes("already installed")) {
87104
await rmRF(destination);
88105
return Promise.reject(Error(`Script exited with non-zero code ${exitCode}`));
89106
}
90-
return
107+
108+
return;
91109
}

src/mpm.unit.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,20 @@ describe("mpm install", () => {
180180
await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined();
181181
expect(rmRFMock).toHaveBeenCalledWith(destination);
182182
});
183+
184+
it("does not reject when mpm exits non-zero but reports already installed", async () => {
185+
const destination = "/opt/matlab";
186+
const products = ["MATLAB", "Compiler"];
187+
188+
// Simulate mpm writing the "already installed" message to stdout and returning non-zero
189+
execMock.mockImplementation((cmd: string, args: string[], options?: exec.ExecOptions) => {
190+
if (options && options.listeners && typeof options.listeners.stdout === 'function') {
191+
options.listeners.stdout(Buffer.from("All specified products are already installed."));
192+
}
193+
return Promise.resolve(1);
194+
});
195+
196+
await expect(mpm.install(mpmPath, releaseInfo, products, destination)).resolves.toBeUndefined();
197+
expect(rmRFMock).not.toHaveBeenCalled();
198+
});
183199
});

0 commit comments

Comments
 (0)