1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2024-11-09 15:12:40 +00:00

update readme and dist files

This commit is contained in:
Maxim Lobanov 2021-08-05 12:00:47 +00:00 committed by GitHub
parent a869e7cc2d
commit 76a4cff9ae
5 changed files with 888 additions and 876 deletions

View file

@ -39,15 +39,13 @@ major versions: `12`, `14`, `16`
more specific versions: `10.15`, `14.2.0`, `16.3.0` more specific versions: `10.15`, `14.2.0`, `16.3.0`
nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*` nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*`
### Caching packages dependencies ## Caching packages dependencies
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are `npm`, `yarn`, `pnpm` (v6.10+). The `cache` input is optional, and caching is turned off by default.
Supported package managers are `npm`, `yarn`, `pnpm`. The `cache` input is optional, and caching is turned off by default. The action defaults to search for the dependency file (`package-lock.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` 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. See the examples of `cache-dependency-path` usage in the [Advanced usage](docs/advanced-usage.md#caching-packages-dependencies) guide. See the examples of using cache for `yarn` / `pnpm` and `cache-dependency-path` input in the [Advanced usage](docs/advanced-usage.md#caching-packages-dependencies) guide.
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 npm dependencies:** **Caching npm dependencies:**
```yaml ```yaml
@ -61,42 +59,20 @@ steps:
- run: npm test - run: npm test
``` ```
**Caching yarn dependencies:** **Caching npm dependencies in monorepos:**
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: '14' node-version: '14'
cache: 'yarn' cache: 'npm'
- run: yarn install cache-dependency-path: subdir/package-lock.json
- run: yarn test - run: npm install
``` - run: npm test
Yarn caching handles both yarn versions: 1 or 2.
**Caching pnpm (v6.10+) dependencies:**
```yaml
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# NOTE: pnpm caching support requires pnpm version >= 6.10.0
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 6.10.0
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'pnpm'
- run: pnpm install
- run: pnpm test
``` ```
### Matrix Testing: ## Matrix Testing:
```yaml ```yaml
jobs: jobs:
build: build:

View file

@ -22,7 +22,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'
cache-dependency-path: cache-dependency-path:
description: 'Used to specify path to a dependencies file: package-lock.json, yarn.lock, etc. Supports wildcards or an array of file names.' 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.'
# 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
# Deprecated option, do not use. Will not be supported after October 1, 2019 # Deprecated option, do not use. Will not be supported after October 1, 2019

View file

@ -4265,87 +4265,87 @@ exports.debug = debug; // for test
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod; result["default"] = mod;
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const exec = __importStar(__webpack_require__(986)); const exec = __importStar(__webpack_require__(986));
exports.supportedPackageManagers = { exports.supportedPackageManagers = {
npm: { npm: {
lockFilePatterns: ['package-lock.json', 'yarn.lock'], lockFilePatterns: ['package-lock.json', 'yarn.lock'],
getCacheFolderCommand: 'npm config get cache' getCacheFolderCommand: 'npm config get cache'
}, },
pnpm: { pnpm: {
lockFilePatterns: ['pnpm-lock.yaml'], lockFilePatterns: ['pnpm-lock.yaml'],
getCacheFolderCommand: 'pnpm store path' getCacheFolderCommand: 'pnpm store path'
}, },
yarn1: { yarn1: {
lockFilePatterns: ['yarn.lock'], lockFilePatterns: ['yarn.lock'],
getCacheFolderCommand: 'yarn cache dir' getCacheFolderCommand: 'yarn cache dir'
}, },
yarn2: { yarn2: {
lockFilePatterns: ['yarn.lock'], lockFilePatterns: ['yarn.lock'],
getCacheFolderCommand: 'yarn config get cacheFolder' getCacheFolderCommand: 'yarn config get cacheFolder'
} }
}; };
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () { exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand); const { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand);
if (stderr) { if (stderr) {
throw new Error(stderr); throw new Error(stderr);
} }
return stdout.trim(); return stdout.trim();
}); });
const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () { const getPackageManagerVersion = (packageManager, command) => __awaiter(void 0, void 0, void 0, function* () {
const stdOut = yield exports.getCommandOutput(`${packageManager} ${command}`); const stdOut = yield exports.getCommandOutput(`${packageManager} ${command}`);
if (!stdOut) { if (!stdOut) {
throw new Error(`Could not retrieve version of ${packageManager}`); throw new Error(`Could not retrieve version of ${packageManager}`);
} }
return stdOut; return stdOut;
}); });
exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
if (packageManager === 'npm') { if (packageManager === 'npm') {
return exports.supportedPackageManagers.npm; return exports.supportedPackageManagers.npm;
} }
else if (packageManager === 'pnpm') { else if (packageManager === 'pnpm') {
return exports.supportedPackageManagers.pnpm; return exports.supportedPackageManagers.pnpm;
} }
else if (packageManager === 'yarn') { else if (packageManager === 'yarn') {
const yarnVersion = yield getPackageManagerVersion('yarn', '--version'); const yarnVersion = yield getPackageManagerVersion('yarn', '--version');
core.debug(`Consumed yarn version is ${yarnVersion}`); core.debug(`Consumed yarn version is ${yarnVersion}`);
if (yarnVersion.startsWith('1.')) { if (yarnVersion.startsWith('1.')) {
return exports.supportedPackageManagers.yarn1; return exports.supportedPackageManagers.yarn1;
} }
else { else {
return exports.supportedPackageManagers.yarn2; return exports.supportedPackageManagers.yarn2;
} }
} }
else { else {
return null; return null;
} }
}); });
exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaiter(void 0, void 0, void 0, function* () { exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaiter(void 0, void 0, void 0, function* () {
const stdOut = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand); const stdOut = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
if (!stdOut) { if (!stdOut) {
throw new Error(`Could not get cache folder path for ${packageManager}`); throw new Error(`Could not get cache folder path for ${packageManager}`);
} }
core.debug(`${packageManager} path is ${stdOut}`); core.debug(`${packageManager} path is ${stdOut}`);
return stdOut; return stdOut;
}); });
/***/ }), /***/ }),
@ -5272,23 +5272,23 @@ module.exports = v1;
/***/ (function(__unusedmodule, exports) { /***/ (function(__unusedmodule, exports) {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
var LockType; var LockType;
(function (LockType) { (function (LockType) {
LockType["Npm"] = "npm"; LockType["Npm"] = "npm";
LockType["Pnpm"] = "pnpm"; LockType["Pnpm"] = "pnpm";
LockType["Yarn"] = "yarn"; LockType["Yarn"] = "yarn";
})(LockType = exports.LockType || (exports.LockType = {})); })(LockType = exports.LockType || (exports.LockType = {}));
var State; var State;
(function (State) { (function (State) {
State["CachePrimaryKey"] = "CACHE_KEY"; State["CachePrimaryKey"] = "CACHE_KEY";
State["CacheMatchedKey"] = "CACHE_RESULT"; State["CacheMatchedKey"] = "CACHE_RESULT";
})(State = exports.State || (exports.State = {})); })(State = exports.State || (exports.State = {}));
var Outputs; var Outputs;
(function (Outputs) { (function (Outputs) {
Outputs["CacheHit"] = "cache-hit"; Outputs["CacheHit"] = "cache-hit";
})(Outputs = exports.Outputs || (exports.Outputs = {})); })(Outputs = exports.Outputs || (exports.Outputs = {}));
/***/ }), /***/ }),
@ -50588,77 +50588,77 @@ module.exports = require("stream");
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod; result["default"] = mod;
return result; return result;
}; };
var __importDefault = (this && this.__importDefault) || function (mod) { 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 });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const cache = __importStar(__webpack_require__(692)); const cache = __importStar(__webpack_require__(692));
const fs_1 = __importDefault(__webpack_require__(747)); const fs_1 = __importDefault(__webpack_require__(747));
const constants_1 = __webpack_require__(196); const constants_1 = __webpack_require__(196);
const cache_utils_1 = __webpack_require__(143); const cache_utils_1 = __webpack_require__(143);
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const cacheLock = core.getInput('cache'); const cacheLock = core.getInput('cache');
yield cachePackages(cacheLock); yield cachePackages(cacheLock);
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
}); });
} }
exports.run = run; exports.run = run;
const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
const state = core.getState(constants_1.State.CacheMatchedKey); const state = core.getState(constants_1.State.CacheMatchedKey);
const primaryKey = core.getState(constants_1.State.CachePrimaryKey); const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
if (!packageManagerInfo) { if (!packageManagerInfo) {
core.debug(`Caching for '${packageManager}' is not supported`); core.debug(`Caching for '${packageManager}' is not supported`);
return; return;
} }
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo, packageManager); const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo, packageManager);
if (!fs_1.default.existsSync(cachePath)) { if (!fs_1.default.existsSync(cachePath)) {
throw new Error(`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePath}`); throw new Error(`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePath}`);
} }
if (primaryKey === state) { if (primaryKey === state) {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
return; return;
} }
try { try {
yield cache.saveCache([cachePath], primaryKey); yield cache.saveCache([cachePath], primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`); core.info(`Cache saved with the key: ${primaryKey}`);
} }
catch (error) { catch (error) {
if (error.name === cache.ValidationError.name) { if (error.name === cache.ValidationError.name) {
throw error; throw error;
} }
else if (error.name === cache.ReserveCacheError.name) { else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message); core.info(error.message);
} }
else { else {
core.warning(`${error.message}`); core.warning(`${error.message}`);
} }
} }
}); });
run(); run();
/***/ }), /***/ }),

1330
dist/setup/index.js vendored

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
# Advanced usage # Advanced usage
### Check latest version ## Check latest version
The `check-latest` flag defaults to `false`. When set to `false`, 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/). Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific version of Node.js is always used. The `check-latest` flag defaults to `false`. When set to `false`, 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/). Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific version of Node.js is always used.
@ -19,7 +19,7 @@ steps:
- run: npm test - run: npm test
``` ```
### Architecture ## Architecture
You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms). You can use any of the [supported operating systems](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).
@ -39,7 +39,43 @@ jobs:
- run: npm test - run: npm test
``` ```
### Caching packages dependencies ## Caching packages dependencies
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.
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'yarn'
- run: yarn install
- run: yarn test
```
**Caching pnpm (v6.10+) dependencies:**
```yaml
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# NOTE: pnpm caching support requires pnpm version >= 6.10.0
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
with:
version: 6.10.0
- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'pnpm'
- run: pnpm install
- run: pnpm test
```
**Using wildcard patterns to cache dependencies** **Using wildcard patterns to cache dependencies**
```yaml ```yaml
@ -69,7 +105,7 @@ steps:
- run: npm test - run: npm test
``` ```
### Multiple Operating Systems and Architectures ## Multiple Operating Systems and Architectures
```yaml ```yaml
jobs: jobs:
@ -104,7 +140,7 @@ jobs:
- run: npm test - run: npm test
``` ```
### Publish to npmjs and GPR with npm ## Publish to npmjs and GPR with npm
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -124,7 +160,7 @@ steps:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
### Publish to npmjs and GPR with yarn ## Publish to npmjs and GPR with yarn
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -144,7 +180,7 @@ steps:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
### Use private packages ## Use private packages
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2