Caching on GHES (#308)

* initial changes

* review comments

* updated with correct message

* linting

* update version

* updated version
This commit is contained in:
Shubham Tiwari
2022-04-01 00:39:57 +05:30
committed by GitHub
parent e886040dc2
commit dc1a9f2791
8 changed files with 826 additions and 712 deletions

View File

@ -2,6 +2,7 @@ import os from 'os';
import path from 'path';
import * as fs from 'fs';
import * as semver from 'semver';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
@ -77,3 +78,24 @@ export function isJobStatusSuccess() {
return jobStatus === 'success';
}
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(
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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;
}