mirror of
				https://github.com/gradle/gradle-build-action.git
				synced 2025-11-04 09:58:56 +08:00 
			
		
		
		
	Restore/cache deduplicated files in parallel
This commit is contained in:
		
							
								
								
									
										2
									
								
								dist/main/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/main/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										2
									
								
								dist/post/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/post/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -42,38 +42,36 @@ export class GradleUserHomeCache extends AbstractCache {
 | 
			
		||||
        const globber = await glob.create(markerFilePatterns)
 | 
			
		||||
        const markerFiles = await globber.glob()
 | 
			
		||||
 | 
			
		||||
        const processes: Promise<void>[] = []
 | 
			
		||||
        for (const markerFile of markerFiles) {
 | 
			
		||||
            const p = this.restoreDeduplicatePath(markerFile)
 | 
			
		||||
            processes.push(p)
 | 
			
		||||
        }
 | 
			
		||||
        await Promise.all(processes)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async restoreDeduplicatePath(markerFile: string): Promise<void> {
 | 
			
		||||
        const targetFile = markerFile.substring(
 | 
			
		||||
            0,
 | 
			
		||||
            markerFile.length - MARKER_FILE_EXTENSION.length
 | 
			
		||||
        )
 | 
			
		||||
            core.info(
 | 
			
		||||
                `Found marker file: ${markerFile}. Looking for ${targetFile}`
 | 
			
		||||
            )
 | 
			
		||||
        core.info(`Found marker file: ${markerFile}. Looking for ${targetFile}`)
 | 
			
		||||
 | 
			
		||||
        if (!fs.existsSync(targetFile)) {
 | 
			
		||||
            const key = path.relative(this.getGradleUserHome(), targetFile)
 | 
			
		||||
            const cacheKey = `gradle-dedup-${key}`
 | 
			
		||||
            core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
 | 
			
		||||
 | 
			
		||||
                const restoreKey = await cache.restoreCache(
 | 
			
		||||
                    [targetFile],
 | 
			
		||||
                    cacheKey
 | 
			
		||||
                )
 | 
			
		||||
            const restoreKey = await cache.restoreCache([targetFile], cacheKey)
 | 
			
		||||
            if (restoreKey) {
 | 
			
		||||
                    core.info(
 | 
			
		||||
                        `Restored ${cacheKey} from cache to ${targetFile}`
 | 
			
		||||
                    )
 | 
			
		||||
                core.info(`Restored ${cacheKey} from cache to ${targetFile}`)
 | 
			
		||||
            } else {
 | 
			
		||||
                    core.info(
 | 
			
		||||
                        `Did NOT restore from ${cacheKey} to ${targetFile}`
 | 
			
		||||
                    )
 | 
			
		||||
                core.info(`Did NOT restore from ${cacheKey} to ${targetFile}`)
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            core.info(`Target file already exists: ${targetFile}`)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async reportCacheEntrySize(): Promise<void> {
 | 
			
		||||
        const gradleUserHome = path.resolve(os.homedir(), '.gradle')
 | 
			
		||||
@@ -99,7 +97,15 @@ export class GradleUserHomeCache extends AbstractCache {
 | 
			
		||||
        const globber = await glob.create(targetFilePatterns)
 | 
			
		||||
        const targetFiles = await globber.glob()
 | 
			
		||||
 | 
			
		||||
        const processes: Promise<void>[] = []
 | 
			
		||||
        for (const targetFile of targetFiles) {
 | 
			
		||||
            const p = this.cacheDeplucatePath(targetFile)
 | 
			
		||||
            processes.push(p)
 | 
			
		||||
        }
 | 
			
		||||
        await Promise.all(processes)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private async cacheDeplucatePath(targetFile: string): Promise<void> {
 | 
			
		||||
        core.info(`Deduplicate caching: ${targetFile}`)
 | 
			
		||||
 | 
			
		||||
        const markerFile = `${targetFile}${MARKER_FILE_EXTENSION}`
 | 
			
		||||
@@ -133,7 +139,6 @@ export class GradleUserHomeCache extends AbstractCache {
 | 
			
		||||
        // Delete the target file
 | 
			
		||||
        fs.unlinkSync(targetFile)
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected cacheOutputExists(): boolean {
 | 
			
		||||
        // Need to check for 'caches' directory to avoid incorrect detection on MacOS agents
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user