mirror of
https://gitea.com/actions/setup-node.git
synced 2025-04-06 15:29:44 +00:00
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:
@ -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;
|
||||
}
|
||||
|
14
src/main.ts
14
src/main.ts
@ -4,7 +4,7 @@ import fs from 'fs';
|
||||
import * as auth from './authutil';
|
||||
import * as path from 'path';
|
||||
import {restoreCache} from './cache-restore';
|
||||
import {URL} from 'url';
|
||||
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
|
||||
import os = require('os');
|
||||
|
||||
export async function run() {
|
||||
@ -45,10 +45,7 @@ export async function run() {
|
||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(cache, cacheDependencyPath);
|
||||
}
|
||||
@ -66,13 +63,6 @@ export async function run() {
|
||||
}
|
||||
}
|
||||
|
||||
function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
function resolveVersionInput(): string {
|
||||
let version = core.getInput('node-version');
|
||||
const versionFileInput = core.getInput('node-version-file');
|
||||
|
Reference in New Issue
Block a user