mirror of
https://github.com/actions/setup-node.git
synced 2025-04-20 03:50:53 +00:00
handle non-dir cache-dependency-path
This commit is contained in:
parent
3527195992
commit
8f7008bbe6
@ -1,11 +1,10 @@
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import * as fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
import * as cacheUtils from '../src/cache-utils';
|
import * as cacheUtils from '../src/cache-utils';
|
||||||
import {getCacheDirectoryPath} from '../src/cache-utils';
|
|
||||||
|
|
||||||
let rcFile: string;
|
let rcFile: string;
|
||||||
|
|
||||||
@ -212,6 +211,25 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getPackageManagerWorkingDir', () => {
|
||||||
|
let existsSpy: jest.SpyInstance;
|
||||||
|
let lstatSpy: jest.SpyInstance;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
|
existsSpy.mockImplementation(() => true);
|
||||||
|
|
||||||
|
lstatSpy = jest.spyOn(fs, 'lstatSync');
|
||||||
|
lstatSpy.mockImplementation(arg => ({
|
||||||
|
isDirectory: () => true
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
existsSpy.mockRestore();
|
||||||
|
lstatSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
it('getPackageManagerWorkingDir should return null for not yarn', async () => {
|
it('getPackageManagerWorkingDir should return null for not yarn', async () => {
|
||||||
process.env['INPUT_CACHE'] = 'some';
|
process.env['INPUT_CACHE'] = 'some';
|
||||||
delete process.env['INPUT_CACHE-DEPENDENCY-PATH'];
|
delete process.env['INPUT_CACHE-DEPENDENCY-PATH'];
|
||||||
@ -233,6 +251,17 @@ describe('authutil tests', () => {
|
|||||||
expect(dir).toBeNull();
|
expect(dir).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getPackageManagerWorkingDir should return null for yarn with cache-dependency-path for not-existing directory', async () => {
|
||||||
|
process.env['INPUT_CACHE'] = 'yarn';
|
||||||
|
const cachePath = '/foo/bar';
|
||||||
|
process.env['INPUT_CACHE-DEPENDENCY-PATH'] = cachePath;
|
||||||
|
lstatSpy.mockImplementation(arg => ({
|
||||||
|
isDirectory: () => false
|
||||||
|
}));
|
||||||
|
const dir = cacheUtils.getPackageManagerWorkingDir();
|
||||||
|
expect(dir).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it('getPackageManagerWorkingDir should return path for yarn with cache-dependency-path', async () => {
|
it('getPackageManagerWorkingDir should return path for yarn with cache-dependency-path', async () => {
|
||||||
process.env['INPUT_CACHE'] = 'yarn';
|
process.env['INPUT_CACHE'] = 'yarn';
|
||||||
const cachePath = '/foo/bar';
|
const cachePath = '/foo/bar';
|
||||||
@ -274,3 +303,4 @@ describe('authutil tests', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
10
dist/cache-save/index.js
vendored
10
dist/cache-save/index.js
vendored
@ -59253,6 +59253,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const cache = __importStar(__nccwpck_require__(7799));
|
const cache = __importStar(__nccwpck_require__(7799));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
exports.supportedPackageManagers = {
|
exports.supportedPackageManagers = {
|
||||||
npm: {
|
npm: {
|
||||||
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
|
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
|
||||||
@ -59288,7 +59289,14 @@ const getPackageManagerWorkingDir = () => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
return cacheDependencyPath ? path_1.default.dirname(cacheDependencyPath) : null;
|
if (!cacheDependencyPath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const wd = path_1.default.dirname(cacheDependencyPath);
|
||||||
|
if (fs_1.default.existsSync(wd) && fs_1.default.lstatSync(wd).isDirectory()) {
|
||||||
|
return wd;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
exports.getPackageManagerWorkingDir = getPackageManagerWorkingDir;
|
exports.getPackageManagerWorkingDir = getPackageManagerWorkingDir;
|
||||||
const getPackageManagerCommandOutput = (command) => exports.getCommandOutput(command, exports.getPackageManagerWorkingDir());
|
const getPackageManagerCommandOutput = (command) => exports.getCommandOutput(command, exports.getPackageManagerWorkingDir());
|
||||||
|
12
dist/setup/index.js
vendored
12
dist/setup/index.js
vendored
@ -71167,7 +71167,7 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
|
|||||||
exports.restoreCache = restoreCache;
|
exports.restoreCache = restoreCache;
|
||||||
const findLockFile = (packageManager) => {
|
const findLockFile = (packageManager) => {
|
||||||
const lockFiles = packageManager.lockFilePatterns;
|
const lockFiles = packageManager.lockFilePatterns;
|
||||||
const workspace = cache_utils_1.getPackageManagerWorkingDir() || process.env.GITHUB_WORKSPACE;
|
const workspace = process.env.GITHUB_WORKSPACE;
|
||||||
const rootContent = fs_1.default.readdirSync(workspace);
|
const rootContent = fs_1.default.readdirSync(workspace);
|
||||||
const lockFile = lockFiles.find(item => rootContent.includes(item));
|
const lockFile = lockFiles.find(item => rootContent.includes(item));
|
||||||
if (!lockFile) {
|
if (!lockFile) {
|
||||||
@ -71221,6 +71221,7 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
const cache = __importStar(__nccwpck_require__(7799));
|
const cache = __importStar(__nccwpck_require__(7799));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
exports.supportedPackageManagers = {
|
exports.supportedPackageManagers = {
|
||||||
npm: {
|
npm: {
|
||||||
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
|
lockFilePatterns: ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock'],
|
||||||
@ -71256,7 +71257,14 @@ const getPackageManagerWorkingDir = () => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
return cacheDependencyPath ? path_1.default.dirname(cacheDependencyPath) : null;
|
if (!cacheDependencyPath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const wd = path_1.default.dirname(cacheDependencyPath);
|
||||||
|
if (fs_1.default.existsSync(wd) && fs_1.default.lstatSync(wd).isDirectory()) {
|
||||||
|
return wd;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
exports.getPackageManagerWorkingDir = getPackageManagerWorkingDir;
|
exports.getPackageManagerWorkingDir = getPackageManagerWorkingDir;
|
||||||
const getPackageManagerCommandOutput = (command) => exports.getCommandOutput(command, exports.getPackageManagerWorkingDir());
|
const getPackageManagerCommandOutput = (command) => exports.getCommandOutput(command, exports.getPackageManagerWorkingDir());
|
||||||
|
@ -56,8 +56,8 @@ export const restoreCache = async (
|
|||||||
|
|
||||||
const findLockFile = (packageManager: PackageManagerInfo) => {
|
const findLockFile = (packageManager: PackageManagerInfo) => {
|
||||||
const lockFiles = packageManager.lockFilePatterns;
|
const lockFiles = packageManager.lockFilePatterns;
|
||||||
const workspace =
|
const workspace = process.env.GITHUB_WORKSPACE!;
|
||||||
getPackageManagerWorkingDir() || process.env.GITHUB_WORKSPACE!;
|
|
||||||
const rootContent = fs.readdirSync(workspace);
|
const rootContent = fs.readdirSync(workspace);
|
||||||
|
|
||||||
const lockFile = lockFiles.find(item => rootContent.includes(item));
|
const lockFile = lockFiles.find(item => rootContent.includes(item));
|
||||||
|
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
type SupportedPackageManagers = {
|
type SupportedPackageManagers = {
|
||||||
[prop: string]: PackageManagerInfo;
|
[prop: string]: PackageManagerInfo;
|
||||||
@ -58,7 +59,17 @@ export const getPackageManagerWorkingDir = (): string | null => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
return cacheDependencyPath ? path.dirname(cacheDependencyPath) : null;
|
if (!cacheDependencyPath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const wd = path.dirname(cacheDependencyPath);
|
||||||
|
|
||||||
|
if (fs.existsSync(wd) && fs.lstatSync(wd).isDirectory()) {
|
||||||
|
return wd;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPackageManagerCommandOutput = (command: string) =>
|
export const getPackageManagerCommandOutput = (command: string) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user