Skip to content

Commit 0cbf109

Browse files
committed
Improve diagnostics
1 parent 7c87da9 commit 0cbf109

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

gc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ const path = require('path')
44
const core = require('@actions/core')
55

66
function init(cacheConfig) {
7-
if (!cacheConfig.enabled) {
8-
return
9-
}
10-
117
core.startGroup(`Computing initial ${cacheConfig.name} cache hash`)
128
fs.writeFileSync(cacheConfig.path + '.sha256', computeCacheHash(cacheConfig.path))
139
core.endGroup()
1410
}
1511

1612
function run(cacheConfig) {
1713
if (!fs.existsSync(cacheConfig.path)) {
14+
core.warning(`No ${cacheConfig.name} cache present`)
1815
return
1916
}
2017

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ async function restoreExternalCaches(cacheConfig) {
142142
}
143143

144144
async function restoreCacheImpl(cacheConfig, primaryKey, restoreKeys, cacheHit) {
145-
if (!cacheConfig.enabled) {
146-
return
147-
}
148-
149145
const delay = Math.random() * 1000 // timeout <= 1 sec to reduce 429 errors
150146
await setTimeout(delay, async function () {
151147
core.startGroup(`Restore cache for ${cacheConfig.name}`)
@@ -175,6 +171,10 @@ async function restoreCacheImpl(cacheConfig, primaryKey, restoreKeys, cacheHit)
175171
}
176172

177173
async function restoreCache(cacheConfig) {
174+
if (!cacheConfig.enabled) {
175+
return
176+
}
177+
178178
const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
179179
const restoreKey = `${config.baseCacheKey}-${cacheConfig.name}-`
180180
const key = `${restoreKey}${hash}`
@@ -185,6 +185,10 @@ async function restoreCache(cacheConfig) {
185185
}
186186

187187
async function restoreGcCache(cacheConfig) {
188+
if (!cacheConfig.enabled) {
189+
return
190+
}
191+
188192
// Since disk caches get updated on any change, each run has a unique key.
189193
// Therefore it can only be restored by prefix match, rather than exact key match.
190194
// When multiple prefix matches exist, the most recent is selected.

post.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ async function saveGcCache(cacheConfig) {
6868

6969
const hash = gc.run(cacheConfig)
7070

71+
core.startGroup(`Save cache for ${cacheConfig.name}`)
72+
7173
// cache is unchanged
7274
if (!hash) {
75+
core.info(`No changes to ${cacheConfig} cache detected, skipping upload`)
7376
return
7477
}
7578

7679
const key = `${config.baseCacheKey}-${cacheConfig.name}-${hash}`
7780
const paths = cacheConfig.paths
7881

7982
try {
80-
core.startGroup(`Save cache for ${cacheConfig.name}`)
81-
8283
// cache already exists
8384
if (await cache.restoreCache(paths, key, [], { lookupOnly: true })) {
8485
core.info('Cache already exists, skipping upload')
@@ -90,9 +91,9 @@ async function saveGcCache(cacheConfig) {
9091
core.info('Successfully saved cache')
9192
} catch (error) {
9293
core.warning(error.stack)
93-
} finally {
94-
core.endGroup()
9594
}
95+
96+
core.endGroup()
9697
}
9798

9899
async function saveCache(cacheConfig) {

0 commit comments

Comments
 (0)