mirror of
https://github.com/actions/setup-node.git
synced 2026-06-29 01:21:38 +00:00
Compare commits
3 Commits
6a65080fb2
...
a2bb18a702
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2bb18a702 | ||
|
|
ca2d4e0cdd | ||
|
|
f89df17cc9 |
3
.github/workflows/versions.yml
vendored
3
.github/workflows/versions.yml
vendored
@ -158,7 +158,8 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
node-version-file: [.nvmrc, .tool-versions, package.json]
|
||||
node-version-file:
|
||||
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Remove volta from package.json
|
||||
|
||||
1
__tests__/data/.node-version
Normal file
1
__tests__/data/.node-version
Normal file
@ -0,0 +1 @@
|
||||
v16
|
||||
1
__tests__/data/.tool-versions-node
Normal file
1
__tests__/data/.tool-versions-node
Normal file
@ -0,0 +1 @@
|
||||
node 14.0.0
|
||||
@ -155,14 +155,6 @@ describe('main tests', () => {
|
||||
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
|
||||
}, 10000);
|
||||
|
||||
it('not used if node-version-file not provided', async () => {
|
||||
// Act
|
||||
await main.run();
|
||||
|
||||
// Assert
|
||||
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('reads node-version-file if provided', async () => {
|
||||
// Arrange
|
||||
const versionSpec = 'v14';
|
||||
@ -215,6 +207,53 @@ describe('main tests', () => {
|
||||
);
|
||||
}, 10000);
|
||||
|
||||
it('reads .node-version if node-version and node-version-file were not provided', async () => {
|
||||
// Arrange
|
||||
const versionSpec = 'v16';
|
||||
const versionFile = '.node-version';
|
||||
const expectedVersionSpec = '16';
|
||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||
|
||||
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(infoSpy).toHaveBeenCalledWith(
|
||||
`Resolved ${versionFile} as ${expectedVersionSpec}`
|
||||
);
|
||||
}, 10000);
|
||||
|
||||
it('reads .nvmrc if node-version and node-version-file were not provided', async () => {
|
||||
// Arrange
|
||||
const versionSpec = 'v14';
|
||||
const versionFile = '.nvmrc';
|
||||
const expectedVersionSpec = '14';
|
||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||
|
||||
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
|
||||
existsSpy.mockImplementation(
|
||||
input => input === path.join(__dirname, 'data', versionFile)
|
||||
);
|
||||
|
||||
// Act
|
||||
await main.run();
|
||||
|
||||
// Assert
|
||||
expect(existsSpy).toHaveBeenCalledTimes(2);
|
||||
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
|
||||
expect(infoSpy).toHaveBeenCalledWith(
|
||||
`Resolved ${versionFile} as ${expectedVersionSpec}`
|
||||
);
|
||||
}, 10000);
|
||||
|
||||
it('both node-version-file and node-version are provided', async () => {
|
||||
inputs['node-version'] = '12';
|
||||
const versionSpec = 'v14';
|
||||
|
||||
2
dist/cache-save/index.js
vendored
2
dist/cache-save/index.js
vendored
@ -60754,7 +60754,7 @@ function parseNodeVersionFile(contents) {
|
||||
core.info('Node version file is not JSON file');
|
||||
}
|
||||
if (!nodeVersion) {
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
|
||||
}
|
||||
// In the case of an unknown format,
|
||||
|
||||
19
dist/setup/index.js
vendored
19
dist/setup/index.js
vendored
@ -72274,11 +72274,22 @@ function resolveVersionInput() {
|
||||
}
|
||||
if (versionFileInput) {
|
||||
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
|
||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||
if (fs_1.default.existsSync(versionFilePath)) {
|
||||
version = util_1.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
return version;
|
||||
}
|
||||
else {
|
||||
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
|
||||
}
|
||||
version = util_1.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
}
|
||||
for (const versionFile of ['.node-version', '.nvmrc']) {
|
||||
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFile);
|
||||
if (fs_1.default.existsSync(versionFilePath)) {
|
||||
version = util_1.parseNodeVersionFile(fs_1.default.readFileSync(versionFilePath, 'utf8'));
|
||||
core.info(`Resolved ${versionFile} as ${version}`);
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
@ -72336,7 +72347,7 @@ function parseNodeVersionFile(contents) {
|
||||
core.info('Node version file is not JSON file');
|
||||
}
|
||||
if (!nodeVersion) {
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
|
||||
}
|
||||
// In the case of an unknown format,
|
||||
|
||||
23
src/main.ts
23
src/main.ts
@ -97,15 +97,32 @@ function resolveVersionInput(): string {
|
||||
versionFileInput
|
||||
);
|
||||
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
if (fs.existsSync(versionFilePath)) {
|
||||
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
|
||||
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
|
||||
return version;
|
||||
} else {
|
||||
throw new Error(
|
||||
`The specified node version file at: ${versionFilePath} does not exist`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
|
||||
for (const versionFile of ['.node-version', '.nvmrc']) {
|
||||
const versionFilePath = path.join(
|
||||
process.env.GITHUB_WORKSPACE!,
|
||||
versionFile
|
||||
);
|
||||
|
||||
core.info(`Resolved ${versionFileInput} as ${version}`);
|
||||
if (fs.existsSync(versionFilePath)) {
|
||||
version = parseNodeVersionFile(fs.readFileSync(versionFilePath, 'utf8'));
|
||||
|
||||
core.info(`Resolved ${versionFile} as ${version}`);
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
|
||||
@ -13,7 +13,7 @@ export function parseNodeVersionFile(contents: string): string {
|
||||
}
|
||||
|
||||
if (!nodeVersion) {
|
||||
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
|
||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||
nodeVersion = found?.groups?.version;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user