From 470d7fe38814eebc5b63113085257617e504974c Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Mon, 22 Sep 2025 15:31:26 +0530 Subject: [PATCH 1/9] default to auto-caching only for npm package manager and documentation update --- README.md | 47 +++++++++++++++++++----------------- __tests__/main.test.ts | 7 +++--- action.yml | 2 +- dist/setup/index.js | 29 +++++++++++----------- docs/advanced-usage.md | 55 +++++++++++++++++++++--------------------- src/main.ts | 34 +++++++++++++------------- 6 files changed, 90 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 633e1460..4656f654 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ This action provides the following functionality for GitHub Actions users: ## Breaking changes in V5 -- Enabled caching by default with package manager detection if no cache input is provided. - > For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation. +- Enabled caching for npm dependencies by default when the package manager is detected and no cache input is provided. + > For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching for npm by setting `package-manager-cache: false` when caching is not needed for secure operation. - Upgraded action from node20 to node24. > Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. [See Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1) @@ -67,7 +67,8 @@ See [action.yml](action.yml) # Default: '' cache: '' - # Used to disable automatic caching based on the package manager field in package.json. By default, caching is enabled if the package manager field is present and no cache input is provided' + # Controls automatic caching for npm. By default, caching for npm is enabled if the packageManager field in package.json specifies npm and no explicit cache input is provided. + # To disable automatic caching for npm, set package-manager-cache to false. # default: true package-manager-cache: true @@ -115,7 +116,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 18 + node-version: 24 - run: npm ci - run: npm test ``` @@ -132,8 +133,8 @@ The `node-version` input supports the Semantic Versioning Specification, for mor Examples: - - Major versions: `18`, `20` - - More specific versions: `10.15`, `16.15.1` , `18.4.0` + - Major versions: `22`, `24` + - More specific versions: `20.19`, `22.17.1` , `24.8.0` - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n` - Latest release: `*` or `latest`/`current`/`node` @@ -151,18 +152,6 @@ It's **always** recommended to commit the lockfile of your package manager for s The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional. -Caching is turned on by default when a `packageManager` field is detected in the `package.json` file and no `cache` input is provided. The `package-manager-cache` input provides control over this automatic caching behavior. By default, `package-manager-cache` is set to `true`, which enables caching when a valid package manager field is detected in the `package.json` file. To disable this automatic caching, set the `package-manager-cache` input to `false`. - -```yaml -steps: -- uses: actions/checkout@v5 -- uses: actions/setup-node@v5 - with: - package-manager-cache: false -- run: npm ci -``` -> If no valid `packageManager` field is detected in the `package.json` file, caching will remain disabled unless explicitly configured. For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation. - The action defaults to search for the dependency file (`package-lock.json`, `npm-shrinkwrap.json` or `yarn.lock`) in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` for cases when multiple dependency files are used, or they are located in different subdirectories. **Note:** The action does not cache `node_modules` @@ -176,7 +165,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 20 + node-version: 24 cache: 'npm' - run: npm ci - run: npm test @@ -189,13 +178,27 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 20 + node-version: 24 cache: 'npm' cache-dependency-path: subdir/package-lock.json - run: npm ci - run: npm test ``` +Caching for npm dependencies is automatically enabled when your `package.json` contains a `packageManager` field set to `npm` and no explicit cache input is provided. + +This behavior is controlled by the `package-manager-cache` input, which defaults to `true`. To turn off automatic caching, set `package-manager-cache` to `false`. + +```yaml +steps: +- uses: actions/checkout@v5 +- uses: actions/setup-node@v5 + with: + package-manager-cache: false +- run: npm ci +``` +> If your `package.json` file does not include a `packageManager` field set to `npm`, caching will be disabled unless you explicitly enable it. For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching for npm by setting `package-manager-cache: false` when caching is not required for secure operation. + ## Matrix Testing ```yaml @@ -204,7 +207,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [ 14, 16, 18 ] + node: [ 20, 22, 24 ] name: Node ${{ matrix.node }} sample steps: - uses: actions/checkout@v5 @@ -226,7 +229,7 @@ To get a higher rate limit, you can [generate a personal access token on github. uses: actions/setup-node@v5 with: token: ${{ secrets.GH_DOTCOM_TOKEN }} - node-version: 20 + node-version: 24 ``` If the runner is not able to access github.com, any Nodejs versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information. diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 5af57092..9411d607 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -288,19 +288,20 @@ describe('main tests', () => { it('Should enable caching with the resolved package manager from packageManager field in package.json when the cache input is not provided', async () => { inputs['package-manager-cache'] = 'true'; inputs['cache'] = ''; // No cache input is provided + isCacheActionAvailable.mockImplementation(() => true); inSpy.mockImplementation(name => inputs[name]); const readFileSpy = jest.spyOn(fs, 'readFileSync'); readFileSpy.mockImplementation(() => JSON.stringify({ - packageManager: 'yarn@3.2.0' + packageManager: 'npm@10.8.2' }) ); await main.run(); - expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'yarn'); + expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); }); it('Should not enable caching if the packageManager field is missing in package.json and the cache input is not provided', async () => { @@ -337,7 +338,7 @@ describe('main tests', () => { inputs['cache'] = 'npm'; // Explicit cache input provided inSpy.mockImplementation(name => inputs[name]); - isCacheActionAvailable.mockReturnValue(true); + isCacheActionAvailable.mockImplementation(() => true); await main.run(); diff --git a/action.yml b/action.yml index fbc851b6..22276180 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,7 @@ inputs: cache: description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.' package-manager-cache: - description: 'Set to false to disable automatic caching based on the package manager field in package.json. By default, caching is enabled if the package manager field is present.' + description: 'Set to false to disable automatic caching. By default, caching is enabled when npm is the specified package manager in package.json.' default: true cache-dependency-path: description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.' diff --git a/dist/setup/index.js b/dist/setup/index.js index ffa02be1..ea80b156 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -99788,16 +99788,19 @@ function run() { } const resolvedPackageManager = getNameFromPackageManagerField(); const cacheDependencyPath = core.getInput('cache-dependency-path'); - if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) { - core.saveState(constants_1.State.CachePackageManager, cache); - yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath); - } - else if (resolvedPackageManager && packagemanagercache) { - core.info("Detected package manager from package.json's packageManager field: " + - resolvedPackageManager + - '. Auto caching has been enabled for it. If you want to disable it, set package-manager-cache input to false'); - core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager); - yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath); + if ((0, cache_utils_1.isCacheFeatureAvailable)()) { + // if the cache input is provided, use it for caching. + if (cache) { + core.saveState(constants_1.State.CachePackageManager, cache); + yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath); + // package manager npm is detected from package.json, enable auto-caching for npm. + } + else if (resolvedPackageManager && packagemanagercache) { + core.info("Detected npm as the package manager from package.json's packageManager field. " + + 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'); + core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager); + yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath); + } } const matchersPath = path.join(__dirname, '../..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`); @@ -99833,14 +99836,12 @@ function resolveVersionInput() { return version; } function getNameFromPackageManagerField() { - // Check packageManager field in package.json - const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm']; + // Enable auto-cache for npm try { const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8')); const pm = packageJson.packageManager; if (typeof pm === 'string') { - const regex = new RegExp(`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@`); - const match = pm.match(regex); + const match = pm.match(/^(?:\^)?(npm)@/); return match ? match[1] : undefined; } return undefined; diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 97f977f7..77f051a2 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -48,7 +48,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '16' + node-version: '24' check-latest: true - run: npm ci - run: npm test @@ -100,7 +100,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14' + node-version: '24' architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default - run: npm ci - run: npm test @@ -121,7 +121,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '20.0.0-v8-canary' # it will install the latest v8 canary release for node 20.0.0 + node-version: '24.0.0-v8-canary' # it will install the latest v8 canary release for node 24.0.0 - run: npm ci - run: npm test ``` @@ -136,7 +136,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '20-v8-canary' # it will install the latest v8 canary release for node 20 + node-version: '24-v8-canary' # it will install the latest v8 canary release for node 24 - run: npm ci - run: npm test ``` @@ -152,7 +152,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: 'v20.1.1-v8-canary20221103f7e2421e91' + node-version: 'v24.0.0-v8-canary2025030537242e55ac' - run: npm ci - run: npm test ``` @@ -172,7 +172,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '16-nightly' # it will install the latest nightly release for node 16 + node-version: '24-nightly' # it will install the latest nightly release for node 24 - run: npm ci - run: npm test ``` @@ -188,7 +188,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '16.0.0-nightly' # it will install the latest nightly release for node 16.0.0 + node-version: '24.0.0-nightly' # it will install the latest nightly release for node 24.0.0 - run: npm ci - run: npm test ``` @@ -204,7 +204,7 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '16.0.0-nightly20210420a0261d231c' + node-version: '24.0.0-nightly202505066102159fa1' - run: npm ci - run: npm test ``` @@ -222,24 +222,25 @@ jobs: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '16.0.0-rc.1' + node-version: '24.0.0-rc.4' - run: npm ci - run: npm test ``` -**Note:** Unlike nightly versions, which support version range specifiers, you must specify the exact version for a release candidate: `16.0.0-rc.1`. +**Note:** Unlike nightly versions, which support version range specifiers, you must specify the exact version for a release candidate: `24.0.0-rc.4`. ## Caching packages data The action follows [actions/cache](https://github.com/actions/cache/blob/main/examples.md#node---npm) guidelines, and caches global cache on the machine instead of `node_modules`, so cache can be reused between different Node.js versions. **Caching yarn dependencies:** -Yarn caching handles both yarn versions: 1 or 2. +Yarn caching handles both Yarn Classic (v1) and Yarn Berry (v2, v3, v4+). + ```yaml steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14' + node-version: '24' cache: 'yarn' - run: yarn install --frozen-lockfile # optional, --immutable - run: yarn test @@ -256,12 +257,12 @@ steps: steps: - uses: actions/checkout@v5 -- uses: pnpm/action-setup@v2 +- uses: pnpm/action-setup@v4 with: - version: 6.32.9 + version: 10 - uses: actions/setup-node@v5 with: - node-version: '14' + node-version: '24' cache: 'pnpm' - run: pnpm install - run: pnpm test @@ -277,7 +278,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14' + node-version: '24' cache: 'npm' cache-dependency-path: '**/package-lock.json' - run: npm ci @@ -290,7 +291,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14' + node-version: '24' cache: 'npm' cache-dependency-path: | server/app/package-lock.json @@ -312,15 +313,15 @@ jobs: - macos-latest - windows-latest node_version: - - 12 - - 14 - - 16 + - 20 + - 22 + - 24 architecture: - x64 # an extra windows-x86 run: include: - - os: windows-2016 - node_version: 12 + - os: windows-2022 + node_version: 24 architecture: x86 name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} steps: @@ -340,7 +341,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14.x' + node-version: '24.x' registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm publish @@ -360,7 +361,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14.x' + node-version: '24.x' registry-url: - run: yarn install --frozen-lockfile - run: yarn publish @@ -380,7 +381,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14.x' + node-version: '24.x' registry-url: 'https://registry.npmjs.org' # Skip post-install scripts here, as a malicious # script could steal NODE_AUTH_TOKEN. @@ -400,7 +401,7 @@ steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: - node-version: '14.x' + node-version: '24.x' - name: Setup .yarnrc.yml run: | yarn config set npmScopes.my-org.npmRegistryServer "https://npm.pkg.github.com" @@ -429,7 +430,7 @@ The token will be passed as a bearer token in the `Authorization` header. ```yaml - uses: actions/setup-node@v5 with: - node-version: '14.x' + node-version: '24.x' mirror: 'https://nodejs.org/dist' mirror-token: 'your-mirror-token' ``` diff --git a/src/main.ts b/src/main.ts index 01e58e05..8e95bf71 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,17 +69,21 @@ export async function run() { const resolvedPackageManager = getNameFromPackageManagerField(); const cacheDependencyPath = core.getInput('cache-dependency-path'); - if (cache && isCacheFeatureAvailable()) { - core.saveState(State.CachePackageManager, cache); - await restoreCache(cache, cacheDependencyPath); - } else if (resolvedPackageManager && packagemanagercache) { - core.info( - "Detected package manager from package.json's packageManager field: " + - resolvedPackageManager + - '. Auto caching has been enabled for it. If you want to disable it, set package-manager-cache input to false' - ); - core.saveState(State.CachePackageManager, resolvedPackageManager); - await restoreCache(resolvedPackageManager, cacheDependencyPath); + + if (isCacheFeatureAvailable()) { + // if the cache input is provided, use it for caching. + if (cache) { + core.saveState(State.CachePackageManager, cache); + await restoreCache(cache, cacheDependencyPath); + // package manager npm is detected from package.json, enable auto-caching for npm. + } else if (resolvedPackageManager && packagemanagercache) { + core.info( + "Detected npm as the package manager from package.json's packageManager field. " + + 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false' + ); + core.saveState(State.CachePackageManager, resolvedPackageManager); + await restoreCache(resolvedPackageManager, cacheDependencyPath); + } } const matchersPath = path.join(__dirname, '../..', '.github'); @@ -132,8 +136,7 @@ function resolveVersionInput(): string { } export function getNameFromPackageManagerField(): string | undefined { - // Check packageManager field in package.json - const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm']; + // Enable auto-cache for npm try { const packageJson = JSON.parse( fs.readFileSync( @@ -143,10 +146,7 @@ export function getNameFromPackageManagerField(): string | undefined { ); const pm = packageJson.packageManager; if (typeof pm === 'string') { - const regex = new RegExp( - `^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@` - ); - const match = pm.match(regex); + const match = pm.match(/^(?:\^)?(npm)@/); return match ? match[1] : undefined; } return undefined; From 7024c214c6be20d6a4ca5606a7ddc2cf63883caf Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Tue, 23 Sep 2025 12:50:33 +0530 Subject: [PATCH 2/9] refactor: enhance package manager detection for auto-caching --- dist/setup/index.js | 14 ++++++++------ src/main.ts | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index ea80b156..331a0bcc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -99786,7 +99786,6 @@ function run() { if (registryUrl) { auth.configAuthentication(registryUrl, alwaysAuth); } - const resolvedPackageManager = getNameFromPackageManagerField(); const cacheDependencyPath = core.getInput('cache-dependency-path'); if ((0, cache_utils_1.isCacheFeatureAvailable)()) { // if the cache input is provided, use it for caching. @@ -99795,11 +99794,14 @@ function run() { yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath); // package manager npm is detected from package.json, enable auto-caching for npm. } - else if (resolvedPackageManager && packagemanagercache) { - core.info("Detected npm as the package manager from package.json's packageManager field. " + - 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'); - core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager); - yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath); + else if (packagemanagercache) { + const resolvedPackageManager = getNameFromPackageManagerField(); + if (resolvedPackageManager) { + core.info("Detected npm as the package manager from package.json's packageManager field. " + + 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'); + core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager); + yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath); + } } } const matchersPath = path.join(__dirname, '../..', '.github'); diff --git a/src/main.ts b/src/main.ts index 8e95bf71..1e98895a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -67,7 +67,6 @@ export async function run() { auth.configAuthentication(registryUrl, alwaysAuth); } - const resolvedPackageManager = getNameFromPackageManagerField(); const cacheDependencyPath = core.getInput('cache-dependency-path'); if (isCacheFeatureAvailable()) { @@ -76,13 +75,16 @@ export async function run() { core.saveState(State.CachePackageManager, cache); await restoreCache(cache, cacheDependencyPath); // package manager npm is detected from package.json, enable auto-caching for npm. - } else if (resolvedPackageManager && packagemanagercache) { - core.info( - "Detected npm as the package manager from package.json's packageManager field. " + - 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false' - ); - core.saveState(State.CachePackageManager, resolvedPackageManager); - await restoreCache(resolvedPackageManager, cacheDependencyPath); + } else if (packagemanagercache) { + const resolvedPackageManager = getNameFromPackageManagerField(); + if (resolvedPackageManager) { + core.info( + "Detected npm as the package manager from package.json's packageManager field. " + + 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false' + ); + core.saveState(State.CachePackageManager, resolvedPackageManager); + await restoreCache(resolvedPackageManager, cacheDependencyPath); + } } } From 8f225c52cefbe00b1b057a8d90d498255aa9cbdb Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Fri, 26 Sep 2025 13:31:00 +0530 Subject: [PATCH 3/9] add devEngines.packageManager detection logic for npm auto-caching --- __tests__/main.test.ts | 113 +++++++++++++++++++++++++++++++++++------ dist/setup/index.js | 27 +++++++--- src/main.ts | 28 +++++++--- 3 files changed, 141 insertions(+), 27 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 9411d607..ba26e64b 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -285,13 +285,12 @@ describe('main tests', () => { }); describe('cache feature tests', () => { - it('Should enable caching with the resolved package manager from packageManager field in package.json when the cache input is not provided', async () => { + it('Should enable caching when packageManager is npm and cache input is not provided', async () => { inputs['package-manager-cache'] = 'true'; - inputs['cache'] = ''; // No cache input is provided + inputs['cache'] = ''; isCacheActionAvailable.mockImplementation(() => true); inSpy.mockImplementation(name => inputs[name]); - const readFileSpy = jest.spyOn(fs, 'readFileSync'); readFileSpy.mockImplementation(() => JSON.stringify({ @@ -304,16 +303,106 @@ describe('main tests', () => { expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); }); - it('Should not enable caching if the packageManager field is missing in package.json and the cache input is not provided', async () => { + it('Should enable caching when devEngines.packageManager.name is "npm" and cache input is not provided', async () => { inputs['package-manager-cache'] = 'true'; - inputs['cache'] = ''; // No cache input is provided + inputs['cache'] = ''; + isCacheActionAvailable.mockImplementation(() => true); inSpy.mockImplementation(name => inputs[name]); - const readFileSpy = jest.spyOn(fs, 'readFileSync'); readFileSpy.mockImplementation(() => JSON.stringify({ - //packageManager field is not present + devEngines: { + packageManager: {name: 'npm'} + } + }) + ); + + await main.run(); + + expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); + }); + + it('Should enable caching when devEngines.packageManager is array and one entry has name "npm"', async () => { + inputs['package-manager-cache'] = 'true'; + inputs['cache'] = ''; + isCacheActionAvailable.mockImplementation(() => true); + + inSpy.mockImplementation(name => inputs[name]); + const readFileSpy = jest.spyOn(fs, 'readFileSync'); + readFileSpy.mockImplementation(() => + JSON.stringify({ + devEngines: { + packageManager: [{name: 'pnpm'}, {name: 'npm'}] + } + }) + ); + + await main.run(); + + expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); + }); + + it('Should not enable caching if packageManager is "pnpm@8.0.0" and cache input is not provided', async () => { + inputs['package-manager-cache'] = 'true'; + inputs['cache'] = ''; + inSpy.mockImplementation(name => inputs[name]); + const readFileSpy = jest.spyOn(fs, 'readFileSync'); + readFileSpy.mockImplementation(() => + JSON.stringify({ + packageManager: 'pnpm@8.0.0' + }) + ); + + await main.run(); + + expect(saveStateSpy).not.toHaveBeenCalled(); + }); + + it('Should not enable caching if devEngines.packageManager.name is "pnpm"', async () => { + inputs['package-manager-cache'] = 'true'; + inputs['cache'] = ''; + inSpy.mockImplementation(name => inputs[name]); + const readFileSpy = jest.spyOn(fs, 'readFileSync'); + readFileSpy.mockImplementation(() => + JSON.stringify({ + devEngines: { + packageManager: {name: 'pnpm'} + } + }) + ); + + await main.run(); + + expect(saveStateSpy).not.toHaveBeenCalled(); + }); + + it('Should not enable caching if devEngines.packageManager is array without "npm"', async () => { + inputs['package-manager-cache'] = 'true'; + inputs['cache'] = ''; + inSpy.mockImplementation(name => inputs[name]); + const readFileSpy = jest.spyOn(fs, 'readFileSync'); + readFileSpy.mockImplementation(() => + JSON.stringify({ + devEngines: { + packageManager: [{name: 'pnpm'}, {name: 'yarn'}] + } + }) + ); + + await main.run(); + + expect(saveStateSpy).not.toHaveBeenCalled(); + }); + + it('Should not enable caching if packageManager field is missing in package.json and cache input is not provided', async () => { + inputs['package-manager-cache'] = 'true'; + inputs['cache'] = ''; + inSpy.mockImplementation(name => inputs[name]); + const readFileSpy = jest.spyOn(fs, 'readFileSync'); + readFileSpy.mockImplementation(() => + JSON.stringify({ + // packageManager field is not present }) ); @@ -324,24 +413,18 @@ describe('main tests', () => { it('Should skip caching when package-manager-cache is false', async () => { inputs['package-manager-cache'] = 'false'; - inputs['cache'] = ''; // No cache input is provided - + inputs['cache'] = ''; inSpy.mockImplementation(name => inputs[name]); - await main.run(); - expect(saveStateSpy).not.toHaveBeenCalled(); }); it('Should enable caching with cache input explicitly provided', async () => { inputs['package-manager-cache'] = 'true'; - inputs['cache'] = 'npm'; // Explicit cache input provided - + inputs['cache'] = 'npm'; inSpy.mockImplementation(name => inputs[name]); isCacheActionAvailable.mockImplementation(() => true); - await main.run(); - expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 331a0bcc..63e926da 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -99838,17 +99838,32 @@ function resolveVersionInput() { return version; } function getNameFromPackageManagerField() { - // Enable auto-cache for npm + var _a; + const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..." try { const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8')); - const pm = packageJson.packageManager; - if (typeof pm === 'string') { - const match = pm.match(/^(?:\^)?(npm)@/); - return match ? match[1] : undefined; + // Check devEngines.packageManager first (object or array) + const devPM = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.devEngines) === null || _a === void 0 ? void 0 : _a.packageManager; + if (devPM) { + if (Array.isArray(devPM)) { + for (const obj of devPM) { + if (typeof (obj === null || obj === void 0 ? void 0 : obj.name) === 'string' && npmRegex.test(obj.name)) { + return 'npm'; + } + } + } + else if (typeof (devPM === null || devPM === void 0 ? void 0 : devPM.name) === 'string' && npmRegex.test(devPM.name)) { + return 'npm'; + } + } + // Check top-level packageManager + const topLevelPM = packageJson === null || packageJson === void 0 ? void 0 : packageJson.packageManager; + if (typeof topLevelPM === 'string' && npmRegex.test(topLevelPM)) { + return 'npm'; } return undefined; } - catch (err) { + catch (_b) { return undefined; } } diff --git a/src/main.ts b/src/main.ts index 1e98895a..b0988701 100644 --- a/src/main.ts +++ b/src/main.ts @@ -138,7 +138,7 @@ function resolveVersionInput(): string { } export function getNameFromPackageManagerField(): string | undefined { - // Enable auto-cache for npm + const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..." try { const packageJson = JSON.parse( fs.readFileSync( @@ -146,13 +146,29 @@ export function getNameFromPackageManagerField(): string | undefined { 'utf-8' ) ); - const pm = packageJson.packageManager; - if (typeof pm === 'string') { - const match = pm.match(/^(?:\^)?(npm)@/); - return match ? match[1] : undefined; + + // Check devEngines.packageManager first (object or array) + const devPM = packageJson?.devEngines?.packageManager; + if (devPM) { + if (Array.isArray(devPM)) { + for (const obj of devPM) { + if (typeof obj?.name === 'string' && npmRegex.test(obj.name)) { + return 'npm'; + } + } + } else if (typeof devPM?.name === 'string' && npmRegex.test(devPM.name)) { + return 'npm'; + } } + + // Check top-level packageManager + const topLevelPM = packageJson?.packageManager; + if (typeof topLevelPM === 'string' && npmRegex.test(topLevelPM)) { + return 'npm'; + } + return undefined; - } catch (err) { + } catch { return undefined; } } From 33371d09d438db7e3938646bc267a4a406adef0a Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Wed, 1 Oct 2025 15:15:48 +0530 Subject: [PATCH 4/9] chore: bump version to 6.0.0 and update documentation --- README.md | 22 ++++++++++++--------- dist/setup/index.js | 12 +++--------- docs/advanced-usage.md | 44 +++++++++++++++++++++--------------------- package-lock.json | 4 ++-- package.json | 2 +- src/main.ts | 11 +++-------- 6 files changed, 44 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 4656f654..7a36ba38 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,14 @@ This action provides the following functionality for GitHub Actions users: - Registering problem matchers for error output - Configuring authentication for GPR or npm +## Breaking changes in V6 + +- Caching is now automatically enabled for npm projects when the `packageManager` field in `package.json` is set to `npm`. For other package managers, such as Yarn and pnpm, caching is disabled by default and must be configured manually using the `cache` input. + ## Breaking changes in V5 -- Enabled caching for npm dependencies by default when the package manager is detected and no cache input is provided. - > For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching for npm by setting `package-manager-cache: false` when caching is not needed for secure operation. +- Enabled caching by default with package manager detection if no cache input is provided. + > For workflows with elevated privileges or access to sensitive information, we recommend disabling automatic caching by setting `package-manager-cache: false` when caching is not needed for secure operation. - Upgraded action from node20 to node24. > Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. [See Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1) @@ -28,7 +32,7 @@ See [action.yml](action.yml) ```yaml -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: # Version Spec of the version to use in SemVer notation. # It also admits such aliases as lts/*, latest, nightly and canary builds @@ -114,7 +118,7 @@ See [action.yml](action.yml) ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: 24 - run: npm ci @@ -163,7 +167,7 @@ See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` in ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: 24 cache: 'npm' @@ -176,7 +180,7 @@ steps: ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: 24 cache: 'npm' @@ -192,7 +196,7 @@ This behavior is controlled by the `package-manager-cache` input, which defaults ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: package-manager-cache: false - run: npm ci @@ -212,7 +216,7 @@ jobs: steps: - uses: actions/checkout@v5 - name: Setup node - uses: actions/setup-node@v5 + uses: actions/setup-node@v6 with: node-version: ${{ matrix.node }} - run: npm ci @@ -226,7 +230,7 @@ jobs: To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action: ```yaml -uses: actions/setup-node@v5 +uses: actions/setup-node@v6 with: token: ${{ secrets.GH_DOTCOM_TOKEN }} node-version: 24 diff --git a/dist/setup/index.js b/dist/setup/index.js index 63e926da..4aa29b26 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -99844,15 +99844,9 @@ function getNameFromPackageManagerField() { const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8')); // Check devEngines.packageManager first (object or array) const devPM = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.devEngines) === null || _a === void 0 ? void 0 : _a.packageManager; - if (devPM) { - if (Array.isArray(devPM)) { - for (const obj of devPM) { - if (typeof (obj === null || obj === void 0 ? void 0 : obj.name) === 'string' && npmRegex.test(obj.name)) { - return 'npm'; - } - } - } - else if (typeof (devPM === null || devPM === void 0 ? void 0 : devPM.name) === 'string' && npmRegex.test(devPM.name)) { + const devPMArray = devPM ? (Array.isArray(devPM) ? devPM : [devPM]) : []; + for (const obj of devPMArray) { + if (typeof (obj === null || obj === void 0 ? void 0 : obj.name) === 'string' && npmRegex.test(obj.name)) { return 'npm'; } } diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 77f051a2..3dcf0e2c 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -46,7 +46,7 @@ If `check-latest` is set to `true`, the action first checks if the cached versio ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24' check-latest: true @@ -64,7 +64,7 @@ See [supported version syntax](https://github.com/actions/setup-node#supported-v ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version-file: '.nvmrc' - run: npm ci @@ -98,7 +98,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24' architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default @@ -119,7 +119,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24.0.0-v8-canary' # it will install the latest v8 canary release for node 24.0.0 - run: npm ci @@ -134,7 +134,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24-v8-canary' # it will install the latest v8 canary release for node 24 - run: npm ci @@ -150,7 +150,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: 'v24.0.0-v8-canary2025030537242e55ac' - run: npm ci @@ -170,7 +170,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24-nightly' # it will install the latest nightly release for node 24 - run: npm ci @@ -186,7 +186,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24.0.0-nightly' # it will install the latest nightly release for node 24.0.0 - run: npm ci @@ -202,7 +202,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24.0.0-nightly202505066102159fa1' - run: npm ci @@ -220,7 +220,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v5 - - uses: actions/setup-node@v5 + - uses: actions/setup-node@v6 with: node-version: '24.0.0-rc.4' - run: npm ci @@ -238,7 +238,7 @@ Yarn caching handles both Yarn Classic (v1) and Yarn Berry (v2, v3, v4+). ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24' cache: 'yarn' @@ -260,7 +260,7 @@ steps: - uses: pnpm/action-setup@v4 with: version: 10 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24' cache: 'pnpm' @@ -276,7 +276,7 @@ steps: ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24' cache: 'npm' @@ -289,7 +289,7 @@ steps: ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24' cache: 'npm' @@ -327,7 +327,7 @@ jobs: steps: - uses: actions/checkout@v5 - name: Setup node - uses: actions/setup-node@v5 + uses: actions/setup-node@v6 with: node-version: ${{ matrix.node_version }} architecture: ${{ matrix.architecture }} @@ -339,7 +339,7 @@ jobs: ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24.x' registry-url: 'https://registry.npmjs.org' @@ -347,7 +347,7 @@ steps: - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: registry-url: 'https://npm.pkg.github.com' - run: npm publish @@ -359,7 +359,7 @@ steps: ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24.x' registry-url: @@ -367,7 +367,7 @@ steps: - run: yarn publish env: NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }} -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: registry-url: 'https://npm.pkg.github.com' - run: yarn publish @@ -379,7 +379,7 @@ steps: ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24.x' registry-url: 'https://registry.npmjs.org' @@ -399,7 +399,7 @@ Below you can find a sample "Setup .yarnrc.yml" step, that is going to allow you ```yaml steps: - uses: actions/checkout@v5 -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24.x' - name: Setup .yarnrc.yml @@ -428,7 +428,7 @@ It is possible to specify a token to authenticate with the mirror using the `mir The token will be passed as a bearer token in the `Authorization` header. ```yaml -- uses: actions/setup-node@v5 +- uses: actions/setup-node@v6 with: node-version: '24.x' mirror: 'https://nodejs.org/dist' diff --git a/package-lock.json b/package-lock.json index 4a35bf12..297a9fdc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "setup-node", - "version": "5.0.0", + "version": "6.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "setup-node", - "version": "5.0.0", + "version": "6.0.0", "license": "MIT", "dependencies": { "@actions/cache": "^4.0.3", diff --git a/package.json b/package.json index df57ab7c..ef1cfc19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-node", - "version": "5.0.0", + "version": "6.0.0", "private": true, "description": "setup node action", "main": "lib/setup-node.js", diff --git a/src/main.ts b/src/main.ts index b0988701..07871150 100644 --- a/src/main.ts +++ b/src/main.ts @@ -149,14 +149,9 @@ export function getNameFromPackageManagerField(): string | undefined { // Check devEngines.packageManager first (object or array) const devPM = packageJson?.devEngines?.packageManager; - if (devPM) { - if (Array.isArray(devPM)) { - for (const obj of devPM) { - if (typeof obj?.name === 'string' && npmRegex.test(obj.name)) { - return 'npm'; - } - } - } else if (typeof devPM?.name === 'string' && npmRegex.test(devPM.name)) { + const devPMArray = devPM ? (Array.isArray(devPM) ? devPM : [devPM]) : []; + for (const obj of devPMArray) { + if (typeof obj?.name === 'string' && npmRegex.test(obj.name)) { return 'npm'; } } From 1ba05d5d30d920284a28609aa0d015c8a4a381b7 Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Wed, 1 Oct 2025 18:20:08 +0530 Subject: [PATCH 5/9] docs: update README and action.yml for npm caching logic clarification --- README.md | 6 +++--- action.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a36ba38..2603f199 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This action provides the following functionality for GitHub Actions users: ## Breaking changes in V6 -- Caching is now automatically enabled for npm projects when the `packageManager` field in `package.json` is set to `npm`. For other package managers, such as Yarn and pnpm, caching is disabled by default and must be configured manually using the `cache` input. +- Caching is now automatically enabled for npm projects when either the `devEngines.packageManager` field or the top-level `packageManager` field in `package.json` is set to `npm`. For other package managers, such as Yarn and pnpm, caching is disabled by default and must be configured manually using the `cache` input. ## Breaking changes in V5 @@ -71,7 +71,7 @@ See [action.yml](action.yml) # Default: '' cache: '' - # Controls automatic caching for npm. By default, caching for npm is enabled if the packageManager field in package.json specifies npm and no explicit cache input is provided. + # Controls automatic caching for npm. By default, caching for npm is enabled if either the devEngines.packageManager field or the top-level packageManager field in package.json specifies npm and no explicit cache input is provided. # To disable automatic caching for npm, set package-manager-cache to false. # default: true package-manager-cache: true @@ -189,7 +189,7 @@ steps: - run: npm test ``` -Caching for npm dependencies is automatically enabled when your `package.json` contains a `packageManager` field set to `npm` and no explicit cache input is provided. +Caching for npm dependencies is automatically enabled when your `package.json` contains either `devEngines.packageManager` field or top-level `packageManager` field set to `npm`, and no explicit cache input is provided. This behavior is controlled by the `package-manager-cache` input, which defaults to `true`. To turn off automatic caching, set `package-manager-cache` to `false`. diff --git a/action.yml b/action.yml index 22276180..73c766bc 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,7 @@ inputs: cache: description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.' package-manager-cache: - description: 'Set to false to disable automatic caching. By default, caching is enabled when npm is the specified package manager in package.json.' + description: 'Set to false to disable automatic caching. By default, caching is enabled when either devEngines.packageManager or the top-level packageManager field in package.json specifies npm as the package manager.' default: true cache-dependency-path: description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.' From 1b582346147c9d4f29a762394eb61f41c2c41324 Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Fri, 3 Oct 2025 12:50:27 +0530 Subject: [PATCH 6/9] chore: update Node.js version in workflows --- .github/workflows/check-dist.yml | 2 +- .github/workflows/e2e-cache.yml | 56 +++++++++++++++++++++++++------- .github/workflows/proxy.yml | 12 +++---- .github/workflows/versions.yml | 10 +++--- 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 64d40471..aac4cd2f 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -16,4 +16,4 @@ jobs: name: Check dist/ uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main with: - node-version: '20.x' + node-version: '24.x' diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index f1c1868b..2be7b67b 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Clean global cache @@ -42,7 +42,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Install pnpm @@ -75,7 +75,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 24] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Yarn version @@ -107,7 +107,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Update yarn @@ -139,7 +139,7 @@ jobs: name: Test yarn subprojects strategy: matrix: - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] runs-on: ubuntu-latest steps: @@ -166,7 +166,7 @@ jobs: name: Test yarn subprojects all locally managed strategy: matrix: - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] runs-on: ubuntu-latest steps: @@ -193,7 +193,7 @@ jobs: name: Test yarn subprojects some locally managed strategy: matrix: - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] runs-on: ubuntu-latest steps: @@ -220,7 +220,7 @@ jobs: name: Test yarn subprojects managed by git strategy: matrix: - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] runs-on: ubuntu-latest steps: @@ -244,14 +244,14 @@ jobs: sub2/*.lock sub3/*.lock - node-npm-package-manager-cache: - name: Test enabling cache if package manager field is present (Node ${{ matrix.node-version }}, ${{ matrix.os }}) + node-npm-packageManager-auto-cache: + name: Test auto cache with top-level packageManager runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 22] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Create package.json with packageManager field @@ -268,3 +268,37 @@ jobs: - name: Verify node and npm run: __tests__/verify-node.sh "${{ matrix.node-version }}" shell: bash + + node-npm-devEngines-auto-cache: + name: Test auto cache with devEngines.packageManager + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + node-version: [20, 22, 24] + steps: + - uses: actions/checkout@v5 + - name: Create package.json with devEngines field + run: | + echo '{ + "name": "test-project", + "version": "1.0.0", + "devEngines": { + "packageManager": { + "name": "npm", + "onFail": "error" + } + } + }' > package.json + - name: Clean global cache + run: npm cache clean --force + - name: Setup Node with caching enabled + uses: ./ + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Verify node and npm + run: __tests__/verify-node.sh "${{ matrix.node-version }}" + shell: bash diff --git a/.github/workflows/proxy.yml b/.github/workflows/proxy.yml index ab52b8fd..c5493b59 100644 --- a/.github/workflows/proxy.yml +++ b/.github/workflows/proxy.yml @@ -28,12 +28,12 @@ jobs: - uses: actions/checkout@v5 - name: Clear tool cache run: rm -rf $RUNNER_TOOL_CACHE/* - - name: Setup node 14 + - name: Setup node 24 uses: ./ with: - node-version: 14.x + node-version: 24.x - name: Verify node and npm - run: __tests__/verify-node.sh 14 + run: __tests__/verify-node.sh 24 test-bypass-proxy: runs-on: ubuntu-latest @@ -44,9 +44,9 @@ jobs: - uses: actions/checkout@v5 - name: Clear tool cache run: rm -rf $RUNNER_TOOL_CACHE/* - - name: Setup node 11 + - name: Setup node 24 uses: ./ with: - node-version: 11 + node-version: 24 - name: Verify node and npm - run: __tests__/verify-node.sh 11 + run: __tests__/verify-node.sh 24 diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index ba56f66f..ee42e38e 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Setup Node @@ -82,7 +82,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [20-nightly, 21-nightly, 18.0.0-nightly] + node-version: [20-nightly, 21-nightly, 24.0.0-nightly] steps: - uses: actions/checkout@v5 - name: Setup Node @@ -102,7 +102,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [20.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0] + node-version: [20.0.0-rc.1, 24.0.0-rc.4, 19.0.0-rc.0] steps: - uses: actions/checkout@v5 - name: Setup Node @@ -122,7 +122,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18.20.0, 20.10.0, 22.0.0] + node-version: [20.10.0, 22.0.0, 24.9.0] steps: - uses: actions/checkout@v5 - name: Setup Node @@ -139,7 +139,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [18, 20, 22, 24] + node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 - name: Setup Node and check latest From 6b226b8717f5a95a76ca0d683c6a81a027be6f24 Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Fri, 3 Oct 2025 13:59:27 +0530 Subject: [PATCH 7/9] chore: update Node.js versions in versions.yml --- .github/workflows/versions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index ee42e38e..4b83a127 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -82,7 +82,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [20-nightly, 21-nightly, 24.0.0-nightly] + node-version: [20-nightly, 25-nightly, 24.0.0-nightly] steps: - uses: actions/checkout@v5 - name: Setup Node @@ -102,7 +102,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [20.0.0-rc.1, 24.0.0-rc.4, 19.0.0-rc.0] + node-version: [20.0.0-rc.1, 24.0.0-rc.4, 25.0.0-rc.0] steps: - uses: actions/checkout@v5 - name: Setup Node From 9b3f664b71b041c596077e9e578741db4c704b1e Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Fri, 3 Oct 2025 14:07:06 +0530 Subject: [PATCH 8/9] chore: update rc Node.js version in versions.yml --- .github/workflows/versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 4b83a127..0290c826 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -102,7 +102,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest, macos-13] - node-version: [20.0.0-rc.1, 24.0.0-rc.4, 25.0.0-rc.0] + node-version: [20.0.0-rc.1, 22.14.0-rc.1, 24.0.0-rc.4] steps: - uses: actions/checkout@v5 - name: Setup Node From 232ec055d654495fdc0fb26d7d773bd3e92e11b1 Mon Sep 17 00:00:00 2001 From: Priyagupta108 Date: Fri, 3 Oct 2025 16:43:42 +0530 Subject: [PATCH 9/9] chore: switch macos-13 runner to macos-latest-large in workflow --- .github/workflows/e2e-cache.yml | 12 ++++++------ .github/workflows/versions.yml | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index 2be7b67b..ddedf39b 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -41,7 +41,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -74,7 +74,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -106,7 +106,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -250,7 +250,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -275,7 +275,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 0290c826..333e3a5b 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -34,7 +34,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest-large] node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1] steps: - uses: actions/checkout@v5 @@ -56,7 +56,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [ '20-v8-canary', @@ -81,7 +81,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20-nightly, 25-nightly, 24.0.0-nightly] steps: - uses: actions/checkout@v5 @@ -101,7 +101,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20.0.0-rc.1, 22.14.0-rc.1, 24.0.0-rc.4] steps: - uses: actions/checkout@v5 @@ -121,7 +121,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20.10.0, 22.0.0, 24.9.0] steps: - uses: actions/checkout@v5 @@ -138,7 +138,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [20, 22, 24] steps: - uses: actions/checkout@v5 @@ -156,7 +156,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version-file: [.nvmrc, .tool-versions, .tool-versions-node, package.json] steps: @@ -173,7 +173,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] steps: - uses: actions/checkout@v5 - name: Setup node from node version file @@ -188,7 +188,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] steps: - uses: actions/checkout@v5 - name: Setup node from node version file @@ -203,7 +203,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [17, 19] steps: - uses: actions/checkout@v5 @@ -220,7 +220,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest-large] steps: - uses: actions/checkout@v5 # test old versions which didn't have npm and layout different @@ -250,7 +250,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] node-version: [current, latest, node] steps: - name: Get node version