Caching on GHES (#452)

* add support for ghes caching

* fix licesnses

* work on resolving comments

* change internal error to warning

* fix warning for internal errors

* update version
This commit is contained in:
Dmitry Shibanov 2022-03-31 21:10:37 +02:00 committed by GitHub
parent bed538bd04
commit bacd6b4b3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 192 additions and 67 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,28 @@ export const getCacheDirectoryPath = async (
return stdOut;
};
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()) {
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'
);
}
return false;
}
return true;
}