add support for ghes caching

This commit is contained in:
Dmitry Shibanov 2022-03-29 11:29:58 +02:00
parent bed538bd04
commit 7af0f4d168
9 changed files with 161 additions and 57 deletions

View file

@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as cache from '@actions/cache';
type SupportedPackageManagers = {
[prop: string]: PackageManagerInfo;
@ -95,3 +96,32 @@ export const getCacheDirectoryPath = async (
return stdOut;
};
function logWarning(message: string): void {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}
export function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
}
export function isCacheFeatureAvailable(): boolean {
if (!cache.isFeatureAvailable()) {
if (isGhes()) {
logWarning(
'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 {
logWarning(
'An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'
);
}
return false;
}
return true;
}