Merge remote-tracking branch 'refs/remotes/origin/pull209' into pull209

This commit is contained in:
Hargun Kaur 2021-11-22 18:29:21 +00:00 committed by GitHub
commit e75d7c128f
7 changed files with 72 additions and 24 deletions

View file

@ -89,7 +89,7 @@ jobs:
- name: Setup node from node version file - name: Setup node from node version file
uses: ./ uses: ./
with: with:
node-version-file: '.nvmrc' node-version-file: '__tests__/data/.nvmrc'
- name: Verify node - name: Verify node
run: __tests__/verify-node.sh 14 run: __tests__/verify-node.sh 14

View file

@ -1,4 +1,5 @@
# setup-node # setup-node
<p align="left"> <p align="left">
<a href="https://github.com/actions/setup-node/actions?query=workflow%3Abuild-test"><img alt="build-test status" src="https://github.com/actions/setup-node/workflows/build-test/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aversions"><img alt="versions status" src="https://github.com/actions/setup-node/workflows/versions/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aproxy"><img alt="proxy status" src="https://github.com/actions/setup-node/workflows/proxy/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Abuild-test"><img alt="build-test status" src="https://github.com/actions/setup-node/workflows/build-test/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aversions"><img alt="versions status" src="https://github.com/actions/setup-node/workflows/versions/badge.svg"></a> <a href="https://github.com/actions/setup-node/actions?query=workflow%3Aproxy"><img alt="proxy status" src="https://github.com/actions/setup-node/workflows/proxy/badge.svg"></a>
</p> </p>
@ -71,7 +72,6 @@ steps:
- run: npm test - run: npm test
``` ```
## Matrix Testing: ## Matrix Testing:
```yaml ```yaml
jobs: jobs:
@ -93,7 +93,7 @@ jobs:
## Advanced usage ## Advanced usage
1. [Check latest version](docs/advanced-usage.md#check-latest-version) 1. [Check latest version](docs/advanced-usage.md#check-latest-version)
2. [Using a node version file](docs/advanced-usage.md#Node-version-file) 2. [Using a node version file](docs/advanced-usage.md#node-version-file)
3. [Using different architectures](docs/advanced-usage.md#architecture) 3. [Using different architectures](docs/advanced-usage.md#architecture)
4. [Caching packages dependencies](docs/advanced-usage.md#caching-packages-dependencies) 4. [Caching packages dependencies](docs/advanced-usage.md#caching-packages-dependencies)
5. [Using multiple operating systems and architectures](docs/advanced-usage.md#multiple-operating-systems-and-architectures) 5. [Using multiple operating systems and architectures](docs/advanced-usage.md#multiple-operating-systems-and-architectures)

View file

@ -65,7 +65,6 @@ describe('setup-node', () => {
// io // io
whichSpy = jest.spyOn(io, 'which'); whichSpy = jest.spyOn(io, 'which');
existsSpy = jest.spyOn(fs, 'existsSync'); existsSpy = jest.spyOn(fs, 'existsSync');
readFileSyncSpy = jest.spyOn(fs, 'readFileSync');
mkdirpSpy = jest.spyOn(io, 'mkdirP'); mkdirpSpy = jest.spyOn(io, 'mkdirP');
// disable authentication portion for installer tests // disable authentication portion for installer tests
@ -95,6 +94,10 @@ describe('setup-node', () => {
// uncomment to see debug output // uncomment to see debug output
// process.stderr.write(msg + '\n'); // process.stderr.write(msg + '\n');
}); });
warningSpy.mockImplementation(msg => {
// uncomment to debug
// process.stderr.write('log:' + line + '\n');
});
}); });
afterEach(() => { afterEach(() => {
@ -563,7 +566,7 @@ describe('setup-node', () => {
await main.run(); await main.run();
// Assert // Assert
expect(readFileSyncSpy).toHaveBeenCalledTimes(0); expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
}); });
it('not used if node-version-file not provided', async () => { it('not used if node-version-file not provided', async () => {
@ -571,32 +574,73 @@ describe('setup-node', () => {
await main.run(); await main.run();
// Assert // Assert
expect(readFileSyncSpy).toHaveBeenCalledTimes(0); expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
}); });
it('reads node-version-file if provided', async () => { it('reads node-version-file if provided', async () => {
// Arrange // Arrange
const versionSpec = 'v12'; const versionSpec = 'v14';
const versionFile = '.nvmrc'; const versionFile = '.nvmrc';
const expectedVersionSpec = '12'; const expectedVersionSpec = '14';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
inputs['node-version-file'] = versionFile;
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
existsSpy.mockImplementationOnce(
input => input === path.join(__dirname, 'data', versionFile)
);
// Act
await main.run();
// Assert
expect(existsSpy).toHaveBeenCalledTimes(1);
expect(existsSpy).toHaveReturnedWith(true);
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
expect(logSpy).toHaveBeenCalledWith(
`Resolved ${versionFile} as ${expectedVersionSpec}`
);
});
it('both node-version-file and node-version are provided', async () => {
inputs['node-version'] = '12';
const versionSpec = 'v14';
const versionFile = '.nvmrc';
const expectedVersionSpec = '14';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..'); process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..');
inputs['node-version-file'] = versionFile; inputs['node-version-file'] = versionFile;
readFileSyncSpy.mockImplementation(() => versionSpec);
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
// Act // Act
await main.run(); await main.run();
// Assert // Assert
expect(readFileSyncSpy).toHaveBeenCalledTimes(1); expect(existsSpy).toHaveBeenCalledTimes(0);
expect(readFileSyncSpy).toHaveBeenCalledWith( expect(parseNodeVersionSpy).not.toHaveBeenCalled();
path.join(process.env.GITHUB_WORKSPACE, versionFile), expect(warningSpy).toHaveBeenCalledWith(
'utf8' 'Both node-version and node-version-file inputs are specified, only node-version will be used'
); );
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); });
expect(logSpy).toHaveBeenCalledWith(
`Resolved ${versionFile} as ${expectedVersionSpec}` it('should throw an error if node-version-file is not found', async () => {
const versionFile = '.nvmrc';
const versionFilePath = path.join(__dirname, '..', versionFile);
inputs['node-version-file'] = versionFile;
inSpy.mockImplementation(name => inputs[name]);
existsSpy.mockImplementationOnce(
input => input === path.join(__dirname, 'data', versionFile)
);
// Act
await main.run();
// Assert
expect(existsSpy).toHaveBeenCalled();
expect(existsSpy).toHaveReturnedWith(false);
expect(parseNodeVersionSpy).not.toHaveBeenCalled();
expect(cnSpy).toHaveBeenCalledWith(
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
); );
}); });
}); });

View file

@ -8,7 +8,7 @@ inputs:
node-version: node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0' description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0'
node-version-file: node-version-file:
description: 'File containing the version Spec of the version to use. Examples: .nvmrc' description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .n-node-version'
architecture: architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.' description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest: check-latest:

4
dist/setup/index.js vendored
View file

@ -7006,7 +7006,7 @@ function resolveVersionInput() {
let version = core.getInput('node-version') || core.getInput('version'); let version = core.getInput('node-version') || core.getInput('version');
const versionFileInput = core.getInput('node-version-file'); const versionFileInput = core.getInput('node-version-file');
if (version && versionFileInput) { if (version && versionFileInput) {
core.warning('Both node-version and node-version-file are specified'); core.warning('Both node-version and node-version-file inputs are specified, only node-version will be used');
} }
if (version) { if (version) {
return version; return version;
@ -7014,7 +7014,7 @@ function resolveVersionInput() {
if (versionFileInput) { if (versionFileInput) {
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput); const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
if (!fs_1.default.existsSync(versionFilePath)) { if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error('No specified file exists'); throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
} }
version = installer.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8')); version = installer.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
core.info(`Resolved ${versionFileInput} as ${version}`); core.info(`Resolved ${versionFileInput} as ${version}`);

View file

@ -21,9 +21,9 @@ steps:
## Node version file ## Node version file
The `node-version-file` input contains the version of node used by project, for example `.nvmrc`. If both the `node-version` and the `node-version-file` inputs are provided the `node-version` input is used. 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.
You can check [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax) See [supported version syntax](https://github.com/actions/setup-node#supported-version-syntax)
> The action will search for the node version file relative to repository root. > The action will search for the node version file relative to the repository root.
```yaml ```yaml
steps: steps:

View file

@ -78,7 +78,9 @@ function resolveVersionInput(): string {
const versionFileInput = core.getInput('node-version-file'); const versionFileInput = core.getInput('node-version-file');
if (version && versionFileInput) { if (version && versionFileInput) {
core.warning('Both node-version and node-version-file are specified'); core.warning(
'Both node-version and node-version-file inputs are specified, only node-version will be used'
);
} }
if (version) { if (version) {
@ -91,7 +93,9 @@ function resolveVersionInput(): string {
versionFileInput versionFileInput
); );
if (!fs.existsSync(versionFilePath)) { if (!fs.existsSync(versionFilePath)) {
throw new Error('No specified file exists'); throw new Error(
`The specified node version file at: ${versionFilePath} does not exist`
);
} }
version = installer.parseNodeVersionFile( version = installer.parseNodeVersionFile(
fs.readFileSync(versionFilePath, 'utf8') fs.readFileSync(versionFilePath, 'utf8')