mirror of
				https://github.com/actions/setup-go.git
				synced 2025-11-04 01:13:43 +00:00 
			
		
		
		
	Add caching of the compiler's temporary files
This commit is contained in:
		
							parent
							
								
									c8ed3f974d
								
							
						
					
					
						commit
						661954d154
					
				
							
								
								
									
										23
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								dist/cache-save/index.js
									
									
									
									
										vendored
									
									
								
							@ -4036,11 +4036,16 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
 | 
				
			|||||||
    return obtainedPackageManager;
 | 
					    return obtainedPackageManager;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    const stdout = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
 | 
					    let pathList = [];
 | 
				
			||||||
    if (!stdout) {
 | 
					    for (let command of packageManagerInfo.cacheFolderCommandList) {
 | 
				
			||||||
        throw new Error(`Could not get cache folder path.`);
 | 
					        pathList.push(yield exports.getCommandOutput(command));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return stdout;
 | 
					    for (let path of pathList) {
 | 
				
			||||||
 | 
					        if (!path) {
 | 
				
			||||||
 | 
					            throw new Error(`Could not get cache folder paths.`);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return pathList;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
function isGhes() {
 | 
					function isGhes() {
 | 
				
			||||||
    const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
 | 
					    const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
 | 
				
			||||||
@ -49202,15 +49207,17 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			|||||||
    const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
 | 
					    const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
 | 
				
			||||||
    const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
 | 
					    const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
 | 
				
			||||||
    const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
 | 
					    const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
 | 
				
			||||||
    if (!fs_1.default.existsSync(cachePath)) {
 | 
					    for (let path of cachePath) {
 | 
				
			||||||
        throw new Error(`Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`);
 | 
					        if (!fs_1.default.existsSync(path)) {
 | 
				
			||||||
 | 
					            throw new Error(`Cache folder path is retrieved but doesn't exist on disk: ${path}`);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (primaryKey === state) {
 | 
					    if (primaryKey === state) {
 | 
				
			||||||
        core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
 | 
					        core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        yield cache.saveCache([cachePath], primaryKey);
 | 
					        yield cache.saveCache(cachePath, primaryKey);
 | 
				
			||||||
        core.info(`Cache saved with the key: ${primaryKey}`);
 | 
					        core.info(`Cache saved with the key: ${primaryKey}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (error) {
 | 
					    catch (error) {
 | 
				
			||||||
@ -49315,7 +49322,7 @@ exports.supportedPackageManagers = void 0;
 | 
				
			|||||||
exports.supportedPackageManagers = {
 | 
					exports.supportedPackageManagers = {
 | 
				
			||||||
    default: {
 | 
					    default: {
 | 
				
			||||||
        dependencyFilePattern: 'go.sum',
 | 
					        dependencyFilePattern: 'go.sum',
 | 
				
			||||||
        getCacheFolderCommand: 'go env GOMODCACHE'
 | 
					        cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										17
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -4298,11 +4298,16 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
 | 
				
			|||||||
    return obtainedPackageManager;
 | 
					    return obtainedPackageManager;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
 | 
					exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
 | 
				
			||||||
    const stdout = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
 | 
					    let pathList = [];
 | 
				
			||||||
    if (!stdout) {
 | 
					    for (let command of packageManagerInfo.cacheFolderCommandList) {
 | 
				
			||||||
        throw new Error(`Could not get cache folder path.`);
 | 
					        pathList.push(yield exports.getCommandOutput(command));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return stdout;
 | 
					    for (let path of pathList) {
 | 
				
			||||||
 | 
					        if (!path) {
 | 
				
			||||||
 | 
					            throw new Error(`Could not get cache folder paths.`);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return pathList;
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
function isGhes() {
 | 
					function isGhes() {
 | 
				
			||||||
    const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
 | 
					    const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
 | 
				
			||||||
@ -37259,7 +37264,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
 | 
				
			|||||||
    const primaryKey = `${platform}-go${versionSpec}-${fileHash}`;
 | 
					    const primaryKey = `${platform}-go${versionSpec}-${fileHash}`;
 | 
				
			||||||
    core.debug(`primary key is ${primaryKey}`);
 | 
					    core.debug(`primary key is ${primaryKey}`);
 | 
				
			||||||
    core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
 | 
					    core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
 | 
				
			||||||
    const cacheKey = yield cache.restoreCache([cachePath], primaryKey);
 | 
					    const cacheKey = yield cache.restoreCache(cachePath, primaryKey);
 | 
				
			||||||
    core.setOutput('cache-hit', Boolean(cacheKey));
 | 
					    core.setOutput('cache-hit', Boolean(cacheKey));
 | 
				
			||||||
    if (!cacheKey) {
 | 
					    if (!cacheKey) {
 | 
				
			||||||
        core.info(`Cache is not found`);
 | 
					        core.info(`Cache is not found`);
 | 
				
			||||||
@ -51205,7 +51210,7 @@ exports.supportedPackageManagers = void 0;
 | 
				
			|||||||
exports.supportedPackageManagers = {
 | 
					exports.supportedPackageManagers = {
 | 
				
			||||||
    default: {
 | 
					    default: {
 | 
				
			||||||
        dependencyFilePattern: 'go.sum',
 | 
					        dependencyFilePattern: 'go.sum',
 | 
				
			||||||
        getCacheFolderCommand: 'go env GOMODCACHE'
 | 
					        cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -34,7 +34,7 @@ export const restoreCache = async (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  core.saveState(State.CachePrimaryKey, primaryKey);
 | 
					  core.saveState(State.CachePrimaryKey, primaryKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const cacheKey = await cache.restoreCache([cachePath], primaryKey);
 | 
					  const cacheKey = await cache.restoreCache(cachePath, primaryKey);
 | 
				
			||||||
  core.setOutput('cache-hit', Boolean(cacheKey));
 | 
					  core.setOutput('cache-hit', Boolean(cacheKey));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!cacheKey) {
 | 
					  if (!cacheKey) {
 | 
				
			||||||
 | 
				
			|||||||
@ -35,11 +35,13 @@ const cachePackages = async () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const cachePath = await getCacheDirectoryPath(packageManagerInfo);
 | 
					  const cachePath = await getCacheDirectoryPath(packageManagerInfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!fs.existsSync(cachePath)) {
 | 
					  for (let path of cachePath) {
 | 
				
			||||||
 | 
					    if (!fs.existsSync(path)) {
 | 
				
			||||||
      throw new Error(
 | 
					      throw new Error(
 | 
				
			||||||
      `Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`
 | 
					        `Cache folder path is retrieved but doesn't exist on disk: ${path}`
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (primaryKey === state) {
 | 
					  if (primaryKey === state) {
 | 
				
			||||||
    core.info(
 | 
					    core.info(
 | 
				
			||||||
@ -49,7 +51,7 @@ const cachePackages = async () => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    await cache.saveCache([cachePath], primaryKey);
 | 
					    await cache.saveCache(cachePath, primaryKey);
 | 
				
			||||||
    core.info(`Cache saved with the key: ${primaryKey}`);
 | 
					    core.info(`Cache saved with the key: ${primaryKey}`);
 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    if (error.name === cache.ValidationError.name) {
 | 
					    if (error.name === cache.ValidationError.name) {
 | 
				
			||||||
 | 
				
			|||||||
@ -34,15 +34,19 @@ export const getPackageManagerInfo = async (packageManager: string) => {
 | 
				
			|||||||
export const getCacheDirectoryPath = async (
 | 
					export const getCacheDirectoryPath = async (
 | 
				
			||||||
  packageManagerInfo: PackageManagerInfo
 | 
					  packageManagerInfo: PackageManagerInfo
 | 
				
			||||||
) => {
 | 
					) => {
 | 
				
			||||||
  const stdout = await getCommandOutput(
 | 
					  let pathList: string[] = [];
 | 
				
			||||||
    packageManagerInfo.getCacheFolderCommand
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!stdout) {
 | 
					  for (let command of packageManagerInfo.cacheFolderCommandList) {
 | 
				
			||||||
    throw new Error(`Could not get cache folder path.`);
 | 
					    pathList.push(await getCommandOutput(command));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return stdout;
 | 
					  for (let path of pathList) {
 | 
				
			||||||
 | 
					    if (!path) {
 | 
				
			||||||
 | 
					      throw new Error(`Could not get cache folder paths.`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return pathList;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function isGhes(): boolean {
 | 
					export function isGhes(): boolean {
 | 
				
			||||||
 | 
				
			|||||||
@ -4,12 +4,12 @@ type SupportedPackageManagers = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export interface PackageManagerInfo {
 | 
					export interface PackageManagerInfo {
 | 
				
			||||||
  dependencyFilePattern: string;
 | 
					  dependencyFilePattern: string;
 | 
				
			||||||
  getCacheFolderCommand: string;
 | 
					  cacheFolderCommandList: string[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const supportedPackageManagers: SupportedPackageManagers = {
 | 
					export const supportedPackageManagers: SupportedPackageManagers = {
 | 
				
			||||||
  default: {
 | 
					  default: {
 | 
				
			||||||
    dependencyFilePattern: 'go.sum',
 | 
					    dependencyFilePattern: 'go.sum',
 | 
				
			||||||
    getCacheFolderCommand: 'go env GOMODCACHE'
 | 
					    cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user