Add caching of the compiler's temporary files

This commit is contained in:
Ivan Zosimov 2022-04-18 17:57:33 +02:00
parent c8ed3f974d
commit 661954d154
6 changed files with 814 additions and 796 deletions

View file

@ -4036,11 +4036,16 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const stdout = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
if (!stdout) {
throw new Error(`Could not get cache folder path.`);
let pathList = [];
for (let command of packageManagerInfo.cacheFolderCommandList) {
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() {
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 packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
if (!fs_1.default.existsSync(cachePath)) {
throw new Error(`Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`);
for (let path of 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) {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
return;
}
try {
yield cache.saveCache([cachePath], primaryKey);
yield cache.saveCache(cachePath, primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`);
}
catch (error) {
@ -49315,7 +49322,7 @@ exports.supportedPackageManagers = void 0;
exports.supportedPackageManagers = {
default: {
dependencyFilePattern: 'go.sum',
getCacheFolderCommand: 'go env GOMODCACHE'
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
}
};

17
dist/setup/index.js vendored
View file

@ -4298,11 +4298,16 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
const stdout = yield exports.getCommandOutput(packageManagerInfo.getCacheFolderCommand);
if (!stdout) {
throw new Error(`Could not get cache folder path.`);
let pathList = [];
for (let command of packageManagerInfo.cacheFolderCommandList) {
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() {
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}`;
core.debug(`primary key is ${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));
if (!cacheKey) {
core.info(`Cache is not found`);
@ -51205,7 +51210,7 @@ exports.supportedPackageManagers = void 0;
exports.supportedPackageManagers = {
default: {
dependencyFilePattern: 'go.sum',
getCacheFolderCommand: 'go env GOMODCACHE'
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
}
};

View file

@ -34,7 +34,7 @@ export const restoreCache = async (
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));
if (!cacheKey) {

View file

@ -35,10 +35,12 @@ const cachePackages = async () => {
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
if (!fs.existsSync(cachePath)) {
throw new Error(
`Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`
);
for (let path of cachePath) {
if (!fs.existsSync(path)) {
throw new Error(
`Cache folder path is retrieved but doesn't exist on disk: ${path}`
);
}
}
if (primaryKey === state) {
@ -49,7 +51,7 @@ const cachePackages = async () => {
}
try {
await cache.saveCache([cachePath], primaryKey);
await cache.saveCache(cachePath, primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`);
} catch (error) {
if (error.name === cache.ValidationError.name) {

View file

@ -34,15 +34,19 @@ export const getPackageManagerInfo = async (packageManager: string) => {
export const getCacheDirectoryPath = async (
packageManagerInfo: PackageManagerInfo
) => {
const stdout = await getCommandOutput(
packageManagerInfo.getCacheFolderCommand
);
let pathList: string[] = [];
if (!stdout) {
throw new Error(`Could not get cache folder path.`);
for (let command of packageManagerInfo.cacheFolderCommandList) {
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 {

View file

@ -4,12 +4,12 @@ type SupportedPackageManagers = {
export interface PackageManagerInfo {
dependencyFilePattern: string;
getCacheFolderCommand: string;
cacheFolderCommandList: string[];
}
export const supportedPackageManagers: SupportedPackageManagers = {
default: {
dependencyFilePattern: 'go.sum',
getCacheFolderCommand: 'go env GOMODCACHE'
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
}
};