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 1
1
import { ICore } from './src/core'
2
2
import { ActionsCore } from './src/actions_core'
3
3
import { mkdirp } from './src/downloader'
4
- import { restoreCache , saveCache } from '@actions/cache'
5
4
import process from 'process'
6
5
import { spawnSync } from 'child_process'
7
6
import {
@@ -67,9 +66,13 @@ async function setup(
67
66
useCache = false
68
67
}
69
68
69
+ if ( ! core . isCacheAvailable ( ) ) {
70
+ useCache = false
71
+ }
72
+
70
73
let needToDownload = true
71
74
try {
72
- if ( useCache && ( await restoreCache ( [ outputDirectory ] , id ) ) ) {
75
+ if ( useCache && ( await core . restoreCache ( [ outputDirectory ] , id ) ) ) {
73
76
core . info ( `Cached ${ id } was successfully restored` )
74
77
needToDownload = false
75
78
}
@@ -86,7 +89,7 @@ async function setup(
86
89
)
87
90
88
91
try {
89
- if ( useCache && ! ( await saveCache ( [ outputDirectory ] , id ) ) ) {
92
+ if ( useCache && ! ( await core . saveCache ( [ outputDirectory ] , id ) ) ) {
90
93
core . warning ( `Failed to cache ${ id } ` )
91
94
}
92
95
} catch ( e ) {
Original file line number Diff line number Diff line change 1
1
import { ICore } from '../src/core'
2
2
import * as core from '@actions/core'
3
+ import * as cache from '@actions/cache'
3
4
4
5
export 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
+
5
21
getInput ( name : string ) : string {
6
22
return core . getInput ( name )
7
23
}
Original file line number Diff line number Diff line change 3
3
* This allows us to avoid module shimming and provide clean implementations for different platforms.
4
4
*/
5
5
export 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
+
6
29
/**
7
30
* Gets an input from the action/task configuration.
8
31
* @param name The name of the input
You can’t perform that action at this time.
0 commit comments