mirror of
https://github.com/actions/setup-node.git
synced 2026-07-11 16:34:21 +08:00
Compare commits
2 Commits
a651f74f8e
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65431fdcf8 | ||
|
|
516db24537 |
12
README.md
12
README.md
@@ -115,7 +115,7 @@ See [action.yml](action.yml)
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 24
|
||||
@@ -123,7 +123,7 @@ steps:
|
||||
- run: npm test
|
||||
```
|
||||
|
||||
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and not rely on the system one.
|
||||
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and don't rely on the system one.
|
||||
|
||||
The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to the previous behavior of downloading directly from [node dist](https://nodejs.org/dist/).
|
||||
|
||||
@@ -164,7 +164,7 @@ See the examples of using cache for `yarn`/`pnpm` and `cache-dependency-path` in
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 24
|
||||
@@ -177,7 +177,7 @@ steps:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 24
|
||||
@@ -193,7 +193,7 @@ This behavior is controlled by the `package-manager-cache` input, which defaults
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
package-manager-cache: false
|
||||
@@ -212,7 +212,7 @@ jobs:
|
||||
node: [ 20, 22, 24 ]
|
||||
name: Node ${{ matrix.node }} sample
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v5
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
|
||||
37
dist/cache-save/index.js
vendored
37
dist/cache-save/index.js
vendored
@@ -44172,24 +44172,7 @@ exports.supportedPackageManagers = {
|
||||
name: 'yarn',
|
||||
lockFilePatterns: ['yarn.lock'],
|
||||
getCacheFolderPath: async (projectDir) => {
|
||||
// Try to enable corepack first if available
|
||||
// This helps with yarn v2+ which requires corepack
|
||||
await enableCorepackIfSupported();
|
||||
let yarnVersion;
|
||||
try {
|
||||
yarnVersion = await (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
|
||||
}
|
||||
catch (err) {
|
||||
// Check if this is a corepack error message
|
||||
const errorMsg = err.message;
|
||||
if (errorMsg.includes('packageManager') &&
|
||||
errorMsg.includes('Corepack')) {
|
||||
throw new Error(`Yarn v4+ requires corepack to be enabled. Please run 'corepack enable' before using ` +
|
||||
`actions/setup-node with yarn, or disable caching with 'package-manager-cache: false'. ` +
|
||||
`See: https://github.com/actions/setup-node/issues/1027 for more information.`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
const yarnVersion = await (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
|
||||
core.debug(`Consumed yarn version is ${yarnVersion} (working dir: "${projectDir || ''}")`);
|
||||
const stdOut = yarnVersion.startsWith('1.')
|
||||
? await (0, exports.getCommandOutput)('yarn cache dir', projectDir)
|
||||
@@ -44201,24 +44184,6 @@ exports.supportedPackageManagers = {
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Tries to enable corepack for Node.js versions that support it (16.9+)
|
||||
* This helps with yarn v2+ which requires corepack
|
||||
* See: https://github.com/actions/setup-node/issues/1027
|
||||
*/
|
||||
const enableCorepackIfSupported = async () => {
|
||||
try {
|
||||
await exec.exec('corepack', ['enable'], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
});
|
||||
core.debug('Corepack enabled successfully');
|
||||
}
|
||||
catch {
|
||||
// Corepack not available or failed silently
|
||||
core.debug('Corepack not available on this system');
|
||||
}
|
||||
};
|
||||
const getCommandOutput = async (toolCommand, cwd) => {
|
||||
let { stdout, stderr, exitCode } = await exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true, ...(cwd && { cwd }) });
|
||||
if (exitCode) {
|
||||
|
||||
37
dist/setup/index.js
vendored
37
dist/setup/index.js
vendored
@@ -53810,24 +53810,7 @@ exports.supportedPackageManagers = {
|
||||
name: 'yarn',
|
||||
lockFilePatterns: ['yarn.lock'],
|
||||
getCacheFolderPath: async (projectDir) => {
|
||||
// Try to enable corepack first if available
|
||||
// This helps with yarn v2+ which requires corepack
|
||||
await enableCorepackIfSupported();
|
||||
let yarnVersion;
|
||||
try {
|
||||
yarnVersion = await (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
|
||||
}
|
||||
catch (err) {
|
||||
// Check if this is a corepack error message
|
||||
const errorMsg = err.message;
|
||||
if (errorMsg.includes('packageManager') &&
|
||||
errorMsg.includes('Corepack')) {
|
||||
throw new Error(`Yarn v4+ requires corepack to be enabled. Please run 'corepack enable' before using ` +
|
||||
`actions/setup-node with yarn, or disable caching with 'package-manager-cache: false'. ` +
|
||||
`See: https://github.com/actions/setup-node/issues/1027 for more information.`);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
const yarnVersion = await (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
|
||||
core.debug(`Consumed yarn version is ${yarnVersion} (working dir: "${projectDir || ''}")`);
|
||||
const stdOut = yarnVersion.startsWith('1.')
|
||||
? await (0, exports.getCommandOutput)('yarn cache dir', projectDir)
|
||||
@@ -53839,24 +53822,6 @@ exports.supportedPackageManagers = {
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Tries to enable corepack for Node.js versions that support it (16.9+)
|
||||
* This helps with yarn v2+ which requires corepack
|
||||
* See: https://github.com/actions/setup-node/issues/1027
|
||||
*/
|
||||
const enableCorepackIfSupported = async () => {
|
||||
try {
|
||||
await exec.exec('corepack', ['enable'], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
});
|
||||
core.debug('Corepack enabled successfully');
|
||||
}
|
||||
catch {
|
||||
// Corepack not available or failed silently
|
||||
core.debug('Corepack not available on this system');
|
||||
}
|
||||
};
|
||||
const getCommandOutput = async (toolCommand, cwd) => {
|
||||
let { stdout, stderr, exitCode } = await exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true, ...(cwd && { cwd }) });
|
||||
if (exitCode) {
|
||||
|
||||
@@ -8,7 +8,7 @@ Currently, `actions/setup-node` supports caching dependencies for Npm and Yarn p
|
||||
For the first iteration, we have decided to not support cases where `package-lock.json` / `yarn.lock` are located outside of repository root.
|
||||
Current implementation searches the following file patterns in the repository root: `package-lock.json`, `yarn.lock` (in order of resolving priorities)
|
||||
|
||||
Obviously, it made built-in caching unusable for mono-repos and repos with complex structure.
|
||||
Obviously, it made build-in caching unusable for mono-repos and repos with complex structure.
|
||||
We would like to revisit this decision and add customization for dependencies lock file location.
|
||||
|
||||
## Proposal
|
||||
@@ -24,7 +24,7 @@ The second option looks more generic because it allows to:
|
||||
## Decision
|
||||
|
||||
Add `cache-dependency-path` input that will accept path (relative to repository root) to dependencies lock file.
|
||||
If provided path contains wildcards, the action will search all matching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does.
|
||||
If provided path contains wildcards, the action will search all maching files and calculate common hash like `${{ hashFiles('**/package-lock.json') }}` YAML construction does.
|
||||
The hash of provided matched files will be used as a part of cache key.
|
||||
|
||||
Yaml examples:
|
||||
|
||||
1542
package-lock.json
generated
1542
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -51,7 +51,7 @@
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"jest-circus": "^30.2.0",
|
||||
"jest-each": "^29.7.0",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-jest": "^29.4.1",
|
||||
|
||||
@@ -40,32 +40,11 @@ export const supportedPackageManagers: SupportedPackageManagers = {
|
||||
name: 'yarn',
|
||||
lockFilePatterns: ['yarn.lock'],
|
||||
getCacheFolderPath: async projectDir => {
|
||||
// Try to enable corepack first if available
|
||||
// This helps with yarn v2+ which requires corepack
|
||||
await enableCorepackIfSupported();
|
||||
|
||||
let yarnVersion: string;
|
||||
try {
|
||||
yarnVersion = await getCommandOutputNotEmpty(
|
||||
`yarn --version`,
|
||||
'Could not retrieve version of yarn',
|
||||
projectDir
|
||||
);
|
||||
} catch (err) {
|
||||
// Check if this is a corepack error message
|
||||
const errorMsg = (err as Error).message;
|
||||
if (
|
||||
errorMsg.includes('packageManager') &&
|
||||
errorMsg.includes('Corepack')
|
||||
) {
|
||||
throw new Error(
|
||||
`Yarn v4+ requires corepack to be enabled. Please run 'corepack enable' before using ` +
|
||||
`actions/setup-node with yarn, or disable caching with 'package-manager-cache: false'. ` +
|
||||
`See: https://github.com/actions/setup-node/issues/1027 for more information.`
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
const yarnVersion = await getCommandOutputNotEmpty(
|
||||
`yarn --version`,
|
||||
'Could not retrieve version of yarn',
|
||||
projectDir
|
||||
);
|
||||
|
||||
core.debug(
|
||||
`Consumed yarn version is ${yarnVersion} (working dir: "${
|
||||
@@ -87,24 +66,6 @@ export const supportedPackageManagers: SupportedPackageManagers = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tries to enable corepack for Node.js versions that support it (16.9+)
|
||||
* This helps with yarn v2+ which requires corepack
|
||||
* See: https://github.com/actions/setup-node/issues/1027
|
||||
*/
|
||||
const enableCorepackIfSupported = async (): Promise<void> => {
|
||||
try {
|
||||
await exec.exec('corepack', ['enable'], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
});
|
||||
core.debug('Corepack enabled successfully');
|
||||
} catch {
|
||||
// Corepack not available or failed silently
|
||||
core.debug('Corepack not available on this system');
|
||||
}
|
||||
};
|
||||
|
||||
export const getCommandOutput = async (
|
||||
toolCommand: string,
|
||||
cwd?: string
|
||||
|
||||
Reference in New Issue
Block a user