mirror of
https://github.com/actions/setup-go.git
synced 2025-06-30 05:03:43 +00:00
Add caching of the compiler's temporary files
This commit is contained in:
parent
c8ed3f974d
commit
661954d154
6 changed files with 814 additions and 796 deletions
|
@ -34,7 +34,7 @@ export const restoreCache = async (
|
|||
|
||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||
|
||||
const cacheKey = await cache.restoreCache([cachePath], primaryKey);
|
||||
const cacheKey = await cache.restoreCache(cachePath, primaryKey);
|
||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||
|
||||
if (!cacheKey) {
|
||||
|
|
|
@ -35,10 +35,12 @@ const cachePackages = async () => {
|
|||
|
||||
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
|
||||
|
||||
if (!fs.existsSync(cachePath)) {
|
||||
throw new Error(
|
||||
`Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`
|
||||
);
|
||||
for (let path of cachePath) {
|
||||
if (!fs.existsSync(path)) {
|
||||
throw new Error(
|
||||
`Cache folder path is retrieved but doesn't exist on disk: ${path}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (primaryKey === state) {
|
||||
|
@ -49,7 +51,7 @@ const cachePackages = async () => {
|
|||
}
|
||||
|
||||
try {
|
||||
await cache.saveCache([cachePath], primaryKey);
|
||||
await cache.saveCache(cachePath, primaryKey);
|
||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
|
|
|
@ -34,15 +34,19 @@ export const getPackageManagerInfo = async (packageManager: string) => {
|
|||
export const getCacheDirectoryPath = async (
|
||||
packageManagerInfo: PackageManagerInfo
|
||||
) => {
|
||||
const stdout = await getCommandOutput(
|
||||
packageManagerInfo.getCacheFolderCommand
|
||||
);
|
||||
let pathList: string[] = [];
|
||||
|
||||
if (!stdout) {
|
||||
throw new Error(`Could not get cache folder path.`);
|
||||
for (let command of packageManagerInfo.cacheFolderCommandList) {
|
||||
pathList.push(await getCommandOutput(command));
|
||||
}
|
||||
|
||||
return stdout;
|
||||
for (let path of pathList) {
|
||||
if (!path) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
}
|
||||
|
||||
return pathList;
|
||||
};
|
||||
|
||||
export function isGhes(): boolean {
|
||||
|
|
|
@ -4,12 +4,12 @@ type SupportedPackageManagers = {
|
|||
|
||||
export interface PackageManagerInfo {
|
||||
dependencyFilePattern: string;
|
||||
getCacheFolderCommand: string;
|
||||
cacheFolderCommandList: string[];
|
||||
}
|
||||
|
||||
export const supportedPackageManagers: SupportedPackageManagers = {
|
||||
default: {
|
||||
dependencyFilePattern: 'go.sum',
|
||||
getCacheFolderCommand: 'go env GOMODCACHE'
|
||||
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue