File tree Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 11import { ICore } from './src/core'
22import { ActionsCore } from './src/actions_core'
33import { mkdirp } from './src/downloader'
4- import { restoreCache , saveCache } from '@actions/cache'
54import process from 'process'
65import { spawnSync } from 'child_process'
76import {
@@ -67,9 +66,13 @@ async function setup(
6766 useCache = false
6867 }
6968
69+ if ( ! core . isCacheAvailable ( ) ) {
70+ useCache = false
71+ }
72+
7073 let needToDownload = true
7174 try {
72- if ( useCache && ( await restoreCache ( [ outputDirectory ] , id ) ) ) {
75+ if ( useCache && ( await core . restoreCache ( [ outputDirectory ] , id ) ) ) {
7376 core . info ( `Cached ${ id } was successfully restored` )
7477 needToDownload = false
7578 }
@@ -86,7 +89,7 @@ async function setup(
8689 )
8790
8891 try {
89- if ( useCache && ! ( await saveCache ( [ outputDirectory ] , id ) ) ) {
92+ if ( useCache && ! ( await core . saveCache ( [ outputDirectory ] , id ) ) ) {
9093 core . warning ( `Failed to cache ${ id } ` )
9194 }
9295 } catch ( e ) {
Original file line number Diff line number Diff line change 11import { ICore } from '../src/core'
22import * as core from '@actions/core'
3+ import * as cache from '@actions/cache'
34
45export class ActionsCore implements ICore {
6+ isCacheAvailable ( ) : boolean {
7+ return cache . isFeatureAvailable ( )
8+ }
9+
10+ async restoreCache (
11+ paths : string [ ] ,
12+ primaryKey : string
13+ ) : Promise < string | undefined > {
14+ return cache . restoreCache ( paths , primaryKey )
15+ }
16+
17+ async saveCache ( paths : string [ ] , key : string ) : Promise < number > {
18+ return cache . saveCache ( paths , key )
19+ }
20+
521 getInput ( name : string ) : string {
622 return core . getInput ( name )
723 }
Original file line number Diff line number Diff line change 33 * This allows us to avoid module shimming and provide clean implementations for different platforms.
44 */
55export interface ICore {
6+ /**
7+ * Checks if caching is available.
8+ */
9+ isCacheAvailable ( ) : boolean
10+
11+ /**
12+ * Restores cache from keys
13+ *
14+ * @param paths a list of file paths to restore from the cache
15+ * @param primaryKey an explicit key for restoring the cache. Lookup is done with prefix matching.
16+ * @returns string returns the key for the cache hit, otherwise returns undefined
17+ */
18+ restoreCache ( paths : string [ ] , primaryKey : string ) : Promise < string | undefined >
19+
20+ /**
21+ * Saves a list of files with the specified key
22+ *
23+ * @param paths a list of file paths to be cached
24+ * @param key an explicit key for restoring the cache
25+ * @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
26+ */
27+ saveCache ( paths : string [ ] , key : string ) : Promise < number >
28+
629 /**
730 * Gets an input from the action/task configuration.
831 * @param name The name of the input
You can’t perform that action at this time.
0 commit comments