Combine java-toolchain entry definitions

- Remove configuration parameter for cache-entry-definitions. This allows richer modelling of extracted entries.
- Include both *.zip and *.tar.gz in entry definition for java-toolchains.
This commit is contained in:
Daz DeBoer 2021-12-29 13:36:24 -07:00
parent c157d0a332
commit 12fc52a49a
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
5 changed files with 52 additions and 47 deletions

View file

@ -22,21 +22,13 @@ jobs:
- name: Setup Gradle - name: Setup Gradle
uses: ./ uses: ./
with: with:
# Add "wrapper" to main cache entry and remove 'wrapper-zips' cache entry # Add "enterprise" to main cache entry but omit "notifications"
# Exclude build-cache from main cache entry
gradle-home-cache-includes: | gradle-home-cache-includes: |
caches caches
notifications enterprise
wrapper # Exclude build-cache from main cache entry
gradle-home-cache-excludes: | gradle-home-cache-excludes: |
caches/build-cache-1 caches/build-cache-1
gradle-home-extracted-cache-entries: |
[
["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"],
["dependencies", "caches/modules-*/files-*/*/*/*/*/"],
["instrumented-jars", "caches/jars-*/*/"],
["kotlin-dsl", "caches/*/kotlin-dsl/*/*/"]
]
- name: Build using Gradle wrapper - name: Build using Gradle wrapper
working-directory: __tests__/samples/groovy-dsl working-directory: __tests__/samples/groovy-dsl
run: ./gradlew test run: ./gradlew test
@ -57,17 +49,9 @@ jobs:
# Use the same configuration when restoring state from cache # Use the same configuration when restoring state from cache
gradle-home-cache-includes: | gradle-home-cache-includes: |
caches caches
notifications enterprise
wrapper
gradle-home-cache-excludes: | gradle-home-cache-excludes: |
caches/build-cache-1 caches/build-cache-1
gradle-home-extracted-cache-entries: |
[
["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"],
["dependencies", "caches/modules-*/files-*/*/*/*/*/"],
["instrumented-jars", "caches/jars-*/*/"],
["kotlin-dsl", "caches/*/kotlin-dsl/*/*/"]
]
cache-read-only: true cache-read-only: true
- name: Execute Gradle build with --offline - name: Execute Gradle build with --offline
working-directory: __tests__/samples/groovy-dsl working-directory: __tests__/samples/groovy-dsl

View file

@ -81,9 +81,10 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup Gradle with no cache extracted cache entries restored - name: Setup Gradle with no cache extracted cache entries restored
uses: ./ uses: ./
env:
GRADLE_BUILD_ACTION_NO_EXTRACTED_ENTRIES: true
with: with:
cache-read-only: true cache-read-only: true
gradle-home-extracted-cache-entries: '[]'
- name: Check execute Gradle build with configuration cache enabled (but not restored) - name: Check execute Gradle build with configuration cache enabled (but not restored)
working-directory: __tests__/samples/groovy-dsl working-directory: __tests__/samples/groovy-dsl
run: ./gradlew test --configuration-cache run: ./gradlew test --configuration-cache

View file

@ -72,9 +72,10 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup Gradle with no extracted cache entries restored - name: Setup Gradle with no extracted cache entries restored
uses: ./ uses: ./
env:
GRADLE_BUILD_ACTION_NO_EXTRACTED_ENTRIES: true
with: with:
cache-read-only: true cache-read-only: true
gradle-home-extracted-cache-entries: '[]'
- name: Check executee Gradle build - name: Check executee Gradle build
working-directory: __tests__/samples/groovy-dsl working-directory: __tests__/samples/groovy-dsl
run: ./gradlew test run: ./gradlew test

View file

@ -55,19 +55,6 @@ inputs:
description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL). description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL).
required: false required: false
default: ${{ toJSON(matrix) }} default: ${{ toJSON(matrix) }}
gradle-home-extracted-cache-entries:
description: Names and patterns of artifacts in Gradle User Home to cache separately. (EXPERIMENTAL - may be changed/removed without notice)
required: false
default: |
[
["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"],
["wrapper-zips", "wrapper/dists/*/*/*.zip"],
["java-toolchains-win", "jdks/*.zip"],
["java-toolchains-nix", "jdks/*.tar.gz"],
["dependencies", "caches/modules-*/files-*/*/*/*/*"],
["instrumented-jars", "caches/jars-*/*"],
["kotlin-dsl", "caches/*/kotlin-dsl/*/*"]
]
outputs: outputs:
build-scan-url: build-scan-url:

View file

@ -12,7 +12,7 @@ const META_FILE = 'cache-metadata.json'
const INCLUDE_PATHS_PARAMETER = 'gradle-home-cache-includes' const INCLUDE_PATHS_PARAMETER = 'gradle-home-cache-includes'
const EXCLUDE_PATHS_PARAMETER = 'gradle-home-cache-excludes' const EXCLUDE_PATHS_PARAMETER = 'gradle-home-cache-excludes'
const EXTRACTED_CACHE_ENTRIES_PARAMETER = 'gradle-home-extracted-cache-entries' const NO_EXTRACTED_ENTRIES_VAR = 'GRADLE_BUILD_ACTION_NO_EXTRACTED_ENTRIES'
/** /**
* Represents the result of attempting to load or store an extracted cache entry. * Represents the result of attempting to load or store an extracted cache entry.
@ -40,6 +40,21 @@ class ExtractedCacheEntryMetadata {
entries: ExtractedCacheEntry[] = [] entries: ExtractedCacheEntry[] = []
} }
/**
* The specification for a type of extracted cache entry.
*/
class ExtractedCacheEntryDefinition {
artifactType: string
pattern: string
bundle: boolean
constructor(artifactType: string, pattern: string, bundle: boolean) {
this.artifactType = artifactType
this.pattern = pattern
this.bundle = bundle
}
}
/** /**
* Caches and restores the entire Gradle User Home directory, extracting entries containing common artifacts * Caches and restores the entire Gradle User Home directory, extracting entries containing common artifacts
* for more efficient storage. * for more efficient storage.
@ -63,7 +78,6 @@ export class GradleUserHomeCache extends AbstractCache {
* Each extracted cache entry is restored in parallel, except when debugging is enabled. * Each extracted cache entry is restored in parallel, except when debugging is enabled.
*/ */
private async restoreExtractedCacheEntries(listener: CacheListener): Promise<void> { private async restoreExtractedCacheEntries(listener: CacheListener): Promise<void> {
const extractedCacheEntryDefinitions = this.getExtractedCacheEntryDefinitions()
const previouslyExtractedCacheEntries = this.loadExtractedCacheEntries() const previouslyExtractedCacheEntries = this.loadExtractedCacheEntries()
const processes: Promise<ExtractedCacheEntry>[] = [] const processes: Promise<ExtractedCacheEntry>[] = []
@ -73,8 +87,8 @@ export class GradleUserHomeCache extends AbstractCache {
const entryListener = listener.entry(cacheEntry.pattern) const entryListener = listener.entry(cacheEntry.pattern)
// Handle case where the extracted-cache-entry definitions have been changed // Handle case where the extracted-cache-entry definitions have been changed
if (extractedCacheEntryDefinitions.get(artifactType) === undefined) { if (process.env[NO_EXTRACTED_ENTRIES_VAR] === 'true') {
core.info(`Found extracted cache entry for ${artifactType} but no such entry defined`) core.info(`Not restoring any extracted cache entries for ${artifactType}`)
entryListener.markRequested('EXTRACTED_ENTRY_NOT_DEFINED') entryListener.markRequested('EXTRACTED_ENTRY_NOT_DEFINED')
} else { } else {
processes.push( processes.push(
@ -137,7 +151,6 @@ export class GradleUserHomeCache extends AbstractCache {
/** /**
* Saves any artifacts that are configured to be cached separately, based on the extracted cache entry definitions. * Saves any artifacts that are configured to be cached separately, based on the extracted cache entry definitions.
* These definitions are normally fixed, but can be overridden by the `gradle-home-extracted-cache-entries` parameter.
* Each entry is extracted and saved in parallel, except when debugging is enabled. * Each entry is extracted and saved in parallel, except when debugging is enabled.
*/ */
private async saveExtractedCacheEntries(listener: CacheListener): Promise<void> { private async saveExtractedCacheEntries(listener: CacheListener): Promise<void> {
@ -146,7 +159,11 @@ export class GradleUserHomeCache extends AbstractCache {
const previouslyRestoredEntries = this.loadExtractedCacheEntries() const previouslyRestoredEntries = this.loadExtractedCacheEntries()
const cacheActions: Promise<ExtractedCacheEntry>[] = [] const cacheActions: Promise<ExtractedCacheEntry>[] = []
for (const [artifactType, pattern] of cacheEntryDefinitions) { // For each cache entry definition, determine if it has already been restored, and if not, extract it
for (const cacheEntryDefinition of cacheEntryDefinitions) {
const artifactType = cacheEntryDefinition.artifactType
const pattern = cacheEntryDefinition.pattern
// Find all matching files for this cache entry definition // Find all matching files for this cache entry definition
const globber = await glob.create(pattern, { const globber = await glob.create(pattern, {
implicitDescendants: false, implicitDescendants: false,
@ -159,7 +176,7 @@ export class GradleUserHomeCache extends AbstractCache {
continue continue
} }
if (this.isBundlePattern(pattern)) { if (cacheEntryDefinition.bundle) {
// For an extracted "bundle", use the defined pattern and cache all matching files in a single entry. // For an extracted "bundle", use the defined pattern and cache all matching files in a single entry.
cacheActions.push( cacheActions.push(
this.saveExtractedCacheEntry( this.saveExtractedCacheEntry(
@ -300,12 +317,27 @@ export class GradleUserHomeCache extends AbstractCache {
/** /**
* Return the extracted cache entry definitions, which determine which artifacts will be cached * Return the extracted cache entry definitions, which determine which artifacts will be cached
* separately from the rest of the Gradle User Home cache entry. * separately from the rest of the Gradle User Home cache entry.
* This is normally a fixed set, but can be overridden by the `gradle-home-extracted-cache-entries` parameter.
*/ */
private getExtractedCacheEntryDefinitions(): Map<string, string> { private getExtractedCacheEntryDefinitions(): ExtractedCacheEntryDefinition[] {
const rawDefinitions = core.getInput(EXTRACTED_CACHE_ENTRIES_PARAMETER) const entryDefinition = (
const parsedDefinitions = JSON.parse(rawDefinitions) artifactType: string,
return new Map(Array.from(parsedDefinitions, ([key, value]) => [key, path.resolve(this.gradleUserHome, value)])) patterns: string[],
bundle: boolean
): ExtractedCacheEntryDefinition => {
const resolvedPattern = patterns.map(x => this.resolveCachePath(x)).join('\n')
return new ExtractedCacheEntryDefinition(artifactType, resolvedPattern, bundle)
}
const definitions = [
entryDefinition('generated-gradle-jars', ['caches/*/generated-gradle-jars/*.jar'], false),
entryDefinition('wrapper-zips', ['wrapper/dists/*/*/*.zip'], false),
entryDefinition('java-toolchains', ['jdks/*.zip', 'jdks/*.tar.gz'], false),
entryDefinition('dependencies', ['caches/modules-*/files-*/*/*/*/*'], true),
entryDefinition('instrumented-jars', ['caches/jars-*/*'], true),
entryDefinition('kotlin-dsl', ['caches/*/kotlin-dsl/*/*'], true)
]
this.debug(`Using extracted cache entry definitions: ${JSON.stringify(definitions, null, 2)}`)
return definitions
} }
/** /**