mirror of https://github.com/actions/setup-go.git
Sources modified
parent
bfd2fb341f
commit
cf004f0dc3
@ -1,85 +1,124 @@
|
|||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as _ from 'lodash'
|
||||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
||||||
|
import * as glob from "@actions/glob";
|
||||||
|
|
||||||
export const getCommandOutput = async (toolCommand: string) => {
|
export const getCommandOutput = async (toolCommand: string) => {
|
||||||
let {stdout, stderr, exitCode} = await exec.getExecOutput(
|
let {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||||
toolCommand,
|
toolCommand,
|
||||||
undefined,
|
undefined,
|
||||||
{ignoreReturnCode: true}
|
{ignoreReturnCode: true}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (exitCode) {
|
if (exitCode) {
|
||||||
stderr = !stderr.trim()
|
stderr = !stderr.trim()
|
||||||
? `The '${toolCommand}' command failed with exit code: ${exitCode}`
|
? `The '${toolCommand}' command failed with exit code: ${exitCode}`
|
||||||
: stderr;
|
: stderr;
|
||||||
throw new Error(stderr);
|
throw new Error(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stdout.trim();
|
return stdout.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPackageManagerInfo = async (packageManager: string) => {
|
export const getPackageManagerInfo = async (packageManager: string) => {
|
||||||
if (!supportedPackageManagers[packageManager]) {
|
if (!supportedPackageManagers[packageManager]) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`
|
`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const obtainedPackageManager = supportedPackageManagers[packageManager];
|
const obtainedPackageManager = supportedPackageManagers[packageManager];
|
||||||
|
|
||||||
return obtainedPackageManager;
|
return obtainedPackageManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCacheDirectoryPath = async (
|
export const getCacheDirectoryPath = async (
|
||||||
packageManagerInfo: PackageManagerInfo
|
packageManagerInfo: PackageManagerInfo
|
||||||
) => {
|
) => {
|
||||||
const pathOutputs = await Promise.allSettled(
|
const pathOutputs = await Promise.allSettled(
|
||||||
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
||||||
getCommandOutput(command)
|
getCommandOutput(command)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = pathOutputs.map(item => {
|
const results = pathOutputs.map(item => {
|
||||||
if (item.status === 'fulfilled') {
|
if (item.status === 'fulfilled') {
|
||||||
return item.value;
|
return item.value;
|
||||||
} else {
|
} else {
|
||||||
core.info(`[warning]getting cache directory path failed: ${item.reason}`);
|
core.info(`[warning]getting cache directory path failed: ${item.reason}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
|
|
||||||
const cachePaths = results.filter(item => item);
|
const cachePaths = results.filter(item => item);
|
||||||
|
|
||||||
if (!cachePaths.length) {
|
if (!cachePaths.length) {
|
||||||
throw new Error(`Could not get cache folder paths.`);
|
throw new Error(`Could not get cache folder paths.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cachePaths;
|
return cachePaths;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isGhes(): boolean {
|
export function isGhes(): boolean {
|
||||||
const ghUrl = new URL(
|
const ghUrl = new URL(
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
);
|
);
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memoize it in order to avoid confusing multiple messages
|
||||||
|
*/
|
||||||
export function isCacheFeatureAvailable(): boolean {
|
export function isCacheFeatureAvailable(): boolean {
|
||||||
if (cache.isFeatureAvailable()) {
|
if (cache.isFeatureAvailable()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isGhes()) {
|
||||||
|
core.warning(
|
||||||
|
'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.'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isGhes()) {
|
|
||||||
core.warning(
|
core.warning(
|
||||||
'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.'
|
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the caching of dependencies is requested
|
||||||
|
* - `cache-mod` input takes precedence over `cache` input if set
|
||||||
|
*/
|
||||||
|
export function needModCache(): Boolean {
|
||||||
|
const cache = core.getBooleanInput('cache');
|
||||||
|
const modCache = core.getInput('cache-mod').toLowerCase()
|
||||||
|
|
||||||
|
return (modCache === 'true' || cache && modCache !== 'false')
|
||||||
|
}
|
||||||
|
|
||||||
core.warning(
|
/**
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
* Checks if the caching of intermediate build files is requested
|
||||||
);
|
* - `cache-mod` input takes precedence over `cache` input if set
|
||||||
return false;
|
*/
|
||||||
|
export function needBuildCache(): Boolean {
|
||||||
|
const cache = core.getBooleanInput('cache');
|
||||||
|
const buildCache = core.getInput('cache-build').toLowerCase()
|
||||||
|
|
||||||
|
return (buildCache === 'true' || cache && buildCache !== 'false')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getModDependenciesPath(): string {
|
||||||
|
return core.getInput('cache-dependency-path')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBuildDependenciesPath(): string {
|
||||||
|
return core.getInput('cache-build-path') || "**/*.go"
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBuildCachePath(): Promise<string> {
|
||||||
|
return getCommandOutput('go env GOCACHE')
|
||||||
|
}
|
@ -1,8 +1,11 @@
|
|||||||
export enum State {
|
export enum State {
|
||||||
CachePrimaryKey = 'CACHE_KEY',
|
CacheModPrimaryKey = 'CACHE_KEY',
|
||||||
CacheMatchedKey = 'CACHE_RESULT'
|
CacheModMatchedKey = 'CACHE_RESULT',
|
||||||
|
CacheBuildPrimaryKey = 'CACHE_BUILD_KEY',
|
||||||
|
CacheBuildMatchedKey = 'CACHE_BUILD_RESULT'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
CacheHit = 'cache-hit'
|
CacheModHit = 'cache-hit',
|
||||||
|
CacheBuildHit = 'cache-build-hit'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue