Skip to content

Commit 3c2b1ce

Browse files
traskCopilot
andauthored
Reduce Gradle cache writers and converge the remote cache (#1247)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 75a6e2b commit 3c2b1ce

5 files changed

Lines changed: 22 additions & 12 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ jobs:
3737
- name: Set up gradle
3838
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
3939
with:
40-
cache-read-only: ${{ github.event_name == 'pull_request' }}
40+
cache-read-only: ${{ github.event_name != 'push' || github.ref_name != github.event.repository.default_branch }}
41+
gradle-home-cache-excludes: >-
42+
${{ matrix.os == 'ubuntu-latest' && secrets.DEVELOCITY_ACCESS_KEY != '' && github.ref_name == github.event.repository.default_branch && 'caches/build-cache-1' || '' }}
4143
4244
- name: Build
4345
run: ./gradlew clean check shadowJar
4446
env:
45-
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
47+
DEVELOCITY_ACCESS_KEY: >-
48+
${{ matrix.os == 'ubuntu-latest' && github.ref_name == github.event.repository.default_branch && secrets.DEVELOCITY_ACCESS_KEY || '' }}
4649
4750
- run: java -cp sdk-usage/build/libs/opentelemetry-examples-sdk-usage-0.1.0-SNAPSHOT-all.jar io.opentelemetry.sdk.example.ConfigureSpanProcessorExample
4851

@@ -62,15 +65,13 @@ jobs:
6265
- name: Set up gradle
6366
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
6467
with:
65-
cache-read-only: ${{ github.event_name == 'pull_request' }}
68+
cache-read-only: true
6669

6770
- name: Run declarative-configuration
6871
working-directory: declarative-configuration
6972
run: |
7073
export OTEL_EXPERIMENTAL_CONFIG_FILE=$(pwd)/otel-sdk-config.yaml
7174
../gradlew run
72-
env:
73-
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
7475
7576
lint:
7677
uses: ./.github/workflows/reusable-lint-check.yml

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
- name: Set up gradle
4343
if: matrix.language == 'java'
4444
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
45+
with:
46+
cache-read-only: true
4547

4648
- name: Initialize CodeQL
4749
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
@@ -57,8 +59,6 @@ jobs:
5759
# --no-daemon is required for codeql to observe the compilation
5860
# (see https://docs.github.com/en/code-security/codeql-cli/getting-started-with-the-codeql-cli/preparing-your-code-for-codeql-analysis#specifying-build-commands)
5961
run: ./gradlew assemble --no-build-cache --no-daemon
60-
env:
61-
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
6262

6363
- name: Perform CodeQL analysis
6464
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6

.github/workflows/oats-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Set up gradle
3636
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
3737
with:
38-
cache-read-only: ${{ github.event_name == 'pull_request' }}
38+
cache-read-only: true
3939

4040
- uses: jdx/mise-action@7e36c90d9ab29c415a2384db3006f3ec8a8cc654 # v4.2.4
4141

.github/workflows/prometheus-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Set up gradle
3232
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
3333
with:
34-
cache-read-only: ${{ github.event_name == 'pull_request' }}
34+
cache-read-only: true
3535

3636
- name: Run Prometheus test
3737
run: .github/scripts/prometheus-test.sh

settings.gradle.kts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ plugins {
1717
val develocityServer = "https://develocity.opentelemetry.io"
1818
val isCI = System.getenv("CI") != null
1919
val develocityAccessKey = System.getenv("DEVELOCITY_ACCESS_KEY") ?: ""
20+
val isRemoteBuildCachePushEnabled = isCI && develocityAccessKey.isNotEmpty()
21+
val shouldDisableLocalBuildCache =
22+
isRemoteBuildCachePushEnabled && System.getenv("GITHUB_REF_NAME") == "main"
2023

2124
develocity {
2225
if (develocityAccessKey.isNotEmpty()) {
@@ -45,9 +48,15 @@ develocity {
4548
}
4649

4750
buildCache {
48-
remote(HttpBuildCache::class) {
49-
url = uri("$develocityServer/cache/")
50-
isPush = isCI && develocityAccessKey.isNotEmpty()
51+
// Tasks restored from the local cache are never pushed to the remote cache. Disable the local
52+
// cache on the authenticated main build so the remote cache converges on complete.
53+
local {
54+
isEnabled = !shouldDisableLocalBuildCache
55+
}
56+
57+
remote(develocity.buildCache) {
58+
server = develocityServer
59+
isPush = isRemoteBuildCachePushEnabled
5160
}
5261
}
5362

0 commit comments

Comments
 (0)