From 0a36ca9fb8a7acc820f34da9116f389a13dc67e2 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Fri, 28 Jan 2022 09:55:33 -0700 Subject: [PATCH 1/3] Use 'cache-read-only' for all but default_branch Cache entries _written_ from jobs run on a non-default branch will be private to other jobs for that branch. When development flow involves working on a feature branch and then merging into 'main', these branch-private cache entries can result in eviction of other (shared) cache entries generated for the default branch. With this change, we make the recommended setup the default, by running with `cache-read-only: true` for any jobs run on a non-default branch. These jobs will be able to read cache entries written from the main branch, but will not write any cache entries. Fixes #143 --- action.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 9e5223a..1e42ea7 100644 --- a/action.yml +++ b/action.yml @@ -14,11 +14,13 @@ inputs: default: false cache-read-only: - description: When 'true', existing entries will be read from the cache but no entries will be written. + description: | + When 'true', existing entries will be read from the cache but no entries will be written. + By default this value is 'false' for workflows on the GitHub default branch and 'true' for workflows on other branches. required: false - default: false + default: ${{ github.ref_name != github.event.repository.default_branch }} # e.g. Use the following setting to only write cache entries from your 'main' branch - # cache-read-only: ${{ github.ref != 'refs/heads/main' }} + # cache-read-only: ${{ github.ref_name != 'main' }} gradle-home-cache-includes: description: Paths within Gradle User Home to cache. From b02f4f1968f1dab6ba1080fb52df0795021f896b Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 4 Jun 2022 11:28:12 -0600 Subject: [PATCH 2/3] Disable cache-read-only when cache-write-only is set --- action.yml | 11 +++++++---- src/cache-utils.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 1e42ea7..02e3c09 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,13 @@ inputs: # e.g. Use the following setting to only write cache entries from your 'main' branch # cache-read-only: ${{ github.ref_name != 'main' }} + cache-write-only: + description: | + When 'true', entries will not be restored from the cache but will be saved at the end of the Job. + Setting this to 'true' implies cache-read-only will be 'false'. + required: false + default: false + gradle-home-cache-includes: description: Paths within Gradle User Home to cache. required: false @@ -52,10 +59,6 @@ inputs: # The following action properties allow fine-grained tweaking of the action caching behaviour. # These properties are experimental and not (yet) designed for production use, and may change without notice in a subsequent release of `gradle-build-action`. # Use at your own risk! - cache-write-only: - description: When 'true', entries will not be restored from the cache but will be saved at the end of the Job. This allows a 'clean' cache entry to be written. - required: false - default: false gradle-home-cache-strict-match: description: When 'true', the action will not attempt to restore the Gradle User Home entries from other Jobs. required: false diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 5b605ef..d5087a3 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -27,7 +27,7 @@ export function isCacheDisabled(): boolean { } export function isCacheReadOnly(): boolean { - return core.getBooleanInput(CACHE_READONLY_PARAMETER) + return !isCacheWriteOnly() && core.getBooleanInput(CACHE_READONLY_PARAMETER) } export function isCacheWriteOnly(): boolean { From 00cdd4dcf984c7c9d46aa84f36c81706b0525b5c Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 4 Jun 2022 11:37:13 -0600 Subject: [PATCH 3/3] Explicitly allow cache-write for test invocations The `gradle-build-action` test workflows need to write cache entries, even when run on non-default branches. This change add explicit configuration to set `cache-read-only: false` when cache writing is required. --- .github/workflows/integ-test-action-inputs-caching.yml | 1 + .github/workflows/integ-test-execution-with-caching.yml | 1 + .github/workflows/integ-test-execution.yml | 2 ++ .github/workflows/integ-test-provision-gradle-versions.yml | 2 ++ .../workflows/integ-test-restore-configuration-cache.yml | 6 ++++++ .github/workflows/integ-test-restore-custom-gradle-home.yml | 2 ++ .github/workflows/integ-test-restore-gradle-home.yml | 2 ++ .github/workflows/integ-test-restore-java-toolchain.yml | 2 ++ .github/workflows/integ-test-sample-gradle-plugin.yml | 2 ++ .github/workflows/integ-test-sample-kotlin-dsl.yml | 2 ++ 10 files changed, 22 insertions(+) diff --git a/.github/workflows/integ-test-action-inputs-caching.yml b/.github/workflows/integ-test-action-inputs-caching.yml index 96f530d..26b2e32 100644 --- a/.github/workflows/integ-test-action-inputs-caching.yml +++ b/.github/workflows/integ-test-action-inputs-caching.yml @@ -31,6 +31,7 @@ jobs: - name: Setup Gradle uses: ./ with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches # Add "enterprise" to main cache entry but omit "notifications" gradle-home-cache-includes: | caches diff --git a/.github/workflows/integ-test-execution-with-caching.yml b/.github/workflows/integ-test-execution-with-caching.yml index 428777f..c1028ef 100644 --- a/.github/workflows/integ-test-execution-with-caching.yml +++ b/.github/workflows/integ-test-execution-with-caching.yml @@ -31,6 +31,7 @@ jobs: - name: Execute Gradle build uses: ./ with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches build-root-directory: .github/workflow-samples/groovy-dsl arguments: test diff --git a/.github/workflows/integ-test-execution.yml b/.github/workflows/integ-test-execution.yml index 178397d..054164c 100644 --- a/.github/workflows/integ-test-execution.yml +++ b/.github/workflows/integ-test-execution.yml @@ -36,6 +36,7 @@ jobs: - name: Test use defined Gradle version uses: ./ with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches gradle-version: 6.9 build-root-directory: .github/workflow-samples/no-wrapper arguments: help -DgradleVersionCheck=6.9 @@ -72,6 +73,7 @@ jobs: uses: ./ id: gradle with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches gradle-version: ${{matrix.gradle}} build-root-directory: .github/workflow-samples/no-wrapper${{ matrix.build-root-suffix }} arguments: help -DgradleVersionCheck=${{matrix.gradle}} diff --git a/.github/workflows/integ-test-provision-gradle-versions.yml b/.github/workflows/integ-test-provision-gradle-versions.yml index dc77b2a..aa11831 100644 --- a/.github/workflows/integ-test-provision-gradle-versions.yml +++ b/.github/workflows/integ-test-provision-gradle-versions.yml @@ -36,6 +36,7 @@ jobs: - name: Setup Gradle with v6.9 uses: ./ with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches gradle-version: 6.9 - name: Test uses Gradle v6.9 working-directory: .github/workflow-samples/no-wrapper @@ -74,6 +75,7 @@ jobs: - name: Setup Gradle uses: ./ with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches gradle-version: ${{ matrix.gradle }} - name: Run Gradle build id: gradle diff --git a/.github/workflows/integ-test-restore-configuration-cache.yml b/.github/workflows/integ-test-restore-configuration-cache.yml index 2861d53..462a464 100644 --- a/.github/workflows/integ-test-restore-configuration-cache.yml +++ b/.github/workflows/integ-test-restore-configuration-cache.yml @@ -32,6 +32,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Groovy build with configuration-cache enabled working-directory: .github/workflow-samples/groovy-dsl run: ./gradlew test --configuration-cache @@ -102,6 +104,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Execute 'help' with configuration-cache enabled working-directory: .github/workflow-samples/kotlin-dsl run: ./gradlew help --configuration-cache @@ -121,6 +125,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Execute 'test' with configuration-cache enabled working-directory: .github/workflow-samples/kotlin-dsl run: ./gradlew test --configuration-cache diff --git a/.github/workflows/integ-test-restore-custom-gradle-home.yml b/.github/workflows/integ-test-restore-custom-gradle-home.yml index 09b9890..35dd471 100644 --- a/.github/workflows/integ-test-restore-custom-gradle-home.yml +++ b/.github/workflows/integ-test-restore-custom-gradle-home.yml @@ -30,6 +30,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Build using Gradle wrapper working-directory: .github/workflow-samples/groovy-dsl run: ./gradlew test --info diff --git a/.github/workflows/integ-test-restore-gradle-home.yml b/.github/workflows/integ-test-restore-gradle-home.yml index 8e24ae2..59d0296 100644 --- a/.github/workflows/integ-test-restore-gradle-home.yml +++ b/.github/workflows/integ-test-restore-gradle-home.yml @@ -31,6 +31,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Build using Gradle wrapper working-directory: .github/workflow-samples/groovy-dsl run: ./gradlew test diff --git a/.github/workflows/integ-test-restore-java-toolchain.yml b/.github/workflows/integ-test-restore-java-toolchain.yml index ab4dd12..4275e58 100644 --- a/.github/workflows/integ-test-restore-java-toolchain.yml +++ b/.github/workflows/integ-test-restore-java-toolchain.yml @@ -30,6 +30,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Build using Gradle wrapper working-directory: .github/workflow-samples/java-toolchain run: ./gradlew test --info diff --git a/.github/workflows/integ-test-sample-gradle-plugin.yml b/.github/workflows/integ-test-sample-gradle-plugin.yml index 0f8979a..554fc6a 100644 --- a/.github/workflows/integ-test-sample-gradle-plugin.yml +++ b/.github/workflows/integ-test-sample-gradle-plugin.yml @@ -30,6 +30,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Build gradle-plugin project working-directory: .github/workflow-samples/gradle-plugin run: ./gradlew build diff --git a/.github/workflows/integ-test-sample-kotlin-dsl.yml b/.github/workflows/integ-test-sample-kotlin-dsl.yml index d518039..6498a75 100644 --- a/.github/workflows/integ-test-sample-kotlin-dsl.yml +++ b/.github/workflows/integ-test-sample-kotlin-dsl.yml @@ -30,6 +30,8 @@ jobs: uses: ./.github/actions/download-dist - name: Setup Gradle uses: ./ + with: + cache-read-only: false # For testing, allow writing cache entries on non-default branches - name: Build kotlin-dsl project working-directory: .github/workflow-samples/kotlin-dsl run: ./gradlew build