mirror of
https://github.com/actions/setup-node.git
synced 2026-06-29 17:51:40 +00:00
Compare commits
3 Commits
c908279815
...
9b8670b275
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b8670b275 | ||
|
|
5e21ff4d9b | ||
|
|
f89df17cc9 |
1
__tests__/data/.node-version
Normal file
1
__tests__/data/.node-version
Normal file
@ -0,0 +1 @@
|
||||
v16
|
||||
@ -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';
|
||||
|
||||
7
dist/cache-save/index.js
vendored
7
dist/cache-save/index.js
vendored
@ -60361,14 +60361,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.run = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const cache = __importStar(__nccwpck_require__(7799));
|
||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||
const constants_1 = __nccwpck_require__(9042);
|
||||
const cache_utils_1 = __nccwpck_require__(1678);
|
||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
||||
@ -60393,8 +60389,7 @@ exports.run = run;
|
||||
const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const state = core.getState(constants_1.State.CacheMatchedKey);
|
||||
const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
|
||||
let cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]');
|
||||
cachePaths = cachePaths.filter(fs_1.default.existsSync);
|
||||
const cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]');
|
||||
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
|
||||
if (!packageManagerInfo) {
|
||||
core.debug(`Caching for '${packageManager}' is not supported`);
|
||||
|
||||
17
dist/setup/index.js
vendored
17
dist/setup/index.js
vendored
@ -72277,11 +72277,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;
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as cache from '@actions/cache';
|
||||
|
||||
import fs from 'fs';
|
||||
|
||||
import {State} from './constants';
|
||||
import {getPackageManagerInfo} from './cache-utils';
|
||||
|
||||
@ -26,10 +24,9 @@ export async function run() {
|
||||
const cachePackages = async (packageManager: string) => {
|
||||
const state = core.getState(State.CacheMatchedKey);
|
||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
||||
let cachePaths = JSON.parse(
|
||||
const cachePaths = JSON.parse(
|
||||
core.getState(State.CachePaths) || '[]'
|
||||
) as string[];
|
||||
cachePaths = cachePaths.filter(fs.existsSync);
|
||||
|
||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||
if (!packageManagerInfo) {
|
||||
|
||||
23
src/main.ts
23
src/main.ts
@ -99,15 +99,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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user