diff --git a/.github/workflows/bat.yml b/.github/workflows/bat.yml index 2f6a058..b17e36a 100644 --- a/.github/workflows/bat.yml +++ b/.github/workflows/bat.yml @@ -80,11 +80,11 @@ jobs: run: 'if [[ "${{ steps.setup_matlab.outputs.matlabroot }}" != *"MATLAB"* ]]; then exit 1; fi' shell: bash - name: Check MATLAB version - uses: matlab-actions/run-command@v2 + uses: matlab-actions/run-command@v3 with: command: "${{ matrix.check-matlab }}" - name: Check toolbox version - uses: matlab-actions/run-command@v2 + uses: matlab-actions/run-command@v3 with: command: "${{ matrix.check-toolbox }}" - name: Check NoOp on 2nd install @@ -100,7 +100,7 @@ jobs: products: Image_Processing_Toolbox - name: Check additional product was installed if: matrix.os != 'windows-latest' - uses: matlab-actions/run-command@v2 + uses: matlab-actions/run-command@v3 with: command: assert(any(strcmp({ver().Name},'Image Processing Toolbox'))) - name: Call setup MATLAB again with different release # should not error as in issue 130 @@ -108,6 +108,6 @@ jobs: with: release: R2023b - name: Check MATLAB version - uses: matlab-actions/run-command@v2 + uses: matlab-actions/run-command@v3 with: command: matlabVer = ver('matlab'); assert(strcmp(matlabVer.Release,'(R2023b)')); diff --git a/README.md b/README.md index eb74d12..10c2dd2 100644 --- a/README.md +++ b/README.md @@ -142,10 +142,9 @@ When you define your workflow in the `.github/workflows` directory of your repos | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `release` |
(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.
**Example**: `release: R2024a`
**Example**: `release: latest`
**Example**: `release: R2024aU4`
(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.
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™ in addition to MATLAB, specify `products: Deep_Learning_Toolbox`.
For an example of how to use the `products` input, see [Run Tests in Parallel](#run-tests-in-parallel).
**Example**: `products: Simulink`
**Example:** `products: Simulink Deep_Learning_Toolbox`
(Optional) Option to install the dependencies required to run MATLAB and other MathWorks products, specified as one of these values:
**Note**: On a self-hosted runner, if you specify this input as `true`, the runner must be configured with passwordless `sudo` access.
**Example**: `install-system-dependencies: true`
| +| `install-system-dependencies` |(Optional) Option to install the dependencies required to run MATLAB and other MathWorks products, specified as one of these values:
**Note**: On a self-hosted runner, if you specify this input as `true`, the runner must be configured with passwordless `sudo` access.
**Example**: `install-system-dependencies: true`
| | `cache` |(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).
**Example**: `cache: true`
| - #### Required Software on Self-Hosted Runners 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. diff --git a/action.yml b/action.yml index b24be59..23caea5 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: description: >- Option to install system dependencies for MATLAB, specified as auto, true, or false required: false - default: auto + default: auto cache: description: >- Option to enable caching with GitHub Actions, specified as false or true diff --git a/devel/contributing.md b/devel/contributing.md index 0f4c6fd..018b52c 100644 --- a/devel/contributing.md +++ b/devel/contributing.md @@ -13,3 +13,32 @@ Familiarize yourself with the best practices for [releasing and maintaining GitH 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. 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. + +## Adding a Pre-Commit Hook + +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: + +_bash (Linux/macOS)_ + +```sh +echo '#!/bin/sh' > .git/hooks/pre-commit +echo 'npm run ci' >> .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit +``` + +_Command Prompt (Windows)_ + +```cmd +echo #!/bin/sh > .git\hooks\pre-commit +echo npm run ci >> .git\hooks\pre-commit +``` + +_PowerShell (Windows)_ + +```pwsh +Set-Content .git\hooks\pre-commit '#!/bin/sh' +Add-Content .git\hooks\pre-commit 'npm run ci' +``` + +> **Note:** +> Git hooks are not version-controlled, so you need to set up this hook for each fresh clone of the repository. diff --git a/jest.config.ts b/jest.config.ts index 6719549..aa9775a 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -14,7 +14,7 @@ export default { }, ], }, - extensionsToTreatAsEsm: ['.ts'], + extensionsToTreatAsEsm: [".ts"], transformIgnorePatterns: ["node_modules/(?!(@actions)/)"], moduleNameMapper: { "^(\\.{1,2}/.*)\\.js$": "$1", diff --git a/package.json b/package.json index 4c8bb81..6126883 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "tsc", "package": "ncc build src/index.ts -o dist/setup --minify && ncc build src/post.ts -o dist/cache-save --minify", "test": "NODE_OPTIONS='--experimental-vm-modules' jest", - "all": "npm run lint && npm test && npm run build && npm run package", + "all": "npm run format-check && npm run lint && npm test && npm run build && npm run package", "ci": "npm run clean && npm ci && npm run all" }, "files": [ diff --git a/src/index.ts b/src/index.ts index ed5e12f..f70da67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,6 @@ import * as core from "@actions/core"; import * as install from "./install.js"; - /** * Gather action inputs and then run action. */ @@ -14,8 +13,15 @@ export async function run() { const products = core.getMultilineInput("products"); const cache = core.getBooleanInput("cache"); const installSystemDependencies = core.getInput("install-system-dependencies"); - - return install.install(platform, architecture, release, products, cache, installSystemDependencies); + + return install.install( + platform, + architecture, + release, + products, + cache, + installSystemDependencies, + ); } run().catch((e) => { diff --git a/src/install.ts b/src/install.ts index d236ec2..b7c2aeb 100644 --- a/src/install.ts +++ b/src/install.ts @@ -7,31 +7,34 @@ import * as path from "path"; import * as cache from "./cache-restore.js"; import { State } from "./install-state.js"; - export function resolveInstallDependencies(input: string): boolean { - const normalized = (input ?? '').trim().toLowerCase(); + const normalized = (input ?? "").trim().toLowerCase(); - if (normalized === 'true') { + if (normalized === "true") { return true; } - if (normalized === 'false'){ + if (normalized === "false") { return false; } - if (normalized === 'auto') { + if (normalized === "auto") { // detect runner type and provide value accordingly const runnerEnvironment = process.env["RUNNER_ENVIRONMENT"]; const agentIsSelfHosted = process.env["AGENT_ISSELFHOSTED"]; const isGitHubHosted = runnerEnvironment === "github-hosted" && agentIsSelfHosted !== "1"; - core.info(`Auto-detected runner type: ${isGitHubHosted ? 'GitHub-hosted' : 'self-hosted'}`); - core.info(`System dependencies will ${isGitHubHosted ? 'be' : 'not be'} installed (auto mode)`); + core.info(`Auto-detected runner type: ${isGitHubHosted ? "GitHub-hosted" : "self-hosted"}`); + core.info( + `System dependencies will ${isGitHubHosted ? "be" : "not be"} installed (auto mode)`, + ); return isGitHubHosted; } - throw new Error(`Invalid value for install-system-dependencies: "${input}". Must be "auto", "true", or "false".`); + throw new Error( + `Invalid value for install-system-dependencies: "${input}". Must be "auto", "true", or "false".`, + ); } /** @@ -48,7 +51,6 @@ export function resolveInstallDependencies(input: string): boolean { * @param installSystemDeps Input value for install-system-dependencies ("auto" | "true" | "false") */ - export async function install( platform: string, architecture: string, diff --git a/src/install.unit.test.ts b/src/install.unit.test.ts index 2b845cc..1282bf8 100644 --- a/src/install.unit.test.ts +++ b/src/install.unit.test.ts @@ -92,8 +92,10 @@ describe("resolveInstallDependencies function", () => { expect(() => { install.resolveInstallDependencies(""); - }).toThrow('Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".'); - }); + }).toThrow( + 'Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".', + ); + }); // for empty string should throw error for self hosted it("throws error for empty string input for self-hosted runner", () => { @@ -102,14 +104,18 @@ describe("resolveInstallDependencies function", () => { expect(() => { install.resolveInstallDependencies(""); - }).toThrow('Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".'); - }); + }).toThrow( + 'Invalid value for install-system-dependencies: "". Must be "auto", "true", or "false".', + ); + }); // for any invalid input should throw error it("throws error for invalid string input", () => { expect(() => { install.resolveInstallDependencies("invalid-value"); - }).toThrow('Invalid value for install-system-dependencies: "invalid-value". Must be "auto", "true", or "false".'); + }).toThrow( + 'Invalid value for install-system-dependencies: "invalid-value". Must be "auto", "true", or "false".', + ); }); }); @@ -145,9 +151,13 @@ describe("install procedure", () => { install.install(platform, arch, release, products, useCache, installSystemDependencies); beforeEach(() => { - matlabInstallSystemDependenciesMock = matlab.installSystemDependencies as jest.Mock