Add support for read-only caching in v2

This commit is contained in:
Daz DeBoer 2021-08-24 12:57:17 -06:00
parent d9cc0aeccf
commit 6fca6b3929
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
6 changed files with 53 additions and 35 deletions

View file

@ -7,6 +7,7 @@ import * as cache from '@actions/cache'
import * as toolCache from '@actions/tool-cache'
import * as gradlew from './gradlew'
import {isCacheReadEnabled, isCacheSaveEnabled} from './cache-utils'
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
@ -119,7 +120,7 @@ async function downloadAndCacheGradleDistribution(
`gradle-installations/downloads/gradle-${versionInfo.version}-bin.zip`
)
if (isDistributionsCacheDisabled()) {
if (!isCacheReadEnabled('distributions')) {
await downloadGradleDistribution(versionInfo, downloadPath)
return downloadPath
}
@ -130,12 +131,14 @@ async function downloadAndCacheGradleDistribution(
core.info(
`Restored Gradle distribution ${cacheKey} from cache to ${downloadPath}`
)
} else {
core.info(
`Gradle distribution ${versionInfo.version} not found in cache. Will download.`
)
await downloadGradleDistribution(versionInfo, downloadPath)
return downloadPath
}
core.info(
`Gradle distribution ${versionInfo.version} not found in cache. Will download.`
)
await downloadGradleDistribution(versionInfo, downloadPath)
if (isCacheSaveEnabled('distributions')) {
try {
await cache.saveCache([downloadPath], cacheKey)
} catch (error) {
@ -183,10 +186,6 @@ async function httpGetString(url: string): Promise<string> {
return response.readBody()
}
function isDistributionsCacheDisabled(): boolean {
return !core.getBooleanInput('distributions-cache-enabled')
}
interface GradleVersionInfo {
version: string
downloadUrl: string