diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 52f024e0c..61abfb4b9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -18,13 +18,13 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v2 - - name: Setup node 16 - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - name: Setup Node 16.x + uses: actions/setup-node@v3 with: node-version: 16.x cache: npm - run: npm ci - run: npm run build - run: npm run format-check - - run: npm test \ No newline at end of file + - run: npm test diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index bc0b72ba7..e5612d299 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -21,10 +21,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Set Node.js 16.x - uses: actions/setup-node@v2 + - name: Setup Node 16.x + uses: actions/setup-node@v3 with: node-version: 16.x cache: npm @@ -45,7 +45,7 @@ jobs: id: diff # If index.js was different than expected, upload the expected version as an artifact - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{ failure() && steps.diff.conclusion == 'failure' }} with: name: dist diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index 69e75fece..87d6d4d30 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -10,7 +10,7 @@ on: - releases/* paths-ignore: - '**.md' - + jobs: node-npm-depencies-caching: name: Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) @@ -21,7 +21,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [12, 14, 16] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Clean global cache run: npm cache clean --force - name: Setup Node @@ -44,7 +44,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [12, 14, 16] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install pnpm uses: pnpm/action-setup@v2 with: @@ -77,7 +77,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [12, 14, 16] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Yarn version run: yarn --version - name: Generate yarn file @@ -109,7 +109,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [12, 14, 16] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Update yarn run: yarn set version berry - name: Yarn version diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml index 38399a61e..a98d6b565 100644 --- a/.github/workflows/licensed.yml +++ b/.github/workflows/licensed.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest name: Check licenses steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - run: npm ci - name: Install licensed run: | diff --git a/.github/workflows/proxy.yml b/.github/workflows/proxy.yml index c77e74fdc..2aef32332 100644 --- a/.github/workflows/proxy.yml +++ b/.github/workflows/proxy.yml @@ -25,7 +25,7 @@ jobs: env: https_proxy: http://squid-proxy:3128 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Clear tool cache run: rm -rf $RUNNER_TOOL_CACHE/* - name: Setup node 14 @@ -41,7 +41,7 @@ jobs: https_proxy: http://no-such-proxy:3128 no_proxy: api.github.com,github.com,nodejs.org,registry.npmjs.org,*.s3.amazonaws.com,s3.amazonaws.com steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Clear tool cache run: rm -rf $RUNNER_TOOL_CACHE/* - name: Setup node 11 diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 459f33cdc..d13fe4024 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -3,14 +3,14 @@ name: versions on: pull_request: paths-ignore: - - '**.md' - push: + - '**.md' + push: branches: - main - releases/* paths-ignore: - '**.md' - + jobs: local-cache: runs-on: ${{ matrix.os }} @@ -20,7 +20,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [10, 12, 14] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node uses: ./ with: @@ -37,7 +37,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node uses: ./ with: @@ -51,7 +51,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [10.15, 12.16.0, 14.2.0, 16.3.0] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node uses: ./ with: @@ -68,7 +68,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [10, 12, 14] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node and check latest uses: ./ with: @@ -85,7 +85,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup node from node version file uses: ./ with: @@ -101,7 +101,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [11, 13] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node from dist uses: ./ with: @@ -117,7 +117,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # test old versions which didn't have npm and layout different - name: Setup node 0.12.18 from dist uses: ./ @@ -130,7 +130,7 @@ jobs: arch: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup node 14 x86 from dist uses: ./ with: diff --git a/.licenses/npm/@actions/cache.dep.yml b/.licenses/npm/@actions/cache.dep.yml index c2d23e2e3..35b0a4bf1 100644 --- a/.licenses/npm/@actions/cache.dep.yml +++ b/.licenses/npm/@actions/cache.dep.yml @@ -1,6 +1,6 @@ --- name: "@actions/cache" -version: 1.0.8 +version: 2.0.0 type: npm summary: Actions cache lib homepage: https://github.com/actions/toolkit/tree/main/packages/cache diff --git a/CODEOWNERS b/CODEOWNERS index a39dda04c..9ec45a506 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @actions/spark \ No newline at end of file +* @actions/actions-service diff --git a/README.md b/README.md index a21ccffc7..4cf8ba4ff 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # setup-node -
+[![build-test](https://github.com/actions/setup-node/actions/workflows/build-test.yml/badge.svg)](https://github.com/actions/setup-node/actions/workflows/build-test.yml) +[![versions](https://github.com/actions/setup-node/actions/workflows/versions.yml/badge.svg)](https://github.com/actions/setup-node/actions/workflows/versions.yml) +[![proxy](https://github.com/actions/setup-node/actions/workflows/proxy.yml/badge.svg)](https://github.com/actions/setup-node/actions/workflows/proxy.yml) This action provides the following functionality for GitHub Actions users: @@ -16,28 +16,30 @@ This action provides the following functionality for GitHub Actions users: See [action.yml](action.yml) **Basic:** + ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' - run: npm install - 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 don't 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/). For information regarding locally cached versions of Node.js on GitHub hosted runners, check out [GitHub Actions Virtual Environments](https://github.com/actions/virtual-environments). #### Supported version syntax + The `node-version` input supports the following syntax: -major versions: `12`, `14`, `16` -more specific versions: `10.15`, `14.2.0`, `16.3.0` -nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*` +major versions: `12`, `14`, `16` +more specific versions: `10.15`, `14.2.0`, `16.3.0` +nvm lts syntax: `lts/erbium`, `lts/fermium`, `lts/*` ## Caching packages dependencies @@ -48,10 +50,11 @@ The action defaults to search for the dependency file (`package-lock.json` or `y 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. **Caching npm dependencies:** + ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -60,10 +63,11 @@ steps: ``` **Caching npm dependencies in monorepos:** + ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -73,6 +77,7 @@ steps: ``` ## Matrix Testing: + ```yaml jobs: build: @@ -82,14 +87,15 @@ jobs: node: [ '12', '14', '16' ] name: Node ${{ matrix.node }} sample steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - run: npm install - run: npm test ``` + ## Advanced usage 1. [Check latest version](docs/advanced-usage.md#check-latest-version) diff --git a/__tests__/cache-utils.test.ts b/__tests__/cache-utils.test.ts index 0ceabeb09..d8934ebaa 100644 --- a/__tests__/cache-utils.test.ts +++ b/__tests__/cache-utils.test.ts @@ -1,37 +1,28 @@ import * as core from '@actions/core'; +import * as cache from '@actions/cache'; import path from 'path'; import * as utils from '../src/cache-utils'; -import {PackageManagerInfo} from '../src/cache-utils'; +import {PackageManagerInfo, isCacheFeatureAvailable} from '../src/cache-utils'; describe('cache-utils', () => { - const commonPath = '/some/random/path'; const versionYarn1 = '1.2.3'; - const versionYarn2 = '2.3.4'; let debugSpy: jest.SpyInstance; let getCommandOutputSpy: jest.SpyInstance; - - function getPackagePath(name: string) { - if (name === utils.supportedPackageManagers.npm.getCacheFolderCommand) { - return `${commonPath}/npm`; - } else if ( - name === utils.supportedPackageManagers.pnpm.getCacheFolderCommand - ) { - return `${commonPath}/pnpm`; - } else { - if (name === utils.supportedPackageManagers.yarn1.getCacheFolderCommand) { - return `${commonPath}/yarn1`; - } else { - return `${commonPath}/yarn2`; - } - } - } + let isFeatureAvailable: jest.SpyInstance; + let info: jest.SpyInstance; + let warningSpy: jest.SpyInstance; beforeEach(() => { process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); debugSpy = jest.spyOn(core, 'debug'); debugSpy.mockImplementation(msg => {}); + info = jest.spyOn(core, 'info'); + warningSpy = jest.spyOn(core, 'warning'); + + isFeatureAvailable = jest.spyOn(cache, 'isFeatureAvailable'); + getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput'); }); @@ -51,7 +42,32 @@ describe('cache-utils', () => { }); }); + it('isCacheFeatureAvailable for GHES is false', () => { + isFeatureAvailable.mockImplementation(() => false); + process.env['GITHUB_SERVER_URL'] = 'https://www.test.com'; + + expect(() => isCacheFeatureAvailable()).toThrowError( + 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' + ); + }); + + it('isCacheFeatureAvailable for GHES has an interhal error', () => { + isFeatureAvailable.mockImplementation(() => false); + process.env['GITHUB_SERVER_URL'] = ''; + isCacheFeatureAvailable(); + expect(warningSpy).toHaveBeenCalledWith( + 'The runner was not able to contact the cache service. Caching will be skipped' + ); + }); + + it('isCacheFeatureAvailable for GHES is available', () => { + isFeatureAvailable.mockImplementation(() => true); + + expect(isCacheFeatureAvailable()).toStrictEqual(true); + }); + afterEach(() => { + process.env['GITHUB_SERVER_URL'] = ''; jest.resetAllMocks(); jest.clearAllMocks(); }); diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 4565dd4ce..19692cf27 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core'; import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; import * as im from '../src/installer'; +import * as cache from '@actions/cache'; import fs from 'fs'; import cp from 'child_process'; import osm = require('os'); @@ -36,6 +37,7 @@ describe('setup-node', () => { let execSpy: jest.SpyInstance; let authSpy: jest.SpyInstance; let parseNodeVersionSpy: jest.SpyInstance; + let isCacheActionAvailable: jest.SpyInstance; beforeEach(() => { // @actions/core @@ -67,6 +69,9 @@ describe('setup-node', () => { existsSpy = jest.spyOn(fs, 'existsSync'); mkdirpSpy = jest.spyOn(io, 'mkdirP'); + // @actions/tool-cache + isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable'); + // disable authentication portion for installer tests authSpy = jest.spyOn(auth, 'configAuthentication'); authSpy.mockImplementation(() => {}); @@ -644,6 +649,49 @@ describe('setup-node', () => { ); }); }); + + describe('cache on GHES', () => { + it('Should throw an error, because cache is not supported', async () => { + inputs['node-version'] = '12'; + inputs['cache'] = 'npm'; + + inSpy.mockImplementation(name => inputs[name]); + + let toolPath = path.normalize('/cache/node/12.16.1/x64'); + findSpy.mockImplementation(() => toolPath); + + // expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); + process.env['GITHUB_SERVER_URL'] = 'https://www.test.com'; + isCacheActionAvailable.mockImplementation(() => false); + + await main.run(); + + expect(cnSpy).toHaveBeenCalledWith( + `::error::Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.${osm.EOL}` + ); + }); + + it('Should throw an internal error', async () => { + inputs['node-version'] = '12'; + inputs['cache'] = 'npm'; + + inSpy.mockImplementation(name => inputs[name]); + + let toolPath = path.normalize('/cache/node/12.16.1/x64'); + findSpy.mockImplementation(() => toolPath); + + // expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); + process.env['GITHUB_SERVER_URL'] = ''; + isCacheActionAvailable.mockImplementation(() => false); + + await main.run(); + + expect(warningSpy).toHaveBeenCalledWith( + 'The runner was not able to contact the cache service. Caching will be skipped' + ); + }); + }); + describe('LTS version', () => { beforeEach(() => { os.platform = 'linux'; diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index e29e4f871..5836c4a0a 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -3139,10 +3139,7 @@ const options_1 = __webpack_require__(248); const requestUtils_1 = __webpack_require__(826); const versionSalt = '1.0'; function getCacheApiUrl(resource) { - // Ideally we just use ACTIONS_CACHE_URL - const baseUrl = (process.env['ACTIONS_CACHE_URL'] || - process.env['ACTIONS_RUNTIME_URL'] || - '').replace('pipelines', 'artifactcache'); + const baseUrl = process.env['ACTIONS_CACHE_URL'] || ''; if (!baseUrl) { throw new Error('Cache Service Url not found, unable to restore cache.'); } @@ -3811,6 +3808,7 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(470)); const exec = __importStar(__webpack_require__(986)); +const cache = __importStar(__webpack_require__(692)); exports.supportedPackageManagers = { npm: { lockFilePatterns: ['package-lock.json', 'yarn.lock'], @@ -3875,6 +3873,24 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite core.debug(`${packageManager} path is ${stdOut}`); return stdOut; }); +function isGhes() { + const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; +} +exports.isGhes = isGhes; +function isCacheFeatureAvailable() { + if (!cache.isFeatureAvailable()) { + if (isGhes()) { + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + } + else { + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + } + return false; + } + return true; +} +exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ }), @@ -5703,7 +5719,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) { // // If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB // on 64-bit systems), split the download into multiple segments - const maxSegmentSize = buffer.constants.MAX_LENGTH; + // ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly. + const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH); const downloadProgress = new DownloadProgress(contentLength); const fd = fs.openSync(archivePath, 'w'); try { @@ -43258,6 +43275,15 @@ function checkKey(key) { throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`); } } +/** + * isFeatureAvailable to check the presence of Actions cache service + * + * @returns boolean return true if Actions cache service feature is available, otherwise false + */ +function isFeatureAvailable() { + return !!process.env['ACTIONS_CACHE_URL']; +} +exports.isFeatureAvailable = isFeatureAvailable; /** * Restores cache from keys * diff --git a/dist/setup/index.js b/dist/setup/index.js index b4b1cfdf8..19df95db3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -5410,10 +5410,7 @@ const options_1 = __webpack_require__(161); const requestUtils_1 = __webpack_require__(246); const versionSalt = '1.0'; function getCacheApiUrl(resource) { - // Ideally we just use ACTIONS_CACHE_URL - const baseUrl = (process.env['ACTIONS_CACHE_URL'] || - process.env['ACTIONS_RUNTIME_URL'] || - '').replace('pipelines', 'artifactcache'); + const baseUrl = process.env['ACTIONS_CACHE_URL'] || ''; if (!baseUrl) { throw new Error('Cache Service Url not found, unable to restore cache.'); } @@ -6588,7 +6585,7 @@ const fs_1 = __importDefault(__webpack_require__(747)); const auth = __importStar(__webpack_require__(749)); const path = __importStar(__webpack_require__(622)); const cache_restore_1 = __webpack_require__(409); -const url_1 = __webpack_require__(835); +const cache_utils_1 = __webpack_require__(570); const os = __webpack_require__(87); function run() { return __awaiter(this, void 0, void 0, function* () { @@ -6610,7 +6607,7 @@ function run() { } if (version) { let token = core.getInput('token'); - let auth = !token || isGhes() ? undefined : `token ${token}`; + let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`; let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; yield installer.getNode(version, stable, checkLatest, auth, arch); @@ -6620,10 +6617,7 @@ function run() { if (registryUrl) { auth.configAuthentication(registryUrl, alwaysAuth); } - if (cache) { - if (isGhes()) { - throw new Error('Caching is not supported on GHES'); - } + if (cache && cache_utils_1.isCacheFeatureAvailable()) { const cacheDependencyPath = core.getInput('cache-dependency-path'); yield cache_restore_1.restoreCache(cache, cacheDependencyPath); } @@ -6638,10 +6632,6 @@ function run() { }); } exports.run = run; -function isGhes() { - const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; -} function resolveVersionInput() { let version = core.getInput('node-version'); const versionFileInput = core.getInput('node-version-file'); @@ -9525,7 +9515,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) { // // If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB // on 64-bit systems), split the download into multiple segments - const maxSegmentSize = buffer.constants.MAX_LENGTH; + // ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly. + const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH); const downloadProgress = new DownloadProgress(contentLength); const fd = fs.openSync(archivePath, 'w'); try { @@ -46070,6 +46061,7 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(470)); const exec = __importStar(__webpack_require__(986)); +const cache = __importStar(__webpack_require__(638)); exports.supportedPackageManagers = { npm: { lockFilePatterns: ['package-lock.json', 'yarn.lock'], @@ -46134,6 +46126,24 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite core.debug(`${packageManager} path is ${stdOut}`); return stdOut; }); +function isGhes() { + const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; +} +exports.isGhes = isGhes; +function isCacheFeatureAvailable() { + if (!cache.isFeatureAvailable()) { + if (isGhes()) { + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + } + else { + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + } + return false; + } + return true; +} +exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /***/ }), @@ -47526,6 +47536,15 @@ function checkKey(key) { throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`); } } +/** + * isFeatureAvailable to check the presence of Actions cache service + * + * @returns boolean return true if Actions cache service feature is available, otherwise false + */ +function isFeatureAvailable() { + return !!process.env['ACTIONS_CACHE_URL']; +} +exports.isFeatureAvailable = isFeatureAvailable; /** * Restores cache from keys * diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 960772f5c..043e2a174 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -10,8 +10,8 @@ If `check-latest` is set to `true`, the action first checks if the cached versio ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' check-latest: true @@ -20,15 +20,15 @@ steps: ``` ## Node version file - -The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc` or `.node-version`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used. -See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax) + +The `node-version-file` input accepts a path to a file containing the version of Node.js to be used by a project, for example `.nvmrc` or `.node-version`. If both the `node-version` and the `node-version-file` inputs are provided then the `node-version` input is used. +See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax) > The action will search for the node version file relative to the repository root. ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' - run: npm install @@ -46,8 +46,8 @@ jobs: runs-on: windows-latest name: Node sample steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: '14' architecture: 'x64' # optional, x64 or x86. If not specified, x64 will be used by default @@ -58,12 +58,12 @@ jobs: ## 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:** +**Caching yarn dependencies:** Yarn caching handles both yarn versions: 1 or 2. ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'yarn' @@ -81,11 +81,11 @@ steps: # NOTE: pnpm caching support requires pnpm version >= 6.10.0 steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2 with: version: 6.10.0 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'pnpm' @@ -96,8 +96,8 @@ steps: **Using wildcard patterns to cache dependencies** ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -109,8 +109,8 @@ steps: **Using a list of file paths to cache dependencies** ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -146,9 +146,9 @@ jobs: architecture: x86 name: Node ${{ matrix.node_version }} - ${{ matrix.architecture }} on ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} architecture: ${{ matrix.architecture }} @@ -159,8 +159,8 @@ jobs: ## Publish to npmjs and GPR with npm ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14.x' registry-url: 'https://registry.npmjs.org' @@ -168,7 +168,7 @@ steps: - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: registry-url: 'https://npm.pkg.github.com' - run: npm publish @@ -179,8 +179,8 @@ steps: ## Publish to npmjs and GPR with yarn ```yaml steps: -- uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/checkout@v3 +- uses: actions/setup-node@v3 with: node-version: '14.x' registry-url: