mirror of
https://github.com/actions/setup-node
synced 2024-11-30 21:22:29 +08:00
Compare commits
11 Commits
9d66822df6
...
d0b35a0578
Author | SHA1 | Date | |
---|---|---|---|
|
d0b35a0578 | ||
|
39370e3970 | ||
|
0c618ceb2e | ||
|
c73bf9098a | ||
|
c871b9da45 | ||
|
802542be35 | ||
|
d8a8b93089 | ||
|
28c91a3bbc | ||
|
f9532b258e | ||
|
7c0fdd03f5 | ||
|
2936fe8cda |
38
.github/workflows/e2e-cache.yml
vendored
38
.github/workflows/e2e-cache.yml
vendored
@ -135,6 +135,44 @@ jobs:
|
|||||||
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
node-yarn4-corepack-dependencies-caching:
|
||||||
|
name: Test yarn 4 (Node ${{ matrix.node-version}}, ${{ matrix.os }})
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
YARN_ENABLE_IMMUTABLE_INSTALLS: false
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
node-version: [18, 20]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Update yarn
|
||||||
|
run: yarn set version 4.1.0
|
||||||
|
- name: Yarn version
|
||||||
|
run: yarn --version
|
||||||
|
- name: Generate simple .yarnrc.yml
|
||||||
|
run: |
|
||||||
|
echo "nodeLinker: node-modules" >> .yarnrc.yml
|
||||||
|
- name: Generate yarn file
|
||||||
|
run: yarn install
|
||||||
|
- name: Remove dependencies
|
||||||
|
shell: pwsh
|
||||||
|
run: Remove-Item node_modules -Force -Recurse
|
||||||
|
- name: Clean global cache
|
||||||
|
run: yarn cache clean --all
|
||||||
|
- name: Setup Node
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: 'yarn'
|
||||||
|
corepack: true
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn install
|
||||||
|
- name: Verify node and yarn
|
||||||
|
run: __tests__/verify-node.sh "${{ matrix.node-version }}"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
yarn-subprojects:
|
yarn-subprojects:
|
||||||
name: Test yarn subprojects
|
name: Test yarn subprojects
|
||||||
strategy:
|
strategy:
|
||||||
|
23
README.md
23
README.md
@ -26,22 +26,22 @@ See [action.yml](action.yml)
|
|||||||
node-version: ''
|
node-version: ''
|
||||||
|
|
||||||
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
|
# File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.
|
||||||
# If node-version and node-version-file are both provided the action will use version from node-version.
|
# If node-version and node-version-file are both provided the action will use version from node-version.
|
||||||
node-version-file: ''
|
node-version-file: ''
|
||||||
|
|
||||||
# Set this option if you want the action to check for the latest available version
|
# Set this option if you want the action to check for the latest available version
|
||||||
# that satisfies the version spec.
|
# that satisfies the version spec.
|
||||||
# It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen).
|
# It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen).
|
||||||
# Default: false
|
# Default: false
|
||||||
check-latest: false
|
check-latest: false
|
||||||
|
|
||||||
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
|
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
|
||||||
# Default: ''. The action use system architecture by default
|
# Default: ''. The action use system architecture by default
|
||||||
architecture: ''
|
architecture: ''
|
||||||
|
|
||||||
# Used to pull node distributions from https://github.com/actions/node-versions.
|
# Used to pull node distributions from https://github.com/actions/node-versions.
|
||||||
# Since there's a default, this is typically not supplied by the user.
|
# Since there's a default, this is typically not supplied by the user.
|
||||||
# When running this action on github.com, the default value is sufficient.
|
# When running this action on github.com, the default value is sufficient.
|
||||||
# When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
# When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
||||||
#
|
#
|
||||||
# We recommend using a service account with the least permissions necessary. Also
|
# We recommend using a service account with the least permissions necessary. Also
|
||||||
@ -57,18 +57,18 @@ See [action.yml](action.yml)
|
|||||||
# Default: ''
|
# Default: ''
|
||||||
cache: ''
|
cache: ''
|
||||||
|
|
||||||
# Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc.
|
# Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc.
|
||||||
# It will generate hash from the target file for primary key. It works only If cache is specified.
|
# It will generate hash from the target file for primary key. It works only If cache is specified.
|
||||||
# Supports wildcards or a list of file names for caching multiple dependencies.
|
# Supports wildcards or a list of file names for caching multiple dependencies.
|
||||||
# Default: ''
|
# Default: ''
|
||||||
cache-dependency-path: ''
|
cache-dependency-path: ''
|
||||||
|
|
||||||
# Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file,
|
# Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file,
|
||||||
# and set up auth to read in from env.NODE_AUTH_TOKEN.
|
# and set up auth to read in from env.NODE_AUTH_TOKEN.
|
||||||
# Default: ''
|
# Default: ''
|
||||||
registry-url: ''
|
registry-url: ''
|
||||||
|
|
||||||
# Optional scope for authenticating against scoped registries.
|
# Optional scope for authenticating against scoped registries.
|
||||||
# Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
|
# Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
|
||||||
# Default: ''
|
# Default: ''
|
||||||
scope: ''
|
scope: ''
|
||||||
@ -203,6 +203,7 @@ If the runner is not able to access github.com, any Nodejs versions requested du
|
|||||||
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
|
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
|
||||||
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
|
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
|
||||||
- [Using private packages](docs/advanced-usage.md#use-private-packages)
|
- [Using private packages](docs/advanced-usage.md#use-private-packages)
|
||||||
|
- [Enabling Corepack](docs/advanced-usage.md#enabling-corepack)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
|
import osm from 'os';
|
||||||
|
|
||||||
import * as utils from '../src/cache-utils';
|
import * as utils from '../src/cache-utils';
|
||||||
import {restoreCache} from '../src/cache-restore';
|
import {restoreCache} from '../src/cache-restore';
|
||||||
@ -12,6 +13,7 @@ describe('cache-restore', () => {
|
|||||||
process.env.RUNNER_OS = 'Linux';
|
process.env.RUNNER_OS = 'Linux';
|
||||||
}
|
}
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
|
const arch = 'arm64';
|
||||||
const commonPath = '/some/random/path';
|
const commonPath = '/some/random/path';
|
||||||
const npmCachePath = `${commonPath}/npm`;
|
const npmCachePath = `${commonPath}/npm`;
|
||||||
const pnpmCachePath = `${commonPath}/pnpm`;
|
const pnpmCachePath = `${commonPath}/pnpm`;
|
||||||
@ -52,6 +54,7 @@ describe('cache-restore', () => {
|
|||||||
let getCommandOutputSpy: jest.SpyInstance;
|
let getCommandOutputSpy: jest.SpyInstance;
|
||||||
let restoreCacheSpy: jest.SpyInstance;
|
let restoreCacheSpy: jest.SpyInstance;
|
||||||
let hashFilesSpy: jest.SpyInstance;
|
let hashFilesSpy: jest.SpyInstance;
|
||||||
|
let archSpy: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// core
|
// core
|
||||||
@ -102,6 +105,10 @@ describe('cache-restore', () => {
|
|||||||
|
|
||||||
// cache-utils
|
// cache-utils
|
||||||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
||||||
|
|
||||||
|
// os
|
||||||
|
archSpy = jest.spyOn(osm, 'arch');
|
||||||
|
archSpy.mockImplementation(() => arch);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Validate provided package manager', () => {
|
describe('Validate provided package manager', () => {
|
||||||
@ -135,7 +142,7 @@ describe('cache-restore', () => {
|
|||||||
await restoreCache(packageManager, '');
|
await restoreCache(packageManager, '');
|
||||||
expect(hashFilesSpy).toHaveBeenCalled();
|
expect(hashFilesSpy).toHaveBeenCalled();
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
|
`Cache restored from key: node-cache-${platform}-${arch}-${packageManager}-${fileHash}`
|
||||||
);
|
);
|
||||||
expect(infoSpy).not.toHaveBeenCalledWith(
|
expect(infoSpy).not.toHaveBeenCalledWith(
|
||||||
`${packageManager} cache is not found`
|
`${packageManager} cache is not found`
|
||||||
|
@ -12,6 +12,7 @@ import each from 'jest-each';
|
|||||||
|
|
||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as util from '../src/util';
|
import * as util from '../src/util';
|
||||||
|
import * as cacheUtil from '../src/cache-utils';
|
||||||
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
|
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
|
||||||
|
|
||||||
describe('main tests', () => {
|
describe('main tests', () => {
|
||||||
@ -30,6 +31,7 @@ describe('main tests', () => {
|
|||||||
let existsSpy: jest.SpyInstance;
|
let existsSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let getExecOutputSpy: jest.SpyInstance;
|
let getExecOutputSpy: jest.SpyInstance;
|
||||||
|
let getCommandOutputSpy: jest.SpyInstance;
|
||||||
|
|
||||||
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
||||||
let cnSpy: jest.SpyInstance;
|
let cnSpy: jest.SpyInstance;
|
||||||
@ -63,6 +65,7 @@ describe('main tests', () => {
|
|||||||
whichSpy = jest.spyOn(io, 'which');
|
whichSpy = jest.spyOn(io, 'which');
|
||||||
|
|
||||||
getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
|
getCommandOutputSpy = jest.spyOn(cacheUtil, 'getCommandOutput');
|
||||||
|
|
||||||
findSpy = jest.spyOn(tc, 'find');
|
findSpy = jest.spyOn(tc, 'find');
|
||||||
|
|
||||||
@ -280,4 +283,38 @@ describe('main tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('corepack flag', () => {
|
||||||
|
it('should not enable corepack when no input', async () => {
|
||||||
|
inputs['corepack'] = '';
|
||||||
|
await main.run();
|
||||||
|
expect(getCommandOutputSpy).not.toHaveBeenCalledWith(expect.stringContaining('corepack'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not enable corepack when input is "false"', async () => {
|
||||||
|
inputs['corepack'] = 'false';
|
||||||
|
await main.run();
|
||||||
|
expect(getCommandOutputSpy).not.toHaveBeenCalledWith(expect.stringContaining('corepack'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should enable corepack when input is "true"', async () => {
|
||||||
|
inputs['corepack'] = 'true';
|
||||||
|
await main.run();
|
||||||
|
expect(getCommandOutputSpy).toHaveBeenCalledWith('corepack enable');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should enable corepack with a single package manager', async () => {
|
||||||
|
inputs['corepack'] = 'npm';
|
||||||
|
await main.run();
|
||||||
|
expect(getCommandOutputSpy).toHaveBeenCalledWith('corepack enable npm');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should enable corepack with multiple package managers', async () => {
|
||||||
|
inputs['corepack'] = 'npm yarn';
|
||||||
|
await main.run();
|
||||||
|
expect(getCommandOutputSpy).toHaveBeenCalledWith(
|
||||||
|
'corepack enable npm yarn'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -25,10 +25,13 @@ inputs:
|
|||||||
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.'
|
||||||
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.'
|
||||||
|
corepack:
|
||||||
|
description: 'Used to specify whether to enable Corepack. Set to true to enable all package managers or set it to one or more package manager names separated by a space. Supported package manager names: npm, yarn, pnpm.'
|
||||||
|
default: 'false'
|
||||||
# TODO: add input to control forcing to pull from cloud or dist.
|
# TODO: add input to control forcing to pull from cloud or dist.
|
||||||
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
|
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit.'
|
description: 'A boolean value to indicate if a cache was hit.'
|
||||||
node-version:
|
node-version:
|
||||||
description: 'The installed node version.'
|
description: 'The installed node version.'
|
||||||
|
16
dist/cache-save/index.js
vendored
16
dist/cache-save/index.js
vendored
@ -84068,12 +84068,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
exports.enableCorepack = exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const io = __importStar(__nccwpck_require__(7436));
|
const io = __importStar(__nccwpck_require__(7436));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const cache_utils_1 = __nccwpck_require__(1678);
|
||||||
function getNodeVersionFromFile(versionFilePath) {
|
function getNodeVersionFromFile(versionFilePath) {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
@ -84166,6 +84167,19 @@ const unique = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
exports.unique = unique;
|
exports.unique = unique;
|
||||||
|
function enableCorepack(input) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (input.length && input !== 'false') {
|
||||||
|
const corepackArgs = ['enable'];
|
||||||
|
if (input !== 'true') {
|
||||||
|
const packageManagers = input.split(' ');
|
||||||
|
corepackArgs.push(...packageManagers);
|
||||||
|
}
|
||||||
|
yield (0, cache_utils_1.getCommandOutput)(`corepack ${corepackArgs.join(' ')}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.enableCorepack = enableCorepack;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
22
dist/setup/index.js
vendored
22
dist/setup/index.js
vendored
@ -93303,6 +93303,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const glob = __importStar(__nccwpck_require__(8090));
|
const glob = __importStar(__nccwpck_require__(8090));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const constants_1 = __nccwpck_require__(9042);
|
const constants_1 = __nccwpck_require__(9042);
|
||||||
const cache_utils_1 = __nccwpck_require__(1678);
|
const cache_utils_1 = __nccwpck_require__(1678);
|
||||||
const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
@ -93311,6 +93312,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
|
|||||||
throw new Error(`Caching for '${packageManager}' is not supported`);
|
throw new Error(`Caching for '${packageManager}' is not supported`);
|
||||||
}
|
}
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
|
const arch = os_1.default.arch();
|
||||||
const cachePaths = yield (0, cache_utils_1.getCacheDirectories)(packageManagerInfo, cacheDependencyPath);
|
const cachePaths = yield (0, cache_utils_1.getCacheDirectories)(packageManagerInfo, cacheDependencyPath);
|
||||||
core.saveState(constants_1.State.CachePaths, cachePaths);
|
core.saveState(constants_1.State.CachePaths, cachePaths);
|
||||||
const lockFilePath = cacheDependencyPath
|
const lockFilePath = cacheDependencyPath
|
||||||
@ -93320,7 +93322,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
|
|||||||
if (!fileHash) {
|
if (!fileHash) {
|
||||||
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
||||||
}
|
}
|
||||||
const keyPrefix = `node-cache-${platform}-${packageManager}`;
|
const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
|
||||||
const primaryKey = `${keyPrefix}-${fileHash}`;
|
const primaryKey = `${keyPrefix}-${fileHash}`;
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
||||||
@ -94467,6 +94469,8 @@ function run() {
|
|||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
const corepack = core.getInput('corepack') || 'false';
|
||||||
|
yield (0, util_1.enableCorepack)(corepack);
|
||||||
if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) {
|
if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) {
|
||||||
core.saveState(constants_1.State.CachePackageManager, cache);
|
core.saveState(constants_1.State.CachePackageManager, cache);
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
@ -94550,12 +94554,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
exports.enableCorepack = exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const io = __importStar(__nccwpck_require__(7436));
|
const io = __importStar(__nccwpck_require__(7436));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const cache_utils_1 = __nccwpck_require__(1678);
|
||||||
function getNodeVersionFromFile(versionFilePath) {
|
function getNodeVersionFromFile(versionFilePath) {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||||
@ -94648,6 +94653,19 @@ const unique = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
exports.unique = unique;
|
exports.unique = unique;
|
||||||
|
function enableCorepack(input) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (input.length && input !== 'false') {
|
||||||
|
const corepackArgs = ['enable'];
|
||||||
|
if (input !== 'true') {
|
||||||
|
const packageManagers = input.split(' ');
|
||||||
|
corepackArgs.push(...packageManagers);
|
||||||
|
}
|
||||||
|
yield (0, cache_utils_1.getCommandOutput)(`corepack ${corepackArgs.join(' ')}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.enableCorepack = enableCorepack;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -159,7 +159,7 @@ jobs:
|
|||||||
|
|
||||||
## Nightly versions
|
## Nightly versions
|
||||||
|
|
||||||
You can specify a nightly version to download it from https://nodejs.org/download/nightly.
|
You can specify a nightly version to download it from https://nodejs.org/download/nightly.
|
||||||
|
|
||||||
### Install the nightly build for a major version
|
### Install the nightly build for a major version
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ steps:
|
|||||||
- run: pnpm test
|
- run: pnpm test
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note**: By default `--frozen-lockfile` option is passed starting from pnpm `6.10.x`. It will be automatically added if you run it on [CI](https://pnpm.io/cli/install#--frozen-lockfile).
|
> **Note**: By default `--frozen-lockfile` option is passed starting from pnpm `6.10.x`. It will be automatically added if you run it on [CI](https://pnpm.io/cli/install#--frozen-lockfile).
|
||||||
> If the `pnpm-lock.yaml` file changes then pass `--frozen-lockfile` option.
|
> If the `pnpm-lock.yaml` file changes then pass `--frozen-lockfile` option.
|
||||||
|
|
||||||
|
|
||||||
@ -418,3 +418,30 @@ Please refer to the [Ensuring workflow access to your package - Configuring a pa
|
|||||||
|
|
||||||
### always-auth input
|
### always-auth input
|
||||||
The always-auth input sets `always-auth=true` in .npmrc file. With this option set [npm](https://docs.npmjs.com/cli/v6/using-npm/config#always-auth)/yarn sends the authentication credentials when making a request to the registries.
|
The always-auth input sets `always-auth=true` in .npmrc file. With this option set [npm](https://docs.npmjs.com/cli/v6/using-npm/config#always-auth)/yarn sends the authentication credentials when making a request to the registries.
|
||||||
|
|
||||||
|
## Enabling Corepack
|
||||||
|
You can enable [Corepack](https://github.com/nodejs/corepack) by using the `corepack` input. You can then use `pnpm` and `yarn` commands in your project.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '18.x'
|
||||||
|
corepack: true
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn install --immutable
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also pass package manager names separated by a space to enable corepack for specific package managers only.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '18.x'
|
||||||
|
corepack: yarn pnpm
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn install --immutable
|
||||||
|
```
|
||||||
|
@ -3,6 +3,7 @@ import * as core from '@actions/core';
|
|||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
import {
|
import {
|
||||||
@ -21,6 +22,7 @@ export const restoreCache = async (
|
|||||||
throw new Error(`Caching for '${packageManager}' is not supported`);
|
throw new Error(`Caching for '${packageManager}' is not supported`);
|
||||||
}
|
}
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
|
const arch = os.arch();
|
||||||
|
|
||||||
const cachePaths = await getCacheDirectories(
|
const cachePaths = await getCacheDirectories(
|
||||||
packageManagerInfo,
|
packageManagerInfo,
|
||||||
@ -38,7 +40,7 @@ export const restoreCache = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyPrefix = `node-cache-${platform}-${packageManager}`;
|
const keyPrefix = `node-cache-${platform}-${arch}-${packageManager}`;
|
||||||
const primaryKey = `${keyPrefix}-${fileHash}`;
|
const primaryKey = `${keyPrefix}-${fileHash}`;
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
|
|
||||||
|
@ -7,7 +7,11 @@ import * as path from 'path';
|
|||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {isCacheFeatureAvailable} from './cache-utils';
|
import {isCacheFeatureAvailable} from './cache-utils';
|
||||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||||
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
|
import {
|
||||||
|
getNodeVersionFromFile,
|
||||||
|
printEnvDetailsAndSetOutput,
|
||||||
|
enableCorepack
|
||||||
|
} from './util';
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
@ -59,6 +63,9 @@ export async function run() {
|
|||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const corepack = core.getInput('corepack') || 'false';
|
||||||
|
await enableCorepack(corepack);
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
core.saveState(State.CachePackageManager, cache);
|
core.saveState(State.CachePackageManager, cache);
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
|
12
src/util.ts
12
src/util.ts
@ -4,6 +4,7 @@ import * as io from '@actions/io';
|
|||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import {getCommandOutput} from './cache-utils';
|
||||||
|
|
||||||
export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
export function getNodeVersionFromFile(versionFilePath: string): string | null {
|
||||||
if (!fs.existsSync(versionFilePath)) {
|
if (!fs.existsSync(versionFilePath)) {
|
||||||
@ -106,3 +107,14 @@ export const unique = () => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function enableCorepack(input: string): Promise<void> {
|
||||||
|
if (input.length && input !== 'false') {
|
||||||
|
const corepackArgs = ['enable'];
|
||||||
|
if (input !== 'true') {
|
||||||
|
const packageManagers = input.split(' ');
|
||||||
|
corepackArgs.push(...packageManagers);
|
||||||
|
}
|
||||||
|
await getCommandOutput(`corepack ${corepackArgs.join(' ')}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user