Skip to content

Commit a735e08

Browse files
authored
Merge pull request #1059 from square/rick/caching_strategies
GH Actions caching tweaks
2 parents 068ff62 + 3f6a188 commit a735e08

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

.github/actions/gradle-task/action.yml

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ inputs :
1616
default : 'zulu'
1717
restore-cache-key :
1818
description : 'The unique identifier for the associated cache. Any other consumers or producers for this cache must use the same name.'
19+
default : 'null'
1920
write-cache-key :
2021
description : 'The unique identifier for the associated cache. Any other consumers or producers for this cache must use the same name.'
22+
default : 'null'
2123

2224
runs :
2325
using : 'composite'
@@ -26,8 +28,8 @@ runs :
2628
- name : Set up JDK
2729
uses : actions/setup-java@v3
2830
with :
29-
distribution : ${{ inputs.distribution }}
30-
java-version : ${{ inputs.java-version }}
31+
distribution : ${{inputs.distribution}}
32+
java-version : ${{inputs.java-version}}
3133

3234
- name : Set Gradle Args for runner OS
3335
id : gradle-args
@@ -42,63 +44,60 @@ runs :
4244
# Attempt to restore from the write-cache-key, or fall back to a partial match for the write key.
4345
# Skipped if the write-cache-key wasn't set.
4446
# This step's "cache_hit" output will only be true if an exact match was found.
45-
- name: restore cache for ${{inputs.write-cache-key}}
46-
id: restore-write-cache
47-
if: ${{inputs.write-cache-key}} != ''
48-
uses: actions/cache/restore@v3
49-
with:
50-
path: |
47+
- name : restore cache for ${{inputs.write-cache-key}}
48+
id : restore-write-cache
49+
if : inputs.write-cache-key != 'null'
50+
uses : actions/cache/restore@v3
51+
with :
52+
path : |
5153
~/.gradle/caches/build-cache-1
52-
~/.gradle/wrapper
53-
key: ${{inputs.write-cache-key}}-${{ hashFiles('**/*.gradle.kt*') }}-${{ hashFiles('**/libs.versions.toml') }}-${{ hashFiles('**/gradle.properties') }}
54-
restore-keys: ${{inputs.write-cache-key}}
55-
enableCrossOsArchive: true
56-
lookup-only: true
54+
./**/build/**
55+
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
56+
restore-keys : ${{runner.os}}-${{inputs.write-cache-key}}
5757

5858
# Attempt to restore from the restore-cache-key, or fall back to a partial match for the restore key.
5959
# Skipped if the restore-cache-key wasn't set, or if the write-cache-key restore had an exact match.
60-
- name: restore cache for ${{inputs.restore-cache-key}}
61-
if: ${{inputs.restore-cache-key}} != '' && steps.restore-write-cache.outputs.cache-hit != 'true'
62-
uses: actions/cache/restore@v3
63-
with:
64-
path: |
60+
- name : restore cache for ${{inputs.restore-cache-key}}
61+
if : inputs.restore-cache-key != 'null' && steps.restore-write-cache.outputs.cache-hit != 'true'
62+
uses : actions/cache/restore@v3
63+
with :
64+
path : |
6565
~/.gradle/caches/build-cache-1
66-
~/.gradle/wrapper
67-
key: ${{inputs.restore-cache-key}}-${{ hashFiles('**/*.gradle.kt*') }}-${{ hashFiles('**/libs.versions.toml') }}-${{ hashFiles('**/gradle.properties') }}
68-
restore-keys: ${{inputs.restore-cache-key}}
69-
enableCrossOsArchive: true
66+
./**/build/**
67+
key : ${{runner.os}}-${{inputs.restore-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
68+
restore-keys : ${{runner.os}}-${{inputs.restore-cache-key}}
7069

71-
- uses: gradle/wrapper-validation-action@v1
70+
- uses : gradle/wrapper-validation-action@v1
7271

7372
# Run the actual task. Note that this still uses gradle-build-action for more fine-grained caching.
74-
- name : Run ${{ inputs.task }}
73+
- name : Run ${{inputs.task}}
7574
uses : gradle/gradle-build-action@v2
7675
with :
7776
# These arguments need to be on a single line. If they're defined with wrapping (using `|`),
7877
# something along the way to the actual CLI invocation gets confused and the jvmargs list
7978
# winds up getting parsed as a single argument.
80-
arguments : ${{ steps.gradle-args.outputs.gradle-property-args }} ${{ inputs.task }} '-Dorg.gradle.jvmargs=${{ steps.gradle-args.outputs.gradle-jvm-args }}'
79+
arguments : ${{steps.gradle-args.outputs.gradle-property-args}} ${{inputs.task}} '-Dorg.gradle.jvmargs=${{steps.gradle-args.outputs.gradle-jvm-args}}'
8180
cache-read-only : false
82-
build-root-directory : ${{ inputs.build-root-directory }}
81+
build-root-directory : ${{inputs.build-root-directory}}
8382
gradle-home-cache-cleanup : true
8483

8584
# Save the build cache to `write-cache-key`.
8685
# Skip if we already had an exact match, or if the key is not set, or if this is a Windows runner.
8786
# Windows runners are welcome to *read* the cross-OS cache, but the directories get weird if
8887
# they try to write to it.
89-
- name: save the '${{inputs.write-cache-key}}' cache
90-
uses: actions/cache/save@v3
91-
id: save-write-cache-key
92-
if: ${{inputs.write-cache-key}} != '' && steps.restore-write-cache.outputs.cache-hit != 'true' && runner.os != 'Windows'
93-
with:
94-
path: |
88+
- name : save the '${{inputs.write-cache-key}}' cache
89+
uses : actions/cache/save@v3
90+
id : save-write-cache-key
91+
if : inputs.write-cache-key != 'null' && steps.restore-write-cache.outputs.cache-hit != 'true'
92+
with :
93+
path : |
9594
~/.gradle/caches/build-cache-1
96-
~/.gradle/wrapper
97-
key: ${{inputs.write-cache-key}}-${{ hashFiles('**/*.gradle.kt*') }}-${{ hashFiles('**/libs.versions.toml') }}-${{ hashFiles('**/gradle.properties') }}
95+
./**/build/**
96+
key : ${{runner.os}}-${{inputs.write-cache-key}}-${{hashFiles('**/*.gradle.kt*')}}-${{hashFiles('**/libs.versions.toml')}}-${{hashFiles('**/gradle.properties')}}
9897

9998
- name : Upload heap dump
10099
if : failure()
101100
uses : actions/upload-artifact@v3
102101
with :
103102
name : heap-dump
104-
path : ${{ github.workspace }}/**/*{.hprof,.log}
103+
path : ${{github.workspace}}/**/*{.hprof,.log}

0 commit comments

Comments
 (0)