Merge branch 'actions:main' into sbt-cache

This commit is contained in:
Florian Meriaux 2022-04-04 15:00:16 +02:00 committed by GitHub
commit c08d2af675
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 833 additions and 718 deletions

View file

@ -1,6 +1,6 @@
import * as core from '@actions/core';
import * as auth from './auth';
import { getBooleanInput } from './util';
import { getBooleanInput, isCacheFeatureAvailable } from './util';
import * as constants from './constants';
import { restore } from './cache';
import * as path from 'path';
@ -42,7 +42,7 @@ async function run() {
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
await auth.configureAuthentication();
if (cache) {
if (cache && isCacheFeatureAvailable()) {
await restore(cache);
}
} catch (error) {

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;
}