mirror of
https://github.com/actions/setup-go
synced 2024-12-22 06:12:42 +00:00
Merge branch 'actions:main' into main
This commit is contained in:
commit
c0e82e3ff3
4 changed files with 5118 additions and 5084 deletions
|
@ -93,6 +93,41 @@ describe('getCacheDirectoryPath', () => {
|
|||
.then(data => expect(data).toEqual(expectedResult));
|
||||
});
|
||||
|
||||
it('should return path to the cache folder if one command return empty str', async () => {
|
||||
//Arrange
|
||||
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
|
||||
return new Promise<exec.ExecOutput>(resolve => {
|
||||
resolve({exitCode: 0, stdout: 'path/to/cache/folder', stderr: ''});
|
||||
});
|
||||
});
|
||||
|
||||
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
|
||||
return new Promise<exec.ExecOutput>(resolve => {
|
||||
resolve({exitCode: 0, stdout: '', stderr: ''});
|
||||
});
|
||||
});
|
||||
|
||||
const expectedResult = ['path/to/cache/folder'];
|
||||
|
||||
//Act + Assert
|
||||
return cacheUtils
|
||||
.getCacheDirectoryPath(validPackageManager)
|
||||
.then(data => expect(data).toEqual(expectedResult));
|
||||
});
|
||||
|
||||
it('should throw if the both commands return empty str', async () => {
|
||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
||||
return new Promise<exec.ExecOutput>(resolve => {
|
||||
resolve({exitCode: 10, stdout: '', stderr: ''});
|
||||
});
|
||||
});
|
||||
|
||||
//Act + Assert
|
||||
expect(async () => {
|
||||
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
||||
}).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should throw if the specified package name is invalid', async () => {
|
||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
||||
return new Promise<exec.ExecOutput>(resolve => {
|
||||
|
@ -162,7 +197,7 @@ describe('isCacheFeatureAvailable', () => {
|
|||
expect(functionResult).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should throw when cache feature is unavailable and GHES is used', () => {
|
||||
it('should warn when cache feature is unavailable and GHES is used', () => {
|
||||
//Arrange
|
||||
isFeatureAvailableSpy.mockImplementation(() => {
|
||||
return false;
|
||||
|
@ -170,10 +205,11 @@ describe('isCacheFeatureAvailable', () => {
|
|||
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
|
||||
|
||||
let errorMessage =
|
||||
let warningMessage =
|
||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';
|
||||
|
||||
//Act + Assert
|
||||
expect(() => cacheUtils.isCacheFeatureAvailable()).toThrow(errorMessage);
|
||||
expect(cacheUtils.isCacheFeatureAvailable()).toBeFalsy();
|
||||
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
||||
});
|
||||
});
|
||||
|
|
21
dist/cache-save/index.js
vendored
21
dist/cache-save/index.js
vendored
|
@ -60457,12 +60457,12 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
|
|||
});
|
||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
|
||||
const emptyPaths = pathList.filter(item => !item);
|
||||
if (emptyPaths.length) {
|
||||
const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
|
||||
const cachePaths = pathList.filter(item => item);
|
||||
if (!cachePaths.length) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
return pathList;
|
||||
return cachePaths;
|
||||
});
|
||||
exports.getCacheDirectoryPath = getCacheDirectoryPath;
|
||||
function isGhes() {
|
||||
|
@ -60471,16 +60471,15 @@ function isGhes() {
|
|||
}
|
||||
exports.isGhes = isGhes;
|
||||
function isCacheFeatureAvailable() {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (cache.isFeatureAvailable()) {
|
||||
return true;
|
||||
}
|
||||
if (isGhes()) {
|
||||
throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
|
||||
}
|
||||
else {
|
||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||
}
|
||||
core.warning('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||
return false;
|
||||
}
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
|
||||
|
|
21
dist/setup/index.js
vendored
21
dist/setup/index.js
vendored
|
@ -63130,12 +63130,12 @@ const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void
|
|||
});
|
||||
exports.getPackageManagerInfo = getPackageManagerInfo;
|
||||
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
|
||||
const emptyPaths = pathList.filter(item => !item);
|
||||
if (emptyPaths.length) {
|
||||
const pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
|
||||
const cachePaths = pathList.filter(item => item);
|
||||
if (!cachePaths.length) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
return pathList;
|
||||
return cachePaths;
|
||||
});
|
||||
exports.getCacheDirectoryPath = getCacheDirectoryPath;
|
||||
function isGhes() {
|
||||
|
@ -63144,16 +63144,15 @@ function isGhes() {
|
|||
}
|
||||
exports.isGhes = isGhes;
|
||||
function isCacheFeatureAvailable() {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (cache.isFeatureAvailable()) {
|
||||
return true;
|
||||
}
|
||||
if (isGhes()) {
|
||||
throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
|
||||
}
|
||||
else {
|
||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||
}
|
||||
core.warning('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||
return false;
|
||||
}
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
|
||||
|
|
|
@ -34,19 +34,19 @@ export const getPackageManagerInfo = async (packageManager: string) => {
|
|||
export const getCacheDirectoryPath = async (
|
||||
packageManagerInfo: PackageManagerInfo
|
||||
) => {
|
||||
let pathList = await Promise.all(
|
||||
const pathList = await Promise.all(
|
||||
packageManagerInfo.cacheFolderCommandList.map(command =>
|
||||
getCommandOutput(command)
|
||||
)
|
||||
);
|
||||
|
||||
const emptyPaths = pathList.filter(item => !item);
|
||||
const cachePaths = pathList.filter(item => item);
|
||||
|
||||
if (emptyPaths.length) {
|
||||
if (!cachePaths.length) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
|
||||
return pathList;
|
||||
return cachePaths;
|
||||
};
|
||||
|
||||
export function isGhes(): boolean {
|
||||
|
@ -57,19 +57,19 @@ export function isGhes(): boolean {
|
|||
}
|
||||
|
||||
export function isCacheFeatureAvailable(): boolean {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
throw new Error(
|
||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'
|
||||
);
|
||||
} else {
|
||||
core.warning(
|
||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||
);
|
||||
if (cache.isFeatureAvailable()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isGhes()) {
|
||||
core.warning(
|
||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
core.warning(
|
||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue