mirror of
				https://kkgithub.com/actions/cache.git
				synced 2025-11-04 12:41:50 +08:00 
			
		
		
		
	Consuming 3.0 actions/cache
This commit is contained in:
		
							
								
								
									
										71
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										71
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							@ -46792,24 +46792,13 @@ function run() {
 | 
			
		||||
            const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
 | 
			
		||||
                required: true
 | 
			
		||||
            });
 | 
			
		||||
            try {
 | 
			
		||||
                yield cache.saveCache(cachePaths, primaryKey, {
 | 
			
		||||
                    uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize)
 | 
			
		||||
                });
 | 
			
		||||
                core.info(`Cache saved with key: ${primaryKey}`);
 | 
			
		||||
            }
 | 
			
		||||
            catch (error) {
 | 
			
		||||
                const typedError = error;
 | 
			
		||||
                if (typedError.name === cache.ValidationError.name) {
 | 
			
		||||
                    throw error;
 | 
			
		||||
                }
 | 
			
		||||
                else if (typedError.name === cache.ReserveCacheError.name) {
 | 
			
		||||
                    core.info(typedError.message);
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    utils.logWarning(typedError.message);
 | 
			
		||||
                }
 | 
			
		||||
            const cacheId = yield cache.saveCache(cachePaths, primaryKey, {
 | 
			
		||||
                uploadChunkSize: utils.getInputAsInt(constants_1.Inputs.UploadChunkSize)
 | 
			
		||||
            });
 | 
			
		||||
            if (cacheId == -1) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            core.info(`Cache saved with key: ${primaryKey}`);
 | 
			
		||||
        }
 | 
			
		||||
        catch (error) {
 | 
			
		||||
            utils.logWarning(error.message);
 | 
			
		||||
@ -46948,17 +46937,18 @@ function restoreCache(paths, primaryKey, restoreKeys, options) {
 | 
			
		||||
            checkKey(key);
 | 
			
		||||
        }
 | 
			
		||||
        const compressionMethod = yield utils.getCompressionMethod();
 | 
			
		||||
        // path are needed to compute version
 | 
			
		||||
        const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, {
 | 
			
		||||
            compressionMethod
 | 
			
		||||
        });
 | 
			
		||||
        if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) {
 | 
			
		||||
            // Cache not found
 | 
			
		||||
            return undefined;
 | 
			
		||||
        }
 | 
			
		||||
        const archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod));
 | 
			
		||||
        core.debug(`Archive Path: ${archivePath}`);
 | 
			
		||||
        let archivePath = '';
 | 
			
		||||
        try {
 | 
			
		||||
            // path are needed to compute version
 | 
			
		||||
            const cacheEntry = yield cacheHttpClient.getCacheEntry(keys, paths, {
 | 
			
		||||
                compressionMethod
 | 
			
		||||
            });
 | 
			
		||||
            if (!(cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.archiveLocation)) {
 | 
			
		||||
                // Cache not found
 | 
			
		||||
                return undefined;
 | 
			
		||||
            }
 | 
			
		||||
            archivePath = path.join(yield utils.createTempDirectory(), utils.getCacheFileName(compressionMethod));
 | 
			
		||||
            core.debug(`Archive Path: ${archivePath}`);
 | 
			
		||||
            // Download the cache from the cache entry
 | 
			
		||||
            yield cacheHttpClient.downloadCache(cacheEntry.archiveLocation, archivePath, options);
 | 
			
		||||
            if (core.isDebug()) {
 | 
			
		||||
@ -46968,6 +46958,17 @@ function restoreCache(paths, primaryKey, restoreKeys, options) {
 | 
			
		||||
            core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
 | 
			
		||||
            yield tar_1.extractTar(archivePath, compressionMethod);
 | 
			
		||||
            core.info('Cache restored successfully');
 | 
			
		||||
            return cacheEntry.cacheKey;
 | 
			
		||||
        }
 | 
			
		||||
        catch (error) {
 | 
			
		||||
            const typedError = error;
 | 
			
		||||
            if (typedError.name === ValidationError.name) {
 | 
			
		||||
                throw error;
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                // Supress all non-validation cache related errors because caching should be optional
 | 
			
		||||
                core.warning(`Failed to restore: ${error.message}`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        finally {
 | 
			
		||||
            // Try to delete the archive to save space
 | 
			
		||||
@ -46978,7 +46979,7 @@ function restoreCache(paths, primaryKey, restoreKeys, options) {
 | 
			
		||||
                core.debug(`Failed to delete archive: ${error}`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return cacheEntry.cacheKey;
 | 
			
		||||
        return undefined;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
exports.restoreCache = restoreCache;
 | 
			
		||||
@ -46996,7 +46997,7 @@ function saveCache(paths, key, options) {
 | 
			
		||||
        checkPaths(paths);
 | 
			
		||||
        checkKey(key);
 | 
			
		||||
        const compressionMethod = yield utils.getCompressionMethod();
 | 
			
		||||
        let cacheId = null;
 | 
			
		||||
        let cacheId = -1;
 | 
			
		||||
        const cachePaths = yield utils.resolvePaths(paths);
 | 
			
		||||
        core.debug('Cache Paths:');
 | 
			
		||||
        core.debug(`${JSON.stringify(cachePaths)}`);
 | 
			
		||||
@ -47035,6 +47036,18 @@ function saveCache(paths, key, options) {
 | 
			
		||||
            core.debug(`Saving Cache (ID: ${cacheId})`);
 | 
			
		||||
            yield cacheHttpClient.saveCache(cacheId, archivePath, options);
 | 
			
		||||
        }
 | 
			
		||||
        catch (error) {
 | 
			
		||||
            const typedError = error;
 | 
			
		||||
            if (typedError.name === ValidationError.name) {
 | 
			
		||||
                throw error;
 | 
			
		||||
            }
 | 
			
		||||
            else if (typedError.name === ReserveCacheError.name) {
 | 
			
		||||
                core.info(`Failed to save: ${typedError.message}`);
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                core.warning(`Failed to save: ${typedError.message}`);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        finally {
 | 
			
		||||
            // Try to delete the archive to save space
 | 
			
		||||
            try {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user