@@ -31,47 +31,52 @@ module.exports = async function (options) {
3131 console . log ( "CACHE HIT!" ) ;
3232
3333 if ( options . downloadCacheOnHit ) {
34- await downloadCache ( hash , options . storageAccount , options . storageContainer , options . storageKey , options . outputPath ) ;
35- extractCache ( options . outputPath , hash ) ;
36- deleteCache ( options . outputPath , hash ) ;
34+ try {
35+ await downloadCache ( hash , options . storageAccount , options . storageContainer , options . storageKey , options . outputPath ) ;
36+ extractCache ( options . outputPath , hash ) ;
37+ deleteCache ( options . outputPath , hash ) ;
38+ return ;
39+ } catch ( e ) {
40+ console . log ( "error - falling back to cache miss:" , e )
41+ }
3742 }
38- } else {
39- console . log ( "CACHE MISS!" ) ;
43+ }
4044
41- if ( options . execCommand ) {
42- console . log ( "Running Command " + options . execCommand ) ;
43- execSync ( options . execCommand , { cwd : options . execWorkingDirectory , stdio : 'inherit' } ) ;
44- } else {
45- console . log ( "No command specified - skipping" ) ;
46- }
45+ console . log ( "CACHE MISS!" ) ;
4746
48- if ( options . uploadCacheOnMiss ) {
49- var files = getFileList ( options . outputPath , options . outputFiles , options . outputIgnore ) ;
47+ if ( options . execCommand ) {
48+ console . log ( "Running Command " + options . execCommand ) ;
49+ execSync ( options . execCommand , { cwd : options . execWorkingDirectory , stdio : 'inherit' } ) ;
50+ } else {
51+ console . log ( "No command specified - skipping" ) ;
52+ }
5053
51- if ( ! files || files . length == 0 ) {
52- console . log ( "No output files found - skipping cache update" ) ;
53- return ;
54- }
54+ if ( options . uploadCacheOnMiss ) {
55+ var files = getFileList ( options . outputPath , options . outputFiles , options . outputIgnore ) ;
5556
56- var tarFile = hash + ".tgz" ;
57- var tarPath = path . join ( options . outputPath , tarFile ) ;
58- // the tar library doesn't like paths that start with @ - need to add ./ to the start
59- files = files . map ( function ( value ) { return value . startsWith ( '@' ) ? './' + value : value } ) ;
57+ if ( ! files || files . length == 0 ) {
58+ console . log ( "No output files found - skipping cache update" ) ;
59+ return ;
60+ }
6061
61- console . log ( "Creating tarball " + tarPath ) ;
62+ var tarFile = hash + ".tgz" ;
63+ var tarPath = path . join ( options . outputPath , tarFile ) ;
64+ // the tar library doesn't like paths that start with @ - need to add ./ to the start
65+ files = files . map ( function ( value ) { return value . startsWith ( '@' ) ? './' + value : value } ) ;
6266
63- var tarOptions = {
64- sync : true ,
65- file : tarPath ,
66- strict : true ,
67- gzip : true ,
68- cwd : options . outputPath
69- }
67+ console . log ( "Creating tarball " + tarPath ) ;
7068
71- tar . create ( tarOptions , files ) ;
72- await uploadCache ( tarPath , tarFile , options . storageAccount , options . storageContainer , options . storageKey ) ;
73- fs . unlinkSync ( tarPath ) ;
69+ var tarOptions = {
70+ sync : true ,
71+ file : tarPath ,
72+ strict : true ,
73+ gzip : true ,
74+ cwd : options . outputPath
7475 }
76+
77+ tar . create ( tarOptions , files ) ;
78+ await uploadCache ( tarPath , tarFile , options . storageAccount , options . storageContainer , options . storageKey ) ;
79+ fs . unlinkSync ( tarPath ) ;
7580 }
7681}
7782
@@ -165,7 +170,7 @@ var downloadCache = function (hash, storageAccount, storageContainer, storageKey
165170 console . log ( "storageAccount: " + storageAccount ) ;
166171 console . log ( "storageContainer: " + storageContainer ) ;
167172 console . log ( "targetPath: " + targetPath ) ;
168-
173+
169174 if ( storageAccount && storageContainer && storageKey ) {
170175 var blobName = hash + ".tgz" ;
171176 var downloadFile = path . join ( targetPath , blobName ) ;
@@ -203,7 +208,7 @@ var uploadCache = function (blobPath, blobName, storageAccount, storageContainer
203208 console . log ( "blobName: " + blobName ) ;
204209 console . log ( "storageAccount: " + storageAccount ) ;
205210 console . log ( "storageContainer: " + storageContainer ) ;
206-
211+
207212 if ( storageAccount && storageContainer && storageKey ) {
208213 var blobService = azureStorage . createBlobService ( storageAccount , storageKey ) ;
209214
@@ -243,7 +248,7 @@ var extractCache = function (targetPath, hash) {
243248 cwd : targetPath
244249 }
245250
246- tar . extract ( tarOptions ) ;
251+ return tar . extract ( tarOptions ) ;
247252}
248253
249254var deleteCache = function ( targetPath , hash ) {
@@ -252,5 +257,5 @@ var deleteCache = function (targetPath, hash) {
252257
253258 console . log ( "Deleting Cache File " + cachePath ) ;
254259
255- fs . unlinkSync ( cachePath ) ;
260+ return fs . unlinkSync ( cachePath ) ;
256261}
0 commit comments