@ -6,9 +6,10 @@ import fs from 'fs';
import { State , Outputs } from './constants' ;
import { PackageManagerInfo } from './package-managers' ;
import { getCacheDirectoryPath , getPackageManagerInfo } from './cache-utils' ;
import { getBuildCachePath , getCacheDirectoryPath , getPackageManagerInfo } from './cache-utils' ;
import { getInput } from "@actions/core" ;
export const restore Cache = async (
export const restore Mod Cache = async (
versionSpec : string ,
packageManager : string ,
cacheDependencyPath? : string
@ -25,27 +26,68 @@ export const restoreCache = async (
if ( ! fileHash ) {
throw new Error (
'Some specified paths were not resolved, unable to cache dependenci es.'
'Some specified paths were not resolved, unable to cache modul es.'
) ;
}
const linuxVersion =
process . env . RUNNER_OS === 'Linux' ? ` ${ process . env . ImageOS } - ` : '' ;
const primaryKey = ` setup-go- ${ platform } - ${ linuxVersion } go- ${ versionSpec } - ${ fileHash } ` ;
core . debug ( ` primary key is ${ primaryKey } ` ) ;
const cacheIdInput = getInput ( 'cache-id' )
const cacheId = cacheIdInput ? ` ${ cacheIdInput } - ` : ''
const primaryKey = ` setup-go- ${ platform } - ${ linuxVersion } go- ${ versionSpec } - ${ cacheId } ${ fileHash } ` ;
core . debug ( ` Primary key for modules cache is ${ primaryKey } ` ) ;
core . saveState ( State . CachePrimaryKey , primaryKey ) ;
core . saveState ( State . Cache Mod PrimaryKey, primaryKey ) ;
const cacheKey = await cache . restoreCache ( cachePaths , primaryKey ) ;
core . setOutput ( Outputs . CacheHit , Boolean ( cacheKey ) ) ;
core . setOutput ( Outputs . CacheModHit , Boolean ( cacheKey ) ) ;
if ( ! cacheKey ) {
core . info ( ` Modules cache is not found ` ) ;
core . setOutput ( Outputs . CacheModHit , false ) ;
return ;
}
core . saveState ( State . CacheModMatchedKey , cacheKey ) ;
core . info ( ` Modules cache restored from key: ${ cacheKey } ` ) ;
} ;
export const restoreBuildCache = async (
versionSpec : string ,
cacheBuildPath : string
) = > {
const platform = process . env . RUNNER_OS ;
const cachePath = await getBuildCachePath ( )
const fileHash = await glob . hashFiles ( cacheBuildPath ) ;
if ( ! fileHash ) {
throw new Error (
` The paths ${ cacheBuildPath } were not resolved, unable to cache intermediate build files. `
) ;
}
const linuxVersion =
process . env . RUNNER_OS === 'Linux' ? ` ${ process . env . ImageOS } - ` : '' ;
const cacheIdInput = getInput ( 'cache-id' )
const cacheId = cacheIdInput ? ` ${ cacheIdInput } - ` : ''
const keyPrefix = ` setup-go-build- ${ platform } - ${ linuxVersion } go- ${ versionSpec } - ${ cacheId } ` ;
const primaryKey = ` ${ keyPrefix } - ${ fileHash } ` ;
core . debug ( ` Primary key for intermediate build files cache is ${ primaryKey } ` ) ;
core . saveState ( State . CacheBuildPrimaryKey , primaryKey ) ;
const cacheKey = await cache . restoreCache ( [ cachePath ] , primaryKey , [ keyPrefix ] ) ;
core . setOutput ( Outputs . CacheBuildHit , Boolean ( cacheKey ) ) ;
if ( ! cacheKey ) {
core . info ( ` Cache is not found ` ) ;
core . setOutput ( Outputs . CacheHit , false ) ;
core . setOutput ( Outputs . Cache Build Hit, false ) ;
return ;
}
core . saveState ( State . CacheMatchedKey , cacheKey ) ;
core . saveState ( State . Cache Build MatchedKey, cacheKey ) ;
core . info ( ` Cache restored from key: ${ cacheKey } ` ) ;
} ;