From 77f43a440004389e5ec966078985f6a3153df1da Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Thu, 10 Mar 2022 13:27:02 -0500 Subject: [PATCH 1/6] Update CODEOWNERS to actions-service --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From f3e93d1b9dbf0ec44d17b09dea3d0446dd7d25d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Mar 2022 11:54:46 +0000 Subject: [PATCH 2/6] Bump minimist from 1.2.5 to 1.2.6 Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0dff0f33..315148385 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3939,9 +3939,9 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "node_modules/ms": { @@ -8179,9 +8179,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", "dev": true }, "ms": { From bacd6b4b3ac3127b28a1e1920c23bf1c2cadbb85 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 31 Mar 2022 21:10:37 +0200 Subject: [PATCH 3/6] Caching on GHES (#452) * add support for ghes caching * fix licesnses * work on resolving comments * change internal error to warning * fix warning for internal errors * update version --- .licenses/npm/@actions/cache.dep.yml | 2 +- __tests__/cache-utils.test.ts | 54 ++++++++++++++++++---------- __tests__/installer.test.ts | 48 +++++++++++++++++++++++++ dist/cache-save/index.js | 36 ++++++++++++++++--- dist/setup/index.js | 49 +++++++++++++++++-------- package-lock.json | 26 +++++++------- package.json | 4 +-- src/cache-utils.ts | 26 ++++++++++++++ src/main.ts | 14 ++------ 9 files changed, 192 insertions(+), 67 deletions(-) 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/__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/package-lock.json b/package-lock.json index 315148385..7610fb69f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "setup-node", - "version": "2.0.0", + "version": "3.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "setup-node", - "version": "2.0.0", + "version": "3.1.0", "license": "MIT", "dependencies": { - "@actions/cache": "^1.0.8", + "@actions/cache": "^2.0.0", "@actions/core": "^1.6.0", "@actions/exec": "^1.1.0", "@actions/github": "^1.1.0", @@ -32,17 +32,17 @@ } }, "node_modules/@actions/cache": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-1.0.8.tgz", - "integrity": "sha512-GWNNB67w93HGJRQXlsV56YqrdAuDoP3esK/mo5mzU8WoDCVjtQgJGsTdkYUX7brswtT7xnI30bWNo1WLKQ8FZQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.0.tgz", + "integrity": "sha512-d7n8ul6HjWX6oDrNEPoqn8ZvqyyDhp9Uek6WOxALyxGVsXU+8+ND+viD3UfrXVWfs/GQiqI5Eq4cOozZj0yRFQ==", "dependencies": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.1", "@actions/glob": "^0.1.0", "@actions/http-client": "^1.0.9", "@actions/io": "^1.0.1", - "@azure/ms-rest-js": "^2.0.7", - "@azure/storage-blob": "^12.1.2", + "@azure/ms-rest-js": "^2.6.0", + "@azure/storage-blob": "^12.8.0", "semver": "^6.1.0", "uuid": "^3.3.3" } @@ -5077,17 +5077,17 @@ }, "dependencies": { "@actions/cache": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-1.0.8.tgz", - "integrity": "sha512-GWNNB67w93HGJRQXlsV56YqrdAuDoP3esK/mo5mzU8WoDCVjtQgJGsTdkYUX7brswtT7xnI30bWNo1WLKQ8FZQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.0.tgz", + "integrity": "sha512-d7n8ul6HjWX6oDrNEPoqn8ZvqyyDhp9Uek6WOxALyxGVsXU+8+ND+viD3UfrXVWfs/GQiqI5Eq4cOozZj0yRFQ==", "requires": { "@actions/core": "^1.2.6", "@actions/exec": "^1.0.1", "@actions/glob": "^0.1.0", "@actions/http-client": "^1.0.9", "@actions/io": "^1.0.1", - "@azure/ms-rest-js": "^2.0.7", - "@azure/storage-blob": "^12.1.2", + "@azure/ms-rest-js": "^2.6.0", + "@azure/storage-blob": "^12.8.0", "semver": "^6.1.0", "uuid": "^3.3.3" }, diff --git a/package.json b/package.json index 8c6eee0ce..03f0241b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-node", - "version": "2.0.0", + "version": "3.1.0", "private": true, "description": "setup node action", "main": "lib/setup-node.js", @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/cache": "^1.0.8", + "@actions/cache": "^2.0.0", "@actions/core": "^1.6.0", "@actions/exec": "^1.1.0", "@actions/github": "^1.1.0", diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 36531bd58..b71bcc8ac 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; +import * as cache from '@actions/cache'; type SupportedPackageManagers = { [prop: string]: PackageManagerInfo; @@ -95,3 +96,28 @@ export const getCacheDirectoryPath = async ( return stdOut; }; + +export function isGhes(): boolean { + const ghUrl = new URL( + process.env['GITHUB_SERVER_URL'] || 'https://github.com' + ); + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; +} + +export function isCacheFeatureAvailable(): boolean { + 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; +} diff --git a/src/main.ts b/src/main.ts index 2de86ca8e..3c5661b55 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,7 @@ import fs from 'fs'; import * as auth from './authutil'; import * as path from 'path'; import {restoreCache} from './cache-restore'; -import {URL} from 'url'; +import {isGhes, isCacheFeatureAvailable} from './cache-utils'; import os = require('os'); export async function run() { @@ -45,10 +45,7 @@ export async function run() { auth.configAuthentication(registryUrl, alwaysAuth); } - if (cache) { - if (isGhes()) { - throw new Error('Caching is not supported on GHES'); - } + if (cache && isCacheFeatureAvailable()) { const cacheDependencyPath = core.getInput('cache-dependency-path'); await restoreCache(cache, cacheDependencyPath); } @@ -66,13 +63,6 @@ export async function run() { } } -function isGhes(): boolean { - const ghUrl = new URL( - process.env['GITHUB_SERVER_URL'] || 'https://github.com' - ); - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; -} - function resolveVersionInput(): string { let version = core.getInput('node-version'); const versionFileInput = core.getInput('node-version-file'); From 546fd45825c7f5d63e19e4595c08c16d66bcbad9 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Fri, 1 Apr 2022 06:14:07 +1100 Subject: [PATCH 4/6] Updated documentation/workflows to use `actions/setup-node@v3` (#433) * Update documentation `actions/setup-node@v2` -> `actions/setup-node@v3` * Bump workflows to `actions/setup-node@v3` * Update `README.md` workflow status badges to new format --- .github/workflows/build-test.yml | 6 +++--- .github/workflows/check-dist.yml | 4 ++-- README.md | 24 +++++++++++----------- docs/advanced-usage.md | 34 ++++++++++++++++---------------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 52f024e0c..3987bad59 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -19,12 +19,12 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v2 - - name: Setup node 16 - uses: actions/setup-node@v2 + - 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..43561fdb0 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -23,8 +23,8 @@ jobs: steps: - uses: actions/checkout@v2 - - 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 diff --git a/README.md b/README.md index a21ccffc7..180b12020 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # setup-node -

- build-test status versions status proxy status -

+[![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: @@ -19,25 +19,26 @@ See [action.yml](action.yml) ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- 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 @@ -51,7 +52,7 @@ See the examples of using cache for `yarn` / `pnpm` and `cache-dependency-path` ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -63,7 +64,7 @@ steps: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -73,6 +74,7 @@ steps: ``` ## Matrix Testing: + ```yaml jobs: build: @@ -84,7 +86,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Setup node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - run: npm install diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 960772f5c..49da5ccd9 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -11,7 +11,7 @@ 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/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/setup-node@v3 with: node-version-file: '.nvmrc' - run: npm install @@ -47,7 +47,7 @@ jobs: name: Node sample steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - 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/setup-node@v3 with: node-version: '14' cache: 'yarn' @@ -85,7 +85,7 @@ steps: - 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' @@ -97,7 +97,7 @@ steps: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -110,7 +110,7 @@ steps: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14' cache: 'npm' @@ -148,7 +148,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Setup node - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} architecture: ${{ matrix.architecture }} @@ -160,7 +160,7 @@ jobs: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- 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 @@ -180,7 +180,7 @@ steps: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14.x' registry-url: @@ -188,7 +188,7 @@ steps: - run: yarn publish env: NODE_AUTH_TOKEN: ${{ secrets.YARN_TOKEN }} -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: registry-url: 'https://npm.pkg.github.com' - run: yarn publish @@ -200,7 +200,7 @@ steps: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v3 with: node-version: '14.x' registry-url: 'https://registry.npmjs.org' From 75716637dc8cd06e88621003df6357fdcee67772 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Fri, 1 Apr 2022 19:13:52 +1100 Subject: [PATCH 5/6] Bump to `actions/checkout@v3` (#437) --- .github/workflows/build-test.yml | 2 +- .github/workflows/check-dist.yml | 4 ++-- .github/workflows/e2e-cache.yml | 10 +++++----- .github/workflows/licensed.yml | 2 +- .github/workflows/proxy.yml | 4 ++-- .github/workflows/versions.yml | 22 +++++++++++----------- README.md | 12 ++++++++---- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 3987bad59..61abfb4b9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -18,7 +18,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node 16.x uses: actions/setup-node@v3 with: diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 43561fdb0..e5612d299 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Node 16.x uses: actions/setup-node@v3 @@ -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/README.md b/README.md index 180b12020..4cf8ba4ff 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,10 @@ This action provides the following functionality for GitHub Actions users: See [action.yml](action.yml) **Basic:** + ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -49,9 +50,10 @@ 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/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -61,9 +63,10 @@ steps: ``` **Caching npm dependencies in monorepos:** + ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -84,7 +87,7 @@ 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@v3 with: @@ -92,6 +95,7 @@ jobs: - run: npm install - run: npm test ``` + ## Advanced usage 1. [Check latest version](docs/advanced-usage.md#check-latest-version) From 5b52f097d36d4b0b2f94ed6de710023fbb8b2236 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Fri, 1 Apr 2022 19:41:49 +1100 Subject: [PATCH 6/6] Bump `actions/checkout@v3` within advanced usage examples documentation (#456) --- docs/advanced-usage.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 49da5ccd9..043e2a174 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -10,7 +10,7 @@ If `check-latest` is set to `true`, the action first checks if the cached versio ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -27,7 +27,7 @@ See [supported version syntax](https://github.com/actions/setup-node#supported-v ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' @@ -46,7 +46,7 @@ jobs: runs-on: windows-latest name: Node sample steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -62,7 +62,7 @@ The action follows [actions/cache](https://github.com/actions/cache/blob/main/ex Yarn caching handles both yarn versions: 1 or 2. ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -81,7 +81,7 @@ 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 @@ -96,7 +96,7 @@ steps: **Using wildcard patterns to cache dependencies** ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -109,7 +109,7 @@ steps: **Using a list of file paths to cache dependencies** ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' @@ -146,7 +146,7 @@ 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@v3 with: @@ -159,7 +159,7 @@ jobs: ## Publish to npmjs and GPR with npm ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14.x' @@ -179,7 +179,7 @@ steps: ## Publish to npmjs and GPR with yarn ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14.x' @@ -199,7 +199,7 @@ steps: ## Use private packages ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14.x'