mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-26 02:00:58 -05:00
Allow use of caches 'read-only'
To avoid evicting useful entries, some pipeline may benefit from using existing cache entries without writing any changes back to the cache. Fixes #62
This commit is contained in:
parent
543cacb256
commit
a693ccda4b
4 changed files with 31 additions and 0 deletions
7
.github/workflows/prod.yml
vendored
7
.github/workflows/prod.yml
vendored
|
@ -62,6 +62,13 @@ jobs:
|
||||||
build-root-directory: __tests__/samples/basic
|
build-root-directory: __tests__/samples/basic
|
||||||
arguments: test --no-daemon
|
arguments: test --no-daemon
|
||||||
dependencies-cache-enabled: true
|
dependencies-cache-enabled: true
|
||||||
|
- name: Test dependencies-cache-enabled
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
build-root-directory: __tests__/samples/basic
|
||||||
|
arguments: test --no-daemon
|
||||||
|
dependencies-cache-enabled: true
|
||||||
|
cache-read-only: true
|
||||||
|
|
||||||
configuration-cache:
|
configuration-cache:
|
||||||
strategy:
|
strategy:
|
||||||
|
|
12
README.md
12
README.md
|
@ -187,6 +187,18 @@ dependencies-cache-key: gradle/dependency-locks/**
|
||||||
dependencies-cache-exact: true
|
dependencies-cache-exact: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using the caches read-only
|
||||||
|
|
||||||
|
Cache storage space is limited for GitHub actions, and writing new cache entries can trigger the deletion of exising entries.
|
||||||
|
In some circumstances, it makes sense for a Gradle invocation to use any existing cache entries but not to write and changes back.
|
||||||
|
For example, you may want to write cache entries for builds on your `main` branch, but not for any PR build invocations.
|
||||||
|
|
||||||
|
Use the following configuration to avoid writing cache entries for the action invocation:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
cache-read-only: true
|
||||||
|
```
|
||||||
|
|
||||||
## Build scans
|
## Build scans
|
||||||
|
|
||||||
If your build publishes a [build scan](https://gradle.com/build-scans/) the `gradle-build-action` action will emit the link to the published build scan as an output named `build-scan-url`.
|
If your build publishes a [build scan](https://gradle.com/build-scans/) the `gradle-build-action` action will emit the link to the published build scan as an output named `build-scan-url`.
|
||||||
|
|
|
@ -51,6 +51,10 @@ inputs:
|
||||||
description: Whether to restore only if exact match, default to 'false'
|
description: Whether to restore only if exact match, default to 'false'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
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: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
build-scan-url:
|
build-scan-url:
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
import * as cacheWrapper from './cache-wrapper'
|
import * as cacheWrapper from './cache-wrapper'
|
||||||
import * as cacheDependencies from './cache-dependencies'
|
import * as cacheDependencies from './cache-dependencies'
|
||||||
import * as cacheConfiguration from './cache-configuration'
|
import * as cacheConfiguration from './cache-configuration'
|
||||||
|
|
||||||
// Invoked by GitHub Actions
|
// Invoked by GitHub Actions
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
|
if (isCacheReadOnly()) return
|
||||||
|
|
||||||
await cacheWrapper.cacheWrapperDist()
|
await cacheWrapper.cacheWrapperDist()
|
||||||
await cacheDependencies.cacheDependencies()
|
await cacheDependencies.cacheDependencies()
|
||||||
await cacheConfiguration.cacheConfiguration()
|
await cacheConfiguration.cacheConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isCacheReadOnly(): boolean {
|
||||||
|
return core.getBooleanInput('cache-read-only')
|
||||||
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
Loading…
Reference in a new issue