Skip to content

Commit 245ed85

Browse files
Format and update actions (#193)
* add format check and bump action versions to v3 in bat.yml * update contributing
1 parent cd7fcc5 commit 245ed85

11 files changed

Lines changed: 84 additions & 39 deletions

File tree

.github/workflows/bat.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ jobs:
8080
run: 'if [[ "${{ steps.setup_matlab.outputs.matlabroot }}" != *"MATLAB"* ]]; then exit 1; fi'
8181
shell: bash
8282
- name: Check MATLAB version
83-
uses: matlab-actions/run-command@v2
83+
uses: matlab-actions/run-command@v3
8484
with:
8585
command: "${{ matrix.check-matlab }}"
8686
- name: Check toolbox version
87-
uses: matlab-actions/run-command@v2
87+
uses: matlab-actions/run-command@v3
8888
with:
8989
command: "${{ matrix.check-toolbox }}"
9090
- name: Check NoOp on 2nd install
@@ -100,14 +100,14 @@ jobs:
100100
products: Image_Processing_Toolbox
101101
- name: Check additional product was installed
102102
if: matrix.os != 'windows-latest'
103-
uses: matlab-actions/run-command@v2
103+
uses: matlab-actions/run-command@v3
104104
with:
105105
command: assert(any(strcmp({ver().Name},'Image Processing Toolbox')))
106106
- name: Call setup MATLAB again with different release # should not error as in issue 130
107107
uses: ./
108108
with:
109109
release: R2023b
110110
- name: Check MATLAB version
111-
uses: matlab-actions/run-command@v2
111+
uses: matlab-actions/run-command@v3
112112
with:
113113
command: matlabVer = ver('matlab'); assert(strcmp(matlabVer.Release,'(R2023b)'));

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ When you define your workflow in the `.github/workflows` directory of your repos
142142
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
143143
| `release` | <p>(Optional) MATLAB release to set up. You can specify R2021a or a later release. By default, the value of `release` is `latest`, which corresponds to the latest release of MATLAB.</p><p><ul><li>To set up the latest update of a release, specify only the release name, for example, `R2024a`.</li><li>To set up a specific update release, specify the release name with an update number suffix, for example, `R2024aU4`.</li><li>To set up a release without updates, specify the release name with an update 0 or general release suffix, for example, `R2024aU0` or `R2024aGR`.</li></ul></p><p>**Example**: `release: R2024a`<br/>**Example**: `release: latest`<br/>**Example**: `release: R2024aU4`</p> |
144144
| `products` | <p>(Optional) Products to set up in addition to MATLAB, specified as a list of product names separated by spaces. You can specify `products` to set up most MathWorks products and support packages. The action uses [MATLAB Package Manager](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/MPM.md) (`mpm`) to set up products.</p><p>For a list of supported products, open the input file for your preferred release from the [`mpm-input-files`](https://github.com/mathworks-ref-arch/matlab-dockerfile/tree/main/mpm-input-files) folder on GitHub. Specify products using the format shown in the input file, excluding the `#product.` prefix. For example, to set up Deep Learning Toolbox&trade; in addition to MATLAB, specify `products: Deep_Learning_Toolbox`.</p><p>For an example of how to use the `products` input, see [Run Tests in Parallel](#run-tests-in-parallel).</p><p>**Example**: `products: Simulink`<br/>**Example:** `products: Simulink Deep_Learning_Toolbox`</p> |
145-
| `install-system-dependencies` | <p>(Optional) Option to install the dependencies required to run MATLAB and other MathWorks products, specified as one of these values:<ul><li>`auto` (default) — If the runner is GitHub-hosted, install the dependencies. Otherwise, do not install any dependencies.</li><li>`true` — Install the dependencies on the runner, regardless of its type.</li><li>`false` — Do not install any dependencies on the runner, regardless of its type.</li></ul></p><p>**Note**: On a self-hosted runner, if you specify this input as `true`, the runner must be configured with passwordless `sudo` access.</p><p>**Example**: `install-system-dependencies: true`</p> |
145+
| `install-system-dependencies` | <p>(Optional) Option to install the dependencies required to run MATLAB and other MathWorks products, specified as one of these values:<ul><li>`auto` (default) — If the runner is GitHub-hosted, install the dependencies. Otherwise, do not install any dependencies.</li><li>`true` — Install the dependencies on the runner, regardless of its type.</li><li>`false` — Do not install any dependencies on the runner, regardless of its type.</li></ul></p><p>**Note**: On a self-hosted runner, if you specify this input as `true`, the runner must be configured with passwordless `sudo` access.</p><p>**Example**: `install-system-dependencies: true`</p> |
146146
| `cache` | <p>(Optional) Option to enable caching with GitHub Actions, specified as `false` or `true`. By default, the value is `false` and the action does not store MATLAB and the specified products in a GitHub Actions cache for future use. For more information about caching with GitHub Actions, see [Caching dependencies to speed up workflows](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows).</p><p>**Example**: `cache: true`</p> |
147147

148-
149148
#### Required Software on Self-Hosted Runners
150149

151150
Setting up MATLAB and other MathWorks products on a self-hosted UNIX runner requires certain dependencies to be installed on the runner. You can install these dependencies by using the `install-system-dependencies` action input.

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inputs:
1818
description: >-
1919
Option to install system dependencies for MATLAB, specified as auto, true, or false
2020
required: false
21-
default: auto
21+
default: auto
2222
cache:
2323
description: >-
2424
Option to enable caching with GitHub Actions, specified as false or true

devel/contributing.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,32 @@ Familiarize yourself with the best practices for [releasing and maintaining GitH
1313
Changes should be made on a new branch. The new branch should be merged to the main branch via a pull request. Ensure that all of the CI pipeline checks and tests have passed for your changes.
1414

1515
After the pull request has been approved and merged to main, follow the Github process for [creating a new release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository). The release must follow semantic versioning (ex: vX.Y.Z). This will kick off a new pipeline execution, and the action will automatically be published to the GitHub Actions Marketplace if the pipeline finishes successfully. Check the [GitHub Marketplace](https://github.com/marketplace/actions/setup-matlab) and check the major version in the repository (ex: v1 for v1.0.0) to ensure that the new semantically versioned tag is available.
16+
17+
## Adding a Pre-Commit Hook
18+
19+
You can run all CI checks before each commit by adding a pre-commit hook. To do so, navigate to the repository root folder and run the following commands:
20+
21+
_bash (Linux/macOS)_
22+
23+
```sh
24+
echo '#!/bin/sh' > .git/hooks/pre-commit
25+
echo 'npm run ci' >> .git/hooks/pre-commit
26+
chmod +x .git/hooks/pre-commit
27+
```
28+
29+
_Command Prompt (Windows)_
30+
31+
```cmd
32+
echo #!/bin/sh > .git\hooks\pre-commit
33+
echo npm run ci >> .git\hooks\pre-commit
34+
```
35+
36+
_PowerShell (Windows)_
37+
38+
```pwsh
39+
Set-Content .git\hooks\pre-commit '#!/bin/sh'
40+
Add-Content .git\hooks\pre-commit 'npm run ci'
41+
```
42+
43+
> **Note:**
44+
> Git hooks are not version-controlled, so you need to set up this hook for each fresh clone of the repository.

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
},
1515
],
1616
},
17-
extensionsToTreatAsEsm: ['.ts'],
17+
extensionsToTreatAsEsm: [".ts"],
1818
transformIgnorePatterns: ["node_modules/(?!(@actions)/)"],
1919
moduleNameMapper: {
2020
"^(\\.{1,2}/.*)\\.js$": "$1",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build": "tsc",
1414
"package": "ncc build src/index.ts -o dist/setup --minify && ncc build src/post.ts -o dist/cache-save --minify",
1515
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
16-
"all": "npm run lint && npm test && npm run build && npm run package",
16+
"all": "npm run format-check && npm run lint && npm test && npm run build && npm run package",
1717
"ci": "npm run clean && npm ci && npm run all"
1818
},
1919
"files": [

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import * as core from "@actions/core";
44
import * as install from "./install.js";
55

6-
76
/**
87
* Gather action inputs and then run action.
98
*/
@@ -14,8 +13,15 @@ export async function run() {
1413
const products = core.getMultilineInput("products");
1514
const cache = core.getBooleanInput("cache");
1615
const installSystemDependencies = core.getInput("install-system-dependencies");
17-
18-
return install.install(platform, architecture, release, products, cache, installSystemDependencies);
16+
17+
return install.install(
18+
platform,
19+
architecture,
20+
release,
21+
products,
22+
cache,
23+
installSystemDependencies,
24+
);
1925
}
2026

2127
run().catch((e) => {

src/install.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,34 @@ import * as path from "path";
77
import * as cache from "./cache-restore.js";
88
import { State } from "./install-state.js";
99

10-
1110
export function resolveInstallDependencies(input: string): boolean {
12-
const normalized = (input ?? '').trim().toLowerCase();
11+
const normalized = (input ?? "").trim().toLowerCase();
1312

14-
if (normalized === 'true') {
13+
if (normalized === "true") {
1514
return true;
1615
}
1716

18-
if (normalized === 'false'){
17+
if (normalized === "false") {
1918
return false;
2019
}
2120

22-
if (normalized === 'auto') {
21+
if (normalized === "auto") {
2322
// detect runner type and provide value accordingly
2423
const runnerEnvironment = process.env["RUNNER_ENVIRONMENT"];
2524
const agentIsSelfHosted = process.env["AGENT_ISSELFHOSTED"];
2625

2726
const isGitHubHosted = runnerEnvironment === "github-hosted" && agentIsSelfHosted !== "1";
2827

29-
core.info(`Auto-detected runner type: ${isGitHubHosted ? 'GitHub-hosted' : 'self-hosted'}`);
30-
core.info(`System dependencies will ${isGitHubHosted ? 'be' : 'not be'} installed (auto mode)`);
28+
core.info(`Auto-detected runner type: ${isGitHubHosted ? "GitHub-hosted" : "self-hosted"}`);
29+
core.info(
30+
`System dependencies will ${isGitHubHosted ? "be" : "not be"} installed (auto mode)`,
31+
);
3132

3233
return isGitHubHosted;
3334
}
34-
throw new Error(`Invalid value for install-system-dependencies: "${input}". Must be "auto", "true", or "false".`);
35+
throw new Error(
36+
`Invalid value for install-system-dependencies: "${input}". Must be "auto", "true", or "false".`,
37+
);
3538
}
3639

3740
/**
@@ -48,7 +51,6 @@ export function resolveInstallDependencies(input: string): boolean {
4851
* @param installSystemDeps Input value for install-system-dependencies ("auto" | "true" | "false")
4952
*/
5053

51-
5254
export async function install(
5355
platform: string,
5456
architecture: string,

src/install.unit.test.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ describe("resolveInstallDependencies function", () => {
9292

9393
expect(() => {
9494
install.resolveInstallDependencies("");
95-
}).toThrow('Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".');
96-
});
95+
}).toThrow(
96+
'Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".',
97+
);
98+
});
9799

98100
// for empty string should throw error for self hosted
99101
it("throws error for empty string input for self-hosted runner", () => {
@@ -102,14 +104,18 @@ describe("resolveInstallDependencies function", () => {
102104

103105
expect(() => {
104106
install.resolveInstallDependencies("");
105-
}).toThrow('Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".');
106-
});
107+
}).toThrow(
108+
'Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".',
109+
);
110+
});
107111

108112
// for any invalid input should throw error
109113
it("throws error for invalid string input", () => {
110114
expect(() => {
111115
install.resolveInstallDependencies("invalid-value");
112-
}).toThrow('Invalid value for install-system-dependencies: "invalid-value". Must be "auto", "true", or "false".');
116+
}).toThrow(
117+
'Invalid value for install-system-dependencies: "invalid-value". Must be "auto", "true", or "false".',
118+
);
113119
});
114120
});
115121

@@ -145,9 +151,13 @@ describe("install procedure", () => {
145151
install.install(platform, arch, release, products, useCache, installSystemDependencies);
146152

147153
beforeEach(() => {
148-
matlabInstallSystemDependenciesMock = matlab.installSystemDependencies as jest.Mock<typeof matlab.installSystemDependencies>;
154+
matlabInstallSystemDependenciesMock = matlab.installSystemDependencies as jest.Mock<
155+
typeof matlab.installSystemDependencies
156+
>;
149157
matlabGetReleaseInfoMock = matlab.getReleaseInfo as jest.Mock<typeof matlab.getReleaseInfo>;
150-
matlabGetToolcacheDirMock = matlab.getToolcacheDir as jest.Mock<typeof matlab.getToolcacheDir>;
158+
matlabGetToolcacheDirMock = matlab.getToolcacheDir as jest.Mock<
159+
typeof matlab.getToolcacheDir
160+
>;
151161
matlabSetupBatchMock = matlab.setupBatch as jest.Mock<typeof matlab.setupBatch>;
152162
mpmSetupMock = mpm.setup as jest.Mock<typeof mpm.setup>;
153163
mpmInstallMock = mpm.install as jest.Mock<typeof mpm.install>;
@@ -202,14 +212,7 @@ describe("install procedure", () => {
202212
isPrerelease: false,
203213
});
204214
await expect(
205-
install.install(
206-
platform,
207-
arch,
208-
"r2020a",
209-
products,
210-
useCache,
211-
"true",
212-
),
215+
install.install(platform, arch, "r2020a", products, useCache, "true"),
213216
).rejects.toBeDefined();
214217
});
215218

src/matlab.unit.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ describe("matlab tests", () => {
123123
runnerToolcache = process.env["RUNNER_TOOL_CACHE"];
124124

125125
process.env["RUNNER_TOOL_CACHE"] = "C:\\hostedtoolcache\\windows\\matlab\\r2022b";
126-
cacheFileMock.mockImplementation(() => Promise.resolve(process.env["RUNNER_TOOL_CACHE"] ?? ""));
126+
cacheFileMock.mockImplementation(() =>
127+
Promise.resolve(process.env["RUNNER_TOOL_CACHE"] ?? ""),
128+
);
127129
findMock.mockReturnValue("");
128130
});
129131

@@ -353,7 +355,9 @@ describe("matlab tests", () => {
353355
const release = "r2023b";
354356

355357
beforeEach(() => {
356-
downloadAndRunScriptMock = script.downloadAndRunScript as jest.Mock<typeof script.downloadAndRunScript>;
358+
downloadAndRunScriptMock = script.downloadAndRunScript as jest.Mock<
359+
typeof script.downloadAndRunScript
360+
>;
357361
tcDownloadToolMock = tc.downloadTool as jest.Mock<typeof tc.downloadTool>;
358362
execMock = exec.exec as jest.Mock<typeof exec.exec>;
359363
});

0 commit comments

Comments
 (0)