Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: actions/setup-node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.3.0
Choose a base ref
...
head repository: actions/setup-node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.4.0
Choose a head ref

Commits on May 30, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    Okeanos Nikolas Grottendieck
    Copy the full SHA
    8249676 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    dbb64ac View commit details

Commits on Jun 14, 2022

  1. 2
    Copy the full SHA
    b287e17 View commit details

Commits on Jun 17, 2022

  1. 2
    Copy the full SHA
    cdcc53e View commit details

Commits on Jun 24, 2022

  1. Update the version of @actions/cache library to 3.0.0

    IvanZosimov committed Jun 24, 2022
    Copy the full SHA
    c22fc3c View commit details
  2. Rebuild action with the new @actions/cache dependency

    IvanZosimov committed Jun 24, 2022
    Copy the full SHA
    1196f2a View commit details
  3. update licenses

    dmitry-shibanov committed Jun 24, 2022
    Copy the full SHA
    f1702f8 View commit details
  4. Copy the full SHA
    11c7f93 View commit details

Commits on Jun 26, 2022

  1. docs: Include warning when configuring token to install private packages

    The distinction between `secrets.GITHUB_TOKEN` and `secrets.NPM_TOKEN` cost myself and a colleague numerous hours when we were trying to fix a GitHub Actions workflow which needed to install a private package from a different repository from our GitHub organisation.
    
    Given the issue dedicated to this point is closed, we should include a warning here to make it more clear why `secrets.GITHUB_TOKEN` will not work when passed to `npm ci`, in the presence of private packages from other GitHub Package repositories.
    jamesottaway authored Jun 26, 2022
    Copy the full SHA
    24301fe View commit details

Commits on Jun 27, 2022

  1. Copy the full SHA
    eaead35 View commit details
  2. Copy the full SHA
    73ea510 View commit details
  3. Format cache-save.test.ts

    IvanZosimov committed Jun 27, 2022
    Copy the full SHA
    bcb9f31 View commit details

Commits on Jun 28, 2022

  1. Merge pull request #526 from IvanZosimov/CacheVersionUpdate

    Add support for the @actions/cache library 3.0.0
    marko-zivic-93 authored Jun 28, 2022
    2
    Copy the full SHA
    7d610f0 View commit details

Commits on Jun 30, 2022

  1. Copy the full SHA
    3ac35da View commit details
  2. run build&format

    panva committed Jun 30, 2022
    Copy the full SHA
    0d74188 View commit details
  3. apply review feedback

    panva committed Jun 30, 2022
    Copy the full SHA
    adeb189 View commit details
  4. Copy the full SHA
    0ad0620 View commit details
  5. Copy the full SHA
    d8b0944 View commit details
  6. fixup mocked version output

    panva committed Jun 30, 2022
    Copy the full SHA
    460f886 View commit details

Commits on Jul 4, 2022

  1. Merge pull request #528 from jamesottaway/patch-1

    docs: Include warning when configuring token to install private packages
    marko-zivic-93 authored Jul 4, 2022
    2
    Copy the full SHA
    0f15a51 View commit details
  2. Merge pull request #534 from panva/set-version-output

    set node-version output (2022 edition)
    marko-zivic-93 authored Jul 4, 2022
    2
    Copy the full SHA
    78faa55 View commit details
  3. 2
    Copy the full SHA
    b3ca1ac View commit details

Commits on Jul 7, 2022

  1. 2
    Copy the full SHA
    09ba51f View commit details

Commits on Jul 11, 2022

  1. Merge pull request #373 from ganta/add-support-for-asdf-format-as-nod…

    …e-version-file
    
    Add support for asdf format as Node.js version file
    marko-zivic-93 authored Jul 11, 2022
    2
    Copy the full SHA
    5b949b5 View commit details
3 changes: 2 additions & 1 deletion .github/workflows/versions.yml
Original file line number Diff line number Diff line change
@@ -92,12 +92,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version-file: [.nvmrc, .tool-versions]
steps:
- uses: actions/checkout@v3
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/.nvmrc'
node-version-file: '__tests__/data/${{ matrix.node-version-file }}'
- name: Verify node
run: __tests__/verify-node.sh 14

2 changes: 1 addition & 1 deletion .licenses/npm/@actions/cache.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
32 changes: 32 additions & 0 deletions .licenses/npm/@actions/http-client-2.0.1.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
@@ -35,14 +35,20 @@ For information regarding locally cached versions of Node.js on GitHub hosted ru

### Supported version syntax

The `node-version` input supports the following values:
The `node-version` input supports the Semantic Versioning Specification, for more detailed examples please refer to the [documentation](https://github.com/npm/node-semver).

- Major versions: `12`, `14`, `16`
- More specific versions: `10.15`, `14.2.0`, `16.3.0`
Examples:

- 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: `latest`/`current`/`node`
- Latest release: `*` or `latest`/`current`/`node`

**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.

**Note:** Since the latest release will not be cached always, there is possibility of hitting rate limit when downloading from dist
`current`/`latest`/`node` always resolve to the latest [dist version](https://nodejs.org/dist/index.json).
That version is then downloaded from actions/node-versions if possible, or directly from Node.js if not.
Since it will not be cached always, there is possibility of hitting rate limit when downloading from dist

### Checking in lockfiles

@@ -52,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`

@@ -65,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
@@ -78,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
@@ -93,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
57 changes: 57 additions & 0 deletions __tests__/cache-save.test.ts
Original file line number Diff line number Diff line change
@@ -294,6 +294,63 @@ describe('run', () => {
);
expect(setFailedSpy).not.toHaveBeenCalled();
});

it('save with -1 cacheId , should not fail workflow', async () => {
inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => {
if (name === State.CacheMatchedKey) {
return npmFileHash;
} else {
return yarnFileHash;
}
});
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
saveCacheSpy.mockImplementation(() => {
return -1;
});

await run();

expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1);
expect(debugSpy).toHaveBeenCalledWith(`npm path is ${commonPath}/npm`);
expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
);
expect(saveCacheSpy).toHaveBeenCalled();
expect(infoSpy).not.toHaveBeenLastCalledWith(
`Cache saved with the key: ${yarnFileHash}`
);
expect(setFailedSpy).not.toHaveBeenCalled();
});

it('saves with error from toolkit, should fail workflow', async () => {
inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => {
if (name === State.CacheMatchedKey) {
return npmFileHash;
} else {
return yarnFileHash;
}
});
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
saveCacheSpy.mockImplementation(() => {
throw new cache.ValidationError('Validation failed');
});

await run();

expect(getInputSpy).toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(2);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1);
expect(debugSpy).toHaveBeenCalledWith(`npm path is ${commonPath}/npm`);
expect(infoSpy).not.toHaveBeenCalledWith(
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
);
expect(saveCacheSpy).toHaveBeenCalled();
expect(setFailedSpy).toHaveBeenCalled();
});
});

afterEach(() => {
1 change: 1 addition & 0 deletions __tests__/data/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 14.0.0
27 changes: 27 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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';
import cp from 'child_process';
import osm = require('os');
import path from 'path';
import each from 'jest-each';
import * as main from '../src/main';
import * as auth from '../src/authutil';

@@ -38,6 +40,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 +106,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(() => {
@@ -898,3 +905,23 @@ describe('setup-node', () => {
);
});
});

describe('helper methods', () => {
describe('parseNodeVersionFile', () => {
each`
contents | expected
${'12'} | ${'12'}
${'12.3'} | ${'12.3'}
${'12.3.4'} | ${'12.3.4'}
${'v12.3.4'} | ${'12.3.4'}
${'lts/erbium'} | ${'lts/erbium'}
${'lts/*'} | ${'lts/*'}
${'nodejs 12.3.4'} | ${'12.3.4'}
${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'}
${''} | ${''}
${'unknown format'} | ${'unknown format'}
`.it('parses "$contents"', ({contents, expected}) => {
expect(im.parseNodeVersionFile(contents)).toBe(expected);
});
});
});
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ inputs:
node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
node-version-file:
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version.'
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.'
architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:
@@ -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'
Loading