Skip to content

Commit 781bb7c

Browse files
committed
Add resolveInstallDependencies function with tests and run npm run format
1 parent 982ffa7 commit 781bb7c

22 files changed

Lines changed: 576 additions & 401 deletions

.eslintrc.js

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es2021": true
2+
env: {
3+
browser: true,
4+
es2021: true,
55
},
6-
"extends": [
7-
"eslint:recommended",
8-
"plugin:@typescript-eslint/recommended"
9-
],
10-
"overrides": [
6+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
7+
overrides: [
118
{
12-
"env": {
13-
"node": true
9+
env: {
10+
node: true,
11+
},
12+
files: [".eslintrc.{js,cjs}"],
13+
parserOptions: {
14+
sourceType: "script",
1415
},
15-
"files": [
16-
".eslintrc.{js,cjs}"
17-
],
18-
"parserOptions": {
19-
"sourceType": "script"
20-
}
2116
},
2217
{
23-
"files": [
24-
"**/*.ts"
25-
],
26-
"rules": {
27-
"prefer-const": "off"
28-
}
29-
}
18+
files: ["**/*.ts"],
19+
rules: {
20+
"prefer-const": "off",
21+
},
22+
},
3023
],
31-
"parser": "@typescript-eslint/parser",
32-
"parserOptions": {
33-
"ecmaVersion": "latest",
34-
"sourceType": "module"
24+
parser: "@typescript-eslint/parser",
25+
parserOptions: {
26+
ecmaVersion: "latest",
27+
sourceType: "module",
3528
},
36-
"plugins": [
37-
"@typescript-eslint"
38-
],
39-
"rules": {
40-
}
41-
}
29+
plugins: ["@typescript-eslint"],
30+
rules: {},
31+
};

.github/workflows/bat.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
matrix:
3030
include:
3131
- os: ubuntu-latest
32-
release: latest
32+
release: latest
3333
products: Symbolic_Math_Toolbox
3434
check-matlab: matlabVer = ver('matlab'); assert(~isempty(matlabVer));
3535
check-toolbox: symbolicVer = ver('symbolic'); assert(~isempty(symbolicVer));
@@ -77,7 +77,7 @@ jobs:
7777
release: ${{ matrix.release }}
7878
products: ${{ matrix.products }}
7979
- name: Check matlabroot output is set
80-
run: 'if [[ "${{ steps.setup_matlab.outputs.matlabroot }}" != *"MATLAB"* ]]; then exit 1; fi'
80+
run: 'if [[ "${{ steps.setup_matlab.outputs.matlabroot }}" != *"MATLAB"* ]]; then exit 1; fi'
8181
shell: bash
8282
- name: Check MATLAB version
8383
uses: matlab-actions/run-command@v2
@@ -111,4 +111,3 @@ jobs:
111111
uses: matlab-actions/run-command@v2
112112
with:
113113
command: matlabVer = ver('matlab'); assert(strcmp(matlabVer.Release,'(R2023b)'));
114-

.github/workflows/publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
git add package.json package-lock.json
3333
git commit -m "[skip ci] Bump $VERSION"
3434
git push origin HEAD:main
35-
35+
3636
# Now carry on, business as usual
3737
- name: Perform npm tasks
3838
run: npm run ci
@@ -61,15 +61,15 @@ jobs:
6161
6262
# Get the commit of the tag you just released
6363
commitHash=$(git rev-list -n 1 $longVersion)
64-
64+
6565
# Delete the old major and minor version tags locally
6666
git tag -d $majorVersion || true
6767
git tag -d $minorVersion || true
68-
68+
6969
# Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above
7070
git tag -f $majorVersion $commitHash
7171
git tag -f $minorVersion $commitHash
72-
72+
7373
# Force push the new minor version tag to overwrite the old tag remotely
7474
echo "Pushing new tags"
7575
git push -f origin $longVersion

README.md

Lines changed: 52 additions & 36 deletions
Large diffs are not rendered by default.

src/cache-restore.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

3-
import * as cache from '@actions/cache';
4-
import * as core from '@actions/core';
3+
import * as cache from "@actions/cache";
4+
import * as core from "@actions/core";
55
import * as crypto from "crypto";
6-
import { State } from './cache-state';
7-
import { Release } from './matlab';
6+
import { State } from "./cache-state";
7+
import { Release } from "./matlab";
88

9-
export async function restoreMATLAB(release: Release, platform: string, architecture: string, products: string[], matlabPath: string, supportPackagesPath?: string): Promise<boolean> {
10-
const installHash = crypto.createHash('sha256').update(products.sort().join('|')).digest('hex');
9+
export async function restoreMATLAB(
10+
release: Release,
11+
platform: string,
12+
architecture: string,
13+
products: string[],
14+
matlabPath: string,
15+
supportPackagesPath?: string,
16+
): Promise<boolean> {
17+
const installHash = crypto.createHash("sha256").update(products.sort().join("|")).digest("hex");
1118
const keyPrefix = `matlab-cache-${platform}-${architecture}-${release.version}`;
1219
const primaryKey = `${keyPrefix}-${installHash}`;
1320
const cachePaths = [matlabPath];
@@ -27,5 +34,5 @@ export async function restoreMATLAB(release: Release, platform: string, architec
2734

2835
core.saveState(State.CacheMatchedKey, cacheKey);
2936
core.info(`Cache restored from key: ${cacheKey}`);
30-
return true
37+
return true;
3138
}

src/cache-restore.unit.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ describe("cache-restore", () => {
3030
restoreCacheMock = cache.restoreCache as jest.Mock;
3131
saveStateMock = core.saveState as jest.Mock;
3232
});
33-
33+
3434
it("returns true if cache is found", async () => {
3535
restoreCacheMock.mockReturnValue("matched-cache-key");
36-
await expect(restoreMATLAB(release, platform, arch, products, location)).resolves.toBe(true);
36+
await expect(restoreMATLAB(release, platform, arch, products, location)).resolves.toBe(
37+
true,
38+
);
3739
expect(saveStateMock).toHaveBeenCalledTimes(4);
3840
});
3941

40-
4142
it("returns false if cache is not found", async () => {
42-
await expect(restoreMATLAB(release, platform, arch, products, location)).resolves.toBe(false);
43+
await expect(restoreMATLAB(release, platform, arch, products, location)).resolves.toBe(
44+
false,
45+
);
4346
expect(saveStateMock).toHaveBeenCalledTimes(3);
4447
});
4548
});

src/cache-save.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

3-
import * as core from '@actions/core';
4-
import * as cache from '@actions/cache';
5-
import {State} from './cache-state';
3+
import * as core from "@actions/core";
4+
import * as cache from "@actions/cache";
5+
import { State } from "./cache-state";
66

77
export async function cacheMATLAB() {
88
const matchedKey = core.getState(State.CacheMatchedKey);
99
const primaryKey = core.getState(State.CachePrimaryKey);
1010
const matlabPath = core.getState(State.MatlabCachePath);
1111
const supportPackagesPath = core.getState(State.SupportPackagesCachePath);
1212

13-
1413
if (primaryKey === matchedKey) {
1514
core.info(`Cache hit occurred for key: ${primaryKey}, not saving cache.`);
1615
return;

src/cache-save.unit.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

3-
import * as core from '@actions/core';
4-
import * as cache from '@actions/cache';
5-
import { cacheMATLAB } from './cache-save';
3+
import * as core from "@actions/core";
4+
import * as cache from "@actions/cache";
5+
import { cacheMATLAB } from "./cache-save";
66

77
jest.mock("@actions/cache");
88
jest.mock("@actions/core");
@@ -21,13 +21,13 @@ describe("cache-save", () => {
2121
});
2222

2323
it("saves cache if key does not equal matched key", async () => {
24-
getStateMock.mockReturnValueOnce("matched-key").mockReturnValueOnce("primary-key")
24+
getStateMock.mockReturnValueOnce("matched-key").mockReturnValueOnce("primary-key");
2525
await expect(cacheMATLAB()).resolves.toBeUndefined();
2626
expect(saveCacheMock).toHaveBeenCalledTimes(1);
2727
});
2828

2929
it("does not re-save cache if key equals matched key", async () => {
30-
getStateMock.mockReturnValueOnce("cache-key").mockReturnValueOnce("cache-key")
30+
getStateMock.mockReturnValueOnce("cache-key").mockReturnValueOnce("cache-key");
3131
await expect(cacheMATLAB()).resolves.toBeUndefined();
3232
expect(saveCacheMock).toHaveBeenCalledTimes(0);
3333
});

src/cache-state.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

33
export enum State {
4-
CachePrimaryKey = 'MATLAB_CACHE_KEY',
5-
CacheMatchedKey = 'MATLAB_CACHE_RESULT',
6-
MatlabCachePath = 'MATLAB_CACHE_PATH',
7-
SupportPackagesCachePath = 'MATLAB_SUPPORT_FILES_CACHE_PATH',
4+
CachePrimaryKey = "MATLAB_CACHE_KEY",
5+
CacheMatchedKey = "MATLAB_CACHE_RESULT",
6+
MatlabCachePath = "MATLAB_CACHE_PATH",
7+
SupportPackagesCachePath = "MATLAB_SUPPORT_FILES_CACHE_PATH",
88
}

src/index.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,6 @@
33
import * as core from "@actions/core";
44
import * as install from "./install";
55

6-
//function resolving whether to install dependencies based on the input and runner type
7-
export function resolveInstallDependencies(input: string): boolean {
8-
if (input.toLowerCase() === 'true') {
9-
core.info(`install-system-dependencies explicitly set to true`);
10-
return true;
11-
}
12-
if (input.toLowerCase() === 'false') {
13-
core.info(`install-system-dependencies explicitly set to false`);
14-
return false;
15-
}
16-
17-
// when expliciatlly not set to true or false then detecting based on the runner type
18-
if (input.toLowerCase() === 'auto' || input === '') {
19-
//using the same detection method for github hosted runner as in install.ts
20-
const runnerEnvironment = process.env["RUNNER_ENVIRONMENT"];
21-
const agentIsSelfHosted = process.env["AGENT_ISSELFHOSTED"];
22-
23-
const isGitHubHosted = runnerEnvironment === "github-hosted" && agentIsSelfHosted !== "1";
24-
25-
// shouldInstall will return true for github-hosted and false for self-hosted
26-
const shouldInstall = isGitHubHosted;
27-
28-
core.info(`Auto-detected runner type: ${isGitHubHosted ? 'GitHub-hosted' : 'self-hosted'}`);
29-
core.info(`System dependencies will ${shouldInstall ? 'be' : 'not be'} installed (auto mode)`);
30-
31-
return shouldInstall;
32-
}
33-
34-
// default set to false for invalid input type
35-
core.warning(`Invalid value for install-system-dependencies: ${input}. Defaulting to false.`);
36-
return false;
37-
}
386

397
/**
408
* Gather action inputs and then run action.
@@ -45,8 +13,7 @@ export async function run() {
4513
const release = core.getInput("release");
4614
const products = core.getMultilineInput("products");
4715
const cache = core.getBooleanInput("cache");
48-
const installDepsInput = core.getInput("install-system-dependencies") || 'auto';
49-
const installSystemDependencies = resolveInstallDependencies(installDepsInput);
16+
const installSystemDependencies = core.getInput("install-system-dependencies");
5017

5118
return install.install(platform, architecture, release, products, cache, installSystemDependencies);
5219
}

0 commit comments

Comments
 (0)