Merge 8f225c52cefbe00b1b057a8d90d498255aa9cbdb into 89d709d423dc495668cd762a18dd4a070611be3f

This commit is contained in:
Priya Gupta 2025-09-26 08:01:09 +00:00 committed by GitHub
commit 4f481c88d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 233 additions and 109 deletions

View File

@ -14,8 +14,8 @@ This action provides the following functionality for GitHub Actions users:
## Breaking changes in V5 ## Breaking changes in V5
- Enabled caching by default with package manager detection if no cache input is provided. - 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 by setting `package-manager-cache: false` when caching is not needed for secure operation. > 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. - 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) > 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: '' # Default: ''
cache: '' 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 # default: true
package-manager-cache: true package-manager-cache: true
@ -115,7 +116,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: 18 node-version: 24
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@ -132,8 +133,8 @@ The `node-version` input supports the Semantic Versioning Specification, for mor
Examples: Examples:
- Major versions: `18`, `20` - Major versions: `22`, `24`
- More specific versions: `10.15`, `16.15.1` , `18.4.0` - More specific versions: `20.19`, `22.17.1` , `24.8.0`
- NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n` - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n`
- Latest release: `*` or `latest`/`current`/`node` - 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. 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. 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` **Note:** The action does not cache `node_modules`
@ -176,7 +165,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: 20 node-version: 24
cache: 'npm' cache: 'npm'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
@ -189,13 +178,27 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: 20 node-version: 24
cache: 'npm' cache: 'npm'
cache-dependency-path: subdir/package-lock.json cache-dependency-path: subdir/package-lock.json
- run: npm ci - run: npm ci
- run: npm test - 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 ## Matrix Testing
```yaml ```yaml
@ -204,7 +207,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
node: [ 14, 16, 18 ] node: [ 20, 22, 24 ]
name: Node ${{ matrix.node }} sample name: Node ${{ matrix.node }} sample
steps: steps:
- uses: actions/checkout@v5 - 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 uses: actions/setup-node@v5
with: with:
token: ${{ secrets.GH_DOTCOM_TOKEN }} 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. 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.

View File

@ -285,34 +285,124 @@ describe('main tests', () => {
}); });
describe('cache feature 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['package-manager-cache'] = 'true';
inputs['cache'] = ''; // No cache input is provided inputs['cache'] = '';
isCacheActionAvailable.mockImplementation(() => true);
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync'); const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() => readFileSpy.mockImplementation(() =>
JSON.stringify({ JSON.stringify({
packageManager: 'yarn@3.2.0' packageManager: 'npm@10.8.2'
}) })
); );
await main.run(); 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 () => { it('Should enable caching when devEngines.packageManager.name is "npm" and cache input is not provided', async () => {
inputs['package-manager-cache'] = 'true'; inputs['package-manager-cache'] = 'true';
inputs['cache'] = ''; // No cache input is provided inputs['cache'] = '';
isCacheActionAvailable.mockImplementation(() => true);
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
const readFileSpy = jest.spyOn(fs, 'readFileSync'); const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(() => readFileSpy.mockImplementation(() =>
JSON.stringify({ 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
}) })
); );
@ -323,24 +413,18 @@ describe('main tests', () => {
it('Should skip caching when package-manager-cache is false', async () => { it('Should skip caching when package-manager-cache is false', async () => {
inputs['package-manager-cache'] = 'false'; inputs['package-manager-cache'] = 'false';
inputs['cache'] = ''; // No cache input is provided inputs['cache'] = '';
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
await main.run(); await main.run();
expect(saveStateSpy).not.toHaveBeenCalled(); expect(saveStateSpy).not.toHaveBeenCalled();
}); });
it('Should enable caching with cache input explicitly provided', async () => { it('Should enable caching with cache input explicitly provided', async () => {
inputs['package-manager-cache'] = 'true'; inputs['package-manager-cache'] = 'true';
inputs['cache'] = 'npm'; // Explicit cache input provided inputs['cache'] = 'npm';
inSpy.mockImplementation(name => inputs[name]); inSpy.mockImplementation(name => inputs[name]);
isCacheActionAvailable.mockReturnValue(true); isCacheActionAvailable.mockImplementation(() => true);
await main.run(); await main.run();
expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm'); expect(saveStateSpy).toHaveBeenCalledWith(expect.anything(), 'npm');
}); });
}); });

View File

@ -24,7 +24,7 @@ inputs:
cache: cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.' description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
package-manager-cache: 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 default: true
cache-dependency-path: 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.' 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.'

46
dist/setup/index.js vendored
View File

@ -99786,19 +99786,24 @@ function run() {
if (registryUrl) { if (registryUrl) {
auth.configAuthentication(registryUrl, alwaysAuth); auth.configAuthentication(registryUrl, alwaysAuth);
} }
const resolvedPackageManager = getNameFromPackageManagerField();
const cacheDependencyPath = core.getInput('cache-dependency-path'); const cacheDependencyPath = core.getInput('cache-dependency-path');
if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) { 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); core.saveState(constants_1.State.CachePackageManager, cache);
yield (0, cache_restore_1.restoreCache)(cache, cacheDependencyPath); 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) { else if (packagemanagercache) {
core.info("Detected package manager from package.json's packageManager field: " + const resolvedPackageManager = getNameFromPackageManagerField();
resolvedPackageManager + if (resolvedPackageManager) {
'. Auto caching has been enabled for it. If you want to disable it, set package-manager-cache input to false'); 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); core.saveState(constants_1.State.CachePackageManager, resolvedPackageManager);
yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath); yield (0, cache_restore_1.restoreCache)(resolvedPackageManager, cacheDependencyPath);
} }
}
}
const matchersPath = path.join(__dirname, '../..', '.github'); const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
core.info(`##[add-matcher]${path.join(matchersPath, 'eslint-stylish.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'eslint-stylish.json')}`);
@ -99833,19 +99838,32 @@ function resolveVersionInput() {
return version; return version;
} }
function getNameFromPackageManagerField() { function getNameFromPackageManagerField() {
// Check packageManager field in package.json var _a;
const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm']; const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..."
try { try {
const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8')); const packageJson = JSON.parse(fs_1.default.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json'), 'utf-8'));
const pm = packageJson.packageManager; // Check devEngines.packageManager first (object or array)
if (typeof pm === 'string') { const devPM = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.devEngines) === null || _a === void 0 ? void 0 : _a.packageManager;
const regex = new RegExp(`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@`); if (devPM) {
const match = pm.match(regex); if (Array.isArray(devPM)) {
return match ? match[1] : undefined; 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; return undefined;
} }
catch (err) { catch (_b) {
return undefined; return undefined;
} }
} }

View File

@ -48,7 +48,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '16' node-version: '24'
check-latest: true check-latest: true
- run: npm ci - run: npm ci
- run: npm test - run: npm test
@ -100,7 +100,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14' node-version: '24'
architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default
- run: npm ci - run: npm ci
- run: npm test - run: npm test
@ -121,7 +121,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: 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 ci
- run: npm test - run: npm test
``` ```
@ -136,7 +136,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: 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 ci
- run: npm test - run: npm test
``` ```
@ -152,7 +152,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: 'v20.1.1-v8-canary20221103f7e2421e91' node-version: 'v24.0.0-v8-canary2025030537242e55ac'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@ -172,7 +172,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: 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 ci
- run: npm test - run: npm test
``` ```
@ -188,7 +188,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: 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 ci
- run: npm test - run: npm test
``` ```
@ -204,7 +204,7 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '16.0.0-nightly20210420a0261d231c' node-version: '24.0.0-nightly202505066102159fa1'
- run: npm ci - run: npm ci
- run: npm test - run: npm test
``` ```
@ -222,24 +222,25 @@ jobs:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '16.0.0-rc.1' node-version: '24.0.0-rc.4'
- run: npm ci - run: npm ci
- run: npm test - 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 ## 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. 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:** **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 ```yaml
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14' node-version: '24'
cache: 'yarn' cache: 'yarn'
- run: yarn install --frozen-lockfile # optional, --immutable - run: yarn install --frozen-lockfile # optional, --immutable
- run: yarn test - run: yarn test
@ -256,12 +257,12 @@ steps:
steps: steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: pnpm/action-setup@v2 - uses: pnpm/action-setup@v4
with: with:
version: 6.32.9 version: 10
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14' node-version: '24'
cache: 'pnpm' cache: 'pnpm'
- run: pnpm install - run: pnpm install
- run: pnpm test - run: pnpm test
@ -277,7 +278,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14' node-version: '24'
cache: 'npm' cache: 'npm'
cache-dependency-path: '**/package-lock.json' cache-dependency-path: '**/package-lock.json'
- run: npm ci - run: npm ci
@ -290,7 +291,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14' node-version: '24'
cache: 'npm' cache: 'npm'
cache-dependency-path: | cache-dependency-path: |
server/app/package-lock.json server/app/package-lock.json
@ -312,15 +313,15 @@ jobs:
- macos-latest - macos-latest
- windows-latest - windows-latest
node_version: node_version:
- 12 - 20
- 14 - 22
- 16 - 24
architecture: architecture:
- x64 - x64
# an extra windows-x86 run: # an extra windows-x86 run:
include: include:
- os: windows-2016 - os: windows-2022
node_version: 12 node_version: 24
architecture: x86 architecture: x86
name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }}
steps: steps:
@ -340,7 +341,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14.x' node-version: '24.x'
registry-url: 'https://registry.npmjs.org' registry-url: 'https://registry.npmjs.org'
- run: npm ci - run: npm ci
- run: npm publish - run: npm publish
@ -360,7 +361,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14.x' node-version: '24.x'
registry-url: <registry url> registry-url: <registry url>
- run: yarn install --frozen-lockfile - run: yarn install --frozen-lockfile
- run: yarn publish - run: yarn publish
@ -380,7 +381,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14.x' node-version: '24.x'
registry-url: 'https://registry.npmjs.org' registry-url: 'https://registry.npmjs.org'
# Skip post-install scripts here, as a malicious # Skip post-install scripts here, as a malicious
# script could steal NODE_AUTH_TOKEN. # script could steal NODE_AUTH_TOKEN.
@ -400,7 +401,7 @@ steps:
- uses: actions/checkout@v5 - uses: actions/checkout@v5
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14.x' node-version: '24.x'
- name: Setup .yarnrc.yml - name: Setup .yarnrc.yml
run: | run: |
yarn config set npmScopes.my-org.npmRegistryServer "https://npm.pkg.github.com" 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 ```yaml
- uses: actions/setup-node@v5 - uses: actions/setup-node@v5
with: with:
node-version: '14.x' node-version: '24.x'
mirror: 'https://nodejs.org/dist' mirror: 'https://nodejs.org/dist'
mirror-token: 'your-mirror-token' mirror-token: 'your-mirror-token'
``` ```

View File

@ -67,20 +67,26 @@ export async function run() {
auth.configAuthentication(registryUrl, alwaysAuth); auth.configAuthentication(registryUrl, alwaysAuth);
} }
const resolvedPackageManager = getNameFromPackageManagerField();
const cacheDependencyPath = core.getInput('cache-dependency-path'); const cacheDependencyPath = core.getInput('cache-dependency-path');
if (cache && isCacheFeatureAvailable()) {
if (isCacheFeatureAvailable()) {
// if the cache input is provided, use it for caching.
if (cache) {
core.saveState(State.CachePackageManager, cache); core.saveState(State.CachePackageManager, cache);
await restoreCache(cache, cacheDependencyPath); await restoreCache(cache, cacheDependencyPath);
} else if (resolvedPackageManager && packagemanagercache) { // package manager npm is detected from package.json, enable auto-caching for npm.
} else if (packagemanagercache) {
const resolvedPackageManager = getNameFromPackageManagerField();
if (resolvedPackageManager) {
core.info( core.info(
"Detected package manager from package.json's packageManager field: " + "Detected npm as the package manager from package.json's packageManager field. " +
resolvedPackageManager + 'Auto caching has been enabled for npm. If you want to disable it, set package-manager-cache input to false'
'. 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); core.saveState(State.CachePackageManager, resolvedPackageManager);
await restoreCache(resolvedPackageManager, cacheDependencyPath); await restoreCache(resolvedPackageManager, cacheDependencyPath);
} }
}
}
const matchersPath = path.join(__dirname, '../..', '.github'); const matchersPath = path.join(__dirname, '../..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`); core.info(`##[add-matcher]${path.join(matchersPath, 'tsc.json')}`);
@ -132,8 +138,7 @@ function resolveVersionInput(): string {
} }
export function getNameFromPackageManagerField(): string | undefined { export function getNameFromPackageManagerField(): string | undefined {
// Check packageManager field in package.json const npmRegex = /^(\^)?npm(@.*)?$/; // matches "npm", "npm@...", "^npm@..."
const SUPPORTED_PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm'];
try { try {
const packageJson = JSON.parse( const packageJson = JSON.parse(
fs.readFileSync( fs.readFileSync(
@ -141,16 +146,29 @@ export function getNameFromPackageManagerField(): string | undefined {
'utf-8' 'utf-8'
) )
); );
const pm = packageJson.packageManager;
if (typeof pm === 'string') { // Check devEngines.packageManager first (object or array)
const regex = new RegExp( const devPM = packageJson?.devEngines?.packageManager;
`^(?:\\^)?(${SUPPORTED_PACKAGE_MANAGERS.join('|')})@` if (devPM) {
); if (Array.isArray(devPM)) {
const match = pm.match(regex); for (const obj of devPM) {
return match ? match[1] : undefined; 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; return undefined;
} catch (err) { } catch {
return undefined; return undefined;
} }
} }