Unverified Commit 723ca4de authored by Daz DeBoer's avatar Daz DeBoer Committed by GitHub
Browse files

Caching improvements (#294)

- Better reporting of cache status in Job Summary (including cache
cleanup)
- Allow cache cleanup to be skipped when Gradle builds fail
- Refactoring
parents a025cbe7 72dde7ef
Loading
Loading
Loading
Loading
+3
Changes for .github/workflows/demo-job-summary.yml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ jobs:

    - name: Setup Gradle
      uses: ./setup-gradle
      with:
        cache-read-only: false
        cache-cleanup: 'on-success'
    - name: Build kotlin-dsl project
      working-directory: .github/workflow-samples/kotlin-dsl
      run: ./gradlew assemble
+1 −1
Changes for .github/workflows/integ-test-cache-cleanup.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ jobs:
      uses: ./setup-gradle
      with:
        cache-read-only: false
        gradle-home-cache-cleanup: true
        cache-cleanup: 'on-success'
    - name: Build with 3.1.1
      working-directory: sources/test/jest/resources/cache-cleanup
      run: ./gradlew --no-daemon --build-cache -Dcommons_math3_version="3.1.1" build
+14 −5
Changes for dependency-submission/action.yml: 14 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -57,6 +57,20 @@ inputs:
      Configuration-cache data will not be saved/restored without an encryption key being provided.
    required: false

  cache-cleanup:
    description: |
      Specifies if the action should attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
      By default, no cleanup is performed. It can be configured to run every time, or only when all Gradle builds succeed for the Job. 
      Valid values are 'never', 'on-success' and 'always'.
    required: false
    default: 'never'

  gradle-home-cache-cleanup:
    description: When 'true', the action will attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
    required: false
    default: false
    deprecation-message: This input has been superceded by the 'cache-cleanup' input parameter.

  gradle-home-cache-includes:
    description: Paths within Gradle User Home to cache.
    required: false
@@ -68,11 +82,6 @@ inputs:
    description: Paths within Gradle User Home to exclude from cache.
    required: false

  gradle-home-cache-cleanup:
    description: When 'true', the action will attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
    required: false
    default: false

  # Job summary configuration
  add-job-summary:
    description: Specifies when a Job Summary should be inluded in the action results. Valid values are 'never', 'always' (default), and 'on-failure'.
+18 −7
Changes for docs/setup-gradle.md: 18 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -153,6 +153,23 @@ In certain circumstances it may be desirable to start with a clean Gradle User H
cache-write-only: true
```

### Enabling cache cleanup

The Gradle User Home directory tends to grow over time. When you switch to a new Gradle wrapper version or upgrade a dependency version
the old files are not automatically and immediately removed. While this can make sense in a local environment, in a GitHub Actions environment
it can lead to ever-larger Gradle User Home cache entries being saved and restored.

To avoid this situation, The `setup-gradle` action supports the `cache-cleanup` parameter.
When cache-cleanup is enabled, this feature will attempt to delete any files in the Gradle User Home that were not used by Gradle during the GitHub Actions Workflow, before saving the Gradle User Home to the GitHub Actions cache.

If cache cleanup runs after a failing Gradle build, it is possible that some required files and dependencies will not be touched, and will be removed.
To prevent this scenario, cache cleanup can be configured to run only when all Gradle builds in the Job are successful.

Gradle Home cache cleanup is considered experimental and is disabled by default.  You can enable this feature for the action as follows:
```yaml
cache-cleanup: 'on-success' # Valid values are 'never' (default), 'on-success' and 'always'
```

### Overwriting an existing Gradle User Home

When the action detects that the Gradle User Home caches directory already exists (`~/.gradle/caches`), then by default it will not overwrite the existing content of this directory.
@@ -362,13 +379,7 @@ The Gradle User Home directory tends to grow over time. When you switch to a new
the old files are not automatically and immediately removed. While this can make sense in a local environment, in a GitHub Actions environment
it can lead to ever-larger Gradle User Home cache entries being saved and restored.

To avoid this situation, The `setup-gradle` action supports the `gradle-home-cache-cleanup` parameter.
When enabled, this feature will attempt to delete any files in the Gradle User Home that were not used by Gradle during the GitHub Actions Workflow, before saving the Gradle User Home to the GitHub Actions cache.

Gradle Home cache cleanup is considered experimental and is disabled by default.  You can enable this feature for the action as follows:
```yaml
gradle-home-cache-cleanup: true
```
See [Enabling cache cleanup](#enabling-cache-cleanup) for a mechanism to mitigate this problem.

### Disable local build-cache when remote build-cache is available

+14 −5
Changes for setup-gradle/action.yml: 14 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,20 @@ inputs:
      Configuration-cache data will not be saved/restored without an encryption key being provided.
    required: false

  cache-cleanup:
    description: |
      Specifies if the action should attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
      By default, no cleanup is performed. It can be configured to run every time, or only when all Gradle builds succeed for the Job. 
      Valid values are 'never', 'on-success' and 'always'.
    required: false
    default: 'never'

  gradle-home-cache-cleanup:
    description: When 'true', the action will attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
    required: false
    default: false
    deprecation-message: This input has been superceded by the 'cache-cleanup' input parameter.

  gradle-home-cache-includes:
    description: Paths within Gradle User Home to cache.
    required: false
@@ -51,11 +65,6 @@ inputs:
    description: Paths within Gradle User Home to exclude from cache.
    required: false

  gradle-home-cache-cleanup:
    description: When 'true', the action will attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
    required: false
    default: false

  # Job summary configuration
  add-job-summary:
    description: Specifies when a Job Summary should be inluded in the action results. Valid values are 'never', 'always' (default), and 'on-failure'.
Loading