Skip to content

Commit 7098ba3

Browse files
committed
add some logging
1 parent 5a492db commit 7098ba3

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/run.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function runCommand({
2525
shouldCacheOnError,
2626
}: RunCommandProps) {
2727
if (!cacheByTime && cacheByFiles.length === 0) {
28+
console.log(`Executing command "${command}" due to no caching options provided`)
2829
await execSh.promise(command)
2930
return
3031
}
@@ -56,28 +57,45 @@ export async function runCommand({
5657
})()
5758

5859
if (areFileHashesEqual && isWithinCacheTime) {
60+
console.log(
61+
[
62+
`Skipping command "${command}" due to`,
63+
[fileHashes && 'unchanged files', duration && 'being within cache time']
64+
.filter(Boolean)
65+
.join(' and '),
66+
].join(' ')
67+
)
5968
return
6069
}
6170

71+
console.log(
72+
[
73+
`Executing command "${command}" due to`,
74+
[fileHashes && 'changed files', duration && 'cache time passing']
75+
.filter(Boolean)
76+
.join(' and '),
77+
].join(' ')
78+
)
6279
let execPromise = execSh.promise(command)
6380

81+
function setCache() {
82+
cache.setKey(cacheKey, {
83+
lastRun: currentDate,
84+
fileHashes,
85+
})
86+
cache.save(true)
87+
console.log(`Cache saved for command "${command}"`)
88+
}
89+
6490
if (shouldCacheOnError) {
6591
execPromise = execPromise.catch((error: unknown) => {
66-
cache.setKey(cacheKey, {
67-
lastRun: currentDate,
68-
fileHashes,
69-
})
70-
cache.save(true)
92+
setCache()
7193

7294
throw error
7395
})
7496
}
7597

7698
await execPromise
7799

78-
cache.setKey(cacheKey, {
79-
lastRun: currentDate,
80-
fileHashes,
81-
})
82-
cache.save(true)
100+
setCache()
83101
}

0 commit comments

Comments
 (0)