mirror of
https://gitea.com/actions/setup-java.git
synced 2025-04-06 07:19:39 +00:00
Merge branch 'actions:main' into suggest-clear-cache-after-dependency-update
This commit is contained in:
@ -76,8 +76,10 @@ export async function restore(id: string) {
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
core.saveState(CACHE_MATCHED_KEY, matchedKey);
|
||||
core.setOutput('cache-hit', matchedKey === primaryKey);
|
||||
core.info(`Cache restored from key: ${matchedKey}`);
|
||||
} else {
|
||||
core.setOutput('cache-hit', false);
|
||||
core.info(`${packageManager.id} cache is not found`);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
22
src/util.ts
22
src/util.ts
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user