Improve cache reporting

- More succinct messages for cache-read-only and cache-disabled
- Report on cache-cleanup enabled/disabled status
This commit is contained in:
daz 2024-07-17 18:38:02 -06:00
parent 8d318190ad
commit d92de28b80
No known key found for this signature in database
2 changed files with 19 additions and 14 deletions

View file

@ -1,20 +1,18 @@
import * as cache from '@actions/cache' import * as cache from '@actions/cache'
export const DEFAULT_READONLY_REASON = `Cache was read-only: by default the action will only write to the cache for Jobs running on the default ('main'/'master') branch. export const DEFAULT_CACHE_ENABLED_REASON = `[Cache was enabled](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#caching-build-state-between-jobs). Action attempted to both restore and save the Gradle User Home.`
See [the docs](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#using-the-cache-read-only) for more details.
`
export const DEFAULT_DISABLED_REASON = `Cache was set to disabled via action confiugration. Gradle User Home was not restored from or saved to the cache. export const DEFAULT_READONLY_REASON = `[Cache was read-only](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#using-the-cache-read-only). By default, the action will only write to the cache for Jobs running on the default branch.`
See [the docs](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#disabling-caching) for more details.
`
export const DEFAULT_WRITEONLY_REASON = `Cache was set to write-only via action configuration. Gradle User Home was not restored from cache. export const DEFAULT_DISABLED_REASON = `[Cache was disabled](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#disabling-caching) via action confiugration. Gradle User Home was not restored from or saved to the cache.`
See [the docs](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#using-the-cache-write-only) for more details.
`
export const EXISTING_GRADLE_HOME = `Cache was disabled to avoid overwriting a pre-existing Gradle User Home. Gradle User Home was not restored from or saved to the cache. export const DEFAULT_WRITEONLY_REASON = `[Cache was set to write-only](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#using-the-cache-write-only) via action configuration. Gradle User Home was not restored from cache.`
See [the docs](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#overwriting-an-existing-gradle-user-home) for a more details.
` export const EXISTING_GRADLE_HOME = `[Cache was disabled to avoid overwriting a pre-existing Gradle User Home](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#overwriting-an-existing-gradle-user-home). Gradle User Home was not restored from or saved to the cache.`
export const DEFAULT_CLEANUP_DISABLED_REASON = `[Cache cleanup](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#remove-unused-files-from-gradle-user-home-before-saving-to-the-cache) was not enabled. It must be explicitly enabled.`
export const DEFAULT_CLEANUP_ENABLED_REASON = `[Cache cleanup](https://github.com/gradle/actions/blob/v3/docs/setup-gradle.md#remove-unused-files-from-gradle-user-home-before-saving-to-the-cache) was enabled.`
/** /**
* Collects information on what entries were saved and restored during the action. * Collects information on what entries were saved and restored during the action.
@ -25,7 +23,8 @@ export class CacheListener {
cacheReadOnly = false cacheReadOnly = false
cacheWriteOnly = false cacheWriteOnly = false
cacheDisabled = false cacheDisabled = false
cacheStatusReason: string | undefined cacheStatusReason: string = DEFAULT_CACHE_ENABLED_REASON
cacheCleanupMessage: string = DEFAULT_CLEANUP_DISABLED_REASON
get fullyRestored(): boolean { get fullyRestored(): boolean {
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored()) return this.cacheEntries.every(x => !x.wasRequestedButNotRestored())
@ -54,6 +53,10 @@ export class CacheListener {
this.cacheStatusReason = reason this.cacheStatusReason = reason
} }
setCacheCleanupEnabled(): void {
this.cacheCleanupMessage = DEFAULT_CLEANUP_ENABLED_REASON
}
entry(name: string): CacheEntryListener { entry(name: string): CacheEntryListener {
for (const entry of this.cacheEntries) { for (const entry of this.cacheEntries) {
if (entry.entryName === name) { if (entry.entryName === name) {
@ -149,7 +152,8 @@ export function generateCachingReport(listener: CacheListener): string {
<details> <details>
<summary><h4>Caching for Gradle actions was ${listener.cacheStatus} - expand for details</h4></summary> <summary><h4>Caching for Gradle actions was ${listener.cacheStatus} - expand for details</h4></summary>
${listener.cacheStatusReason} - ${listener.cacheStatusReason}
- ${listener.cacheCleanupMessage}
${renderEntryTable(entries)} ${renderEntryTable(entries)}

View file

@ -88,6 +88,7 @@ export async function save(
await daemonController.stopAllDaemons() await daemonController.stopAllDaemons()
if (cacheConfig.isCacheCleanupEnabled()) { if (cacheConfig.isCacheCleanupEnabled()) {
cacheListener.setCacheCleanupEnabled()
core.info('Forcing cache cleanup.') core.info('Forcing cache cleanup.')
const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!) const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!)
try { try {