diff --git a/.licenses/npm/@actions/http-client.dep.yml b/.licenses/npm/@actions/http-client-1.0.11.dep.yml similarity index 100% rename from .licenses/npm/@actions/http-client.dep.yml rename to .licenses/npm/@actions/http-client-1.0.11.dep.yml diff --git a/.licenses/npm/@actions/http-client-2.0.1.dep.yml b/.licenses/npm/@actions/http-client-2.0.1.dep.yml new file mode 100644 index 00000000..5c60ad35 Binary files /dev/null and b/.licenses/npm/@actions/http-client-2.0.1.dep.yml differ diff --git a/README.md b/README.md index 3b9ea0a0..6f44fdc6 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 16 - run: npm ci - run: npm test ``` @@ -39,8 +39,8 @@ The `node-version` input supports the Semantic Versioning Specification, for mor Examples: - - Major versions: `12`, `14`, `16` - - More specific versions: `10.15`, `14.2.0`, `16.3.0` + - Major versions: `14`, `16`, `18` + - More specific versions: `10.15`, `16.15.1` , `18.4.0` - NVM LTS syntax: `lts/erbium`, `lts/fermium`, `lts/*`, `lts/-n` - Latest release: `*` or `latest`/`current`/`node` @@ -58,7 +58,7 @@ It's **always** recommended to commit the lockfile of your package manager for s The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under the hood for caching global packages data 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. -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`, `npm-shrinkwrap.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. **Note:** The action does not cache `node_modules` @@ -71,7 +71,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 16 cache: 'npm' - run: npm ci - run: npm test @@ -84,7 +84,7 @@ steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 16 cache: 'npm' cache-dependency-path: subdir/package-lock.json - run: npm ci @@ -99,7 +99,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [ 12, 14, 16 ] + node: [ 14, 16, 18 ] name: Node ${{ matrix.node }} sample steps: - uses: actions/checkout@v3 diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 5a3ad553..67948a3e 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core'; import * as io from '@actions/io'; import * as tc from '@actions/tool-cache'; +import * as exec from '@actions/exec'; import * as im from '../src/installer'; import * as cache from '@actions/cache'; import fs from 'fs'; @@ -38,6 +39,7 @@ describe('setup-node', () => { let authSpy: jest.SpyInstance; let parseNodeVersionSpy: jest.SpyInstance; let isCacheActionAvailable: jest.SpyInstance; + let getExecOutputSpy: jest.SpyInstance; beforeEach(() => { // @actions/core @@ -103,6 +105,10 @@ describe('setup-node', () => { // uncomment to debug // process.stderr.write('log:' + line + '\n'); }); + + // @actions/exec + getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); + getExecOutputSpy.mockImplementation(() => 'v16.15.0'); }); afterEach(() => { diff --git a/action.yml b/action.yml index 7bed73dc..a5e4877f 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,8 @@ inputs: outputs: cache-hit: description: 'A boolean value to indicate if a cache was hit.' + node-version: + description: 'The installed node version.' runs: using: 'node16' main: 'dist/setup/index.js' diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 23a85ca5..5784552f 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -59926,7 +59926,7 @@ const exec = __importStar(__nccwpck_require__(1514)); const cache = __importStar(__nccwpck_require__(7799)); exports.supportedPackageManagers = { npm: { - lockFilePatterns: ['package-lock.json', 'yarn.lock'], + lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'], getCacheFolderCommand: 'npm config get cache' }, pnpm: { diff --git a/dist/setup/index.js b/dist/setup/index.js index ac9f4437..36ba8dd2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -71882,7 +71882,7 @@ const exec = __importStar(__nccwpck_require__(1514)); const cache = __importStar(__nccwpck_require__(7799)); exports.supportedPackageManagers = { npm: { - lockFilePatterns: ['package-lock.json', 'yarn.lock'], + lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'], getCacheFolderCommand: 'npm config get cache' }, pnpm: { @@ -72418,6 +72418,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); const core = __importStar(__nccwpck_require__(2186)); +const exec = __importStar(__nccwpck_require__(1514)); const installer = __importStar(__nccwpck_require__(2574)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const auth = __importStar(__nccwpck_require__(7573)); @@ -72450,6 +72451,9 @@ function run() { const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; yield installer.getNode(version, stable, checkLatest, auth, arch); } + // Output version of node is being used + const { stdout: installedVersion } = yield exec.getExecOutput('node', ['--version'], { ignoreReturnCode: true }); + core.setOutput('node-version', installedVersion); const registryUrl = core.getInput('registry-url'); const alwaysAuth = core.getInput('always-auth'); if (registryUrl) { diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 36c1ec8b..7e8b9c81 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -247,3 +247,5 @@ steps: # `npm rebuild` will run all those post-install scripts for us. - run: npm rebuild && npm run prepare --if-present ``` + +NOTE: As per https://github.com/actions/setup-node/issues/49 you cannot use `secrets.GITHUB_TOKEN` to access private GitHub Packages within the same organisation but in a different repository. diff --git a/package-lock.json b/package-lock.json index 938aca71..5e8bc086 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,6 +56,14 @@ "minimatch": "^3.0.4" } }, + "node_modules/@actions/cache/node_modules/@actions/http-client": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", + "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", + "dependencies": { + "tunnel": "^0.0.6" + } + }, "node_modules/@actions/cache/node_modules/uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", @@ -5119,6 +5127,14 @@ "minimatch": "^3.0.4" } }, + "@actions/http-client": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", + "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", + "requires": { + "tunnel": "^0.0.6" + } + }, "uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", diff --git a/package.json b/package.json index 7258fde2..f19d8b84 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "ncc build -o dist/setup src/setup-node.ts && ncc build -o dist/cache-save src/cache-save.ts", "format": "prettier --write **/*.ts", "format-check": "prettier --check **/*.ts", - "test": "jest", + "test": "jest --coverage", "pre-checkin": "npm run format && npm run build && npm test" }, "repository": { diff --git a/src/cache-utils.ts b/src/cache-utils.ts index b71bcc8a..4db730eb 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -13,7 +13,7 @@ export interface PackageManagerInfo { export const supportedPackageManagers: SupportedPackageManagers = { npm: { - lockFilePatterns: ['package-lock.json', 'yarn.lock'], + lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'], getCacheFolderCommand: 'npm config get cache' }, pnpm: { diff --git a/src/main.ts b/src/main.ts index 3c5661b5..5cfba617 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import * as exec from '@actions/exec'; import * as installer from './installer'; import fs from 'fs'; import * as auth from './authutil'; @@ -39,6 +40,14 @@ export async function run() { await installer.getNode(version, stable, checkLatest, auth, arch); } + // Output version of node is being used + const {stdout: installedVersion} = await exec.getExecOutput( + 'node', + ['--version'], + {ignoreReturnCode: true} + ); + core.setOutput('node-version', installedVersion); + const registryUrl: string = core.getInput('registry-url'); const alwaysAuth: string = core.getInput('always-auth'); if (registryUrl) {