Unverified Commit 33905401 authored by Daz DeBoer's avatar Daz DeBoer
Browse files

Simplify setting caches to disabled or read-only

parent 1c72a314
Loading
Loading
Loading
Loading
+1 −1
Changes for .github/workflows/failure-cases.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -34,4 +34,4 @@ jobs:
      with:
        build-root-directory: __tests__/samples/no-wrapper
        arguments: help
        gradle-cache-enabled: no
        cache-disabled: yes
+6 −6
Changes for .github/workflows/integration-testing.yml: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -51,21 +51,21 @@ jobs:
        gradle-version: 6.9
        build-root-directory: __tests__/samples/no-wrapper
        arguments: help -DgradleVersionCheck=6.9
        gradle-cache-enabled: read-only
        cache-read-only: true
    - name: Test use Gradle version alias
      uses: ./
      with:
        gradle-version: release-candidate
        build-root-directory: __tests__/samples/no-wrapper
        arguments: help -DgradleVersionCheck=7.2
        gradle-cache-enabled: read-only
        cache-read-only: true
    - name: Test use defined Gradle executable
      uses: ./
      with:
        gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
        build-root-directory: __tests__/samples/no-wrapper
        arguments: help -DgradleVersionCheck=7.1.1
        gradle-cache-enabled: read-only
        cache-read-only: true

  # Test that the gradle-user-home cache will cache dependencies, by running build with --offline
  dependencies-cache:
@@ -82,7 +82,7 @@ jobs:
      with:
        build-root-directory: __tests__/samples/basic
        arguments: test --offline
        gradle-cache-enabled: read-only
        cache-read-only: true

  # Test that the gradle-user-home cache will cache and restore local build-cache
  build-cache:
@@ -99,7 +99,7 @@ jobs:
      with:
        build-root-directory: __tests__/samples/basic
        arguments: test -DverifyCachedBuild=true
        gradle-cache-enabled: read-only
        cache-read-only: true

  # Test that the project-dot-gradle cache will cache and restore configuration-cache
  configuration-cache:
@@ -118,4 +118,4 @@ jobs:
      with:
        build-root-directory: __tests__/samples/basic
        arguments: test --configuration-cache
        gradle-cache-enabled: read-only
        cache-read-only: true
+6 −6
Changes for action.yml: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -16,14 +16,14 @@ inputs:
  arguments:
    description: Gradle command line arguments, see gradle --help
    required: false
  distributions-cache-enabled:
    description: Whether caching downloaded Gradle distributions is enabled or not. Valid values are 'true' (default), 'false', and 'read-only'.
  cache-disabled:
    description: When 'true', all caching is disabled. No entries will be written to or read from the cache.
    required: false
    default: true
  gradle-cache-enabled:
    description: Whether caching of Gradle User Home and project .gradle directory is enabled. Valid values are 'true' (default), 'false', and 'read-only'.
    default: false
  cache-read-only:
    description: When 'true', existing entries will be read from the cache but no entries will be written
    required: false
    default: true
    default: false
  workflow-job-context:
    description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users.
    required: false
+4 −19
Changes for src/cache-utils.ts: 4 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -3,27 +3,12 @@ import * as cache from '@actions/cache'
import * as github from '@actions/github'
import * as crypto from 'crypto'

export function isCacheReadEnabled(cacheName: string): boolean {
    const configValue = getCacheEnabledValue(cacheName)
    return configValue === 'true' || configValue === 'read-only'
export function isCacheDisabled(): boolean {
    return core.getBooleanInput('cache-disabled')
}

export function isCacheSaveEnabled(cacheName: string): boolean {
    const configValue = getCacheEnabledValue(cacheName)
    return configValue === 'true'
}

function getCacheEnabledValue(cacheName: string): string {
    const configValue = core
        .getInput(`${cacheName}-cache-enabled`)
        .toLowerCase()

    if (['true', 'false', 'read-only'].includes(configValue)) {
        return configValue
    }
    throw new Error(
        `Invalid cache-enabled parameter '${configValue}'. Valid values are ['true', 'false', 'read-only']`
    )
export function isCacheReadOnly(): boolean {
    return core.getBooleanInput('cache-read-only')
}

export function isCacheDebuggingEnabled(): boolean {
+4 −4
Changes for src/caches.ts: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
import {GradleUserHomeCache} from './cache-gradle-user-home'
import {ProjectDotGradleCache} from './cache-project-dot-gradle'
import * as core from '@actions/core'
import {isCacheReadEnabled, isCacheSaveEnabled} from './cache-utils'
import {isCacheDisabled, isCacheReadOnly} from './cache-utils'

const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'

export async function restore(buildRootDirectory: string): Promise<void> {
    if (!isCacheReadEnabled('gradle')) {
    if (isCacheDisabled()) {
        core.debug('Cache read disabled')
        return
    }
@@ -21,8 +21,8 @@ export async function restore(buildRootDirectory: string): Promise<void> {
}

export async function save(): Promise<void> {
    if (!isCacheSaveEnabled('gradle')) {
        core.debug('Cache save disabled')
    if (isCacheReadOnly()) {
        core.debug('Cache is read-only: not saving cache entry')
        return
    }

Loading