Add functionality for caching with GHES

This commit is contained in:
Ivan Zosimov 2022-04-07 11:44:23 +02:00
parent e72fc4648f
commit 1466d1b901
4 changed files with 74 additions and 24 deletions

View file

@ -4,9 +4,9 @@ import * as installer from './installer';
import * as semver from 'semver';
import path from 'path';
import {restoreCache} from './cache-restore';
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
import cp from 'child_process';
import fs from 'fs';
import {URL} from 'url';
export async function run() {
try {
@ -41,10 +41,7 @@ export async function run() {
core.info(`Successfully setup go version ${versionSpec}`);
}
if (cache) {
if (isGhes()) {
throw new Error('Caching is not supported on GHES');
}
if (cache && isCacheFeatureAvailable()) {
const packageManager = 'default';
const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache(packageManager, cacheDependencyPath);
@ -98,10 +95,3 @@ export async function addBinToPath(): Promise<boolean> {
}
return added;
}
function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
}