mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-25 17:51:02 -05:00
Merge pull request #67 from gradle/dd/v15
Allow caching to be enabled read-only
This commit is contained in:
commit
eaad2cd2bb
5 changed files with 61 additions and 7 deletions
40
.github/workflows/prod.yml
vendored
40
.github/workflows/prod.yml
vendored
|
@ -7,7 +7,22 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
basic-build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Build using Gradle wrapper
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
build-root-directory: __tests__/samples/basic
|
||||||
|
arguments: test
|
||||||
|
|
||||||
gradle-execution:
|
gradle-execution:
|
||||||
|
needs: basic-build
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
@ -18,11 +33,6 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Test use Gradle wrapper
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
build-root-directory: __tests__/samples/basic
|
|
||||||
arguments: test
|
|
||||||
- name: Test use defined Gradle version
|
- name: Test use defined Gradle version
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
@ -49,6 +59,7 @@ jobs:
|
||||||
arguments: help
|
arguments: help
|
||||||
|
|
||||||
dependencies-cache:
|
dependencies-cache:
|
||||||
|
needs: basic-build
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
@ -64,6 +75,7 @@ jobs:
|
||||||
dependencies-cache-enabled: true
|
dependencies-cache-enabled: true
|
||||||
|
|
||||||
configuration-cache:
|
configuration-cache:
|
||||||
|
needs: basic-build
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
@ -80,8 +92,26 @@ jobs:
|
||||||
dependencies-cache-enabled: true
|
dependencies-cache-enabled: true
|
||||||
# Configuration cache requires dependencies cache, since it assumes dependencies are already downloaded.
|
# Configuration cache requires dependencies cache, since it assumes dependencies are already downloaded.
|
||||||
|
|
||||||
|
cache-read-only:
|
||||||
|
needs: basic-build
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout sources
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Test cache-read-only
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
build-root-directory: __tests__/samples/basic
|
||||||
|
arguments: test --no-daemon
|
||||||
|
dependencies-cache-enabled: true
|
||||||
|
configuration-cache-enabled: true
|
||||||
|
cache-read-only: true
|
||||||
|
|
||||||
failures: # These build invocations are informational only, and are expected to fail
|
failures: # These build invocations are informational only, and are expected to fail
|
||||||
|
needs: basic-build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
|
|
14
README.md
14
README.md
|
@ -144,7 +144,7 @@ The distributions cache is simple and can't be configured further.
|
||||||
The dependencies and configuration cache will compute a cache key in a best effort manner.
|
The dependencies and configuration cache will compute a cache key in a best effort manner.
|
||||||
Keep reading to learn how to better control how they work.
|
Keep reading to learn how to better control how they work.
|
||||||
|
|
||||||
Note that enabling configuration cache without thee dependencies cache is not permitted, since a hit in the configuration cache assumes that dependencies are already present in the local dependencies cache.
|
Note that enabling configuration cache without the dependencies cache is not permitted, since a hit in the configuration cache assumes that dependencies are already present in the local dependencies cache.
|
||||||
|
|
||||||
### Configuring the dependencies and configuration caches
|
### Configuring the dependencies and configuration caches
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
|
2
dist/post/index.js
vendored
2
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -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