mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 01:50:52 +00:00
Merge pull request #3 from IvanZosimov/compiler-caching
Added caching for compiler's dependencies
This commit is contained in:
commit
3a3f8d0d3c
8 changed files with 833 additions and 802 deletions
|
@ -23,8 +23,8 @@ describe('restoreCache', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
getCacheDirectoryPathSpy.mockImplementation(
|
getCacheDirectoryPathSpy.mockImplementation(
|
||||||
(PackageManager: PackageManagerInfo) => {
|
(PackageManager: PackageManagerInfo) => {
|
||||||
return new Promise<string>(resolve => {
|
return new Promise<string[]>(resolve => {
|
||||||
resolve('cache_directory_path');
|
resolve(['cache_directory_path', 'cache_directory_path']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -48,7 +48,7 @@ describe('getPackageManagerInfo', () => {
|
||||||
const packageManagerName = 'default';
|
const packageManagerName = 'default';
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
dependencyFilePattern: 'go.sum',
|
dependencyFilePattern: 'go.sum',
|
||||||
getCacheFolderCommand: 'go env GOMODCACHE'
|
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
||||||
};
|
};
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
|
@ -74,10 +74,10 @@ describe('getCacheDirectoryPath', () => {
|
||||||
|
|
||||||
const validPackageManager: PackageManagerInfo = {
|
const validPackageManager: PackageManagerInfo = {
|
||||||
dependencyFilePattern: 'go.sum',
|
dependencyFilePattern: 'go.sum',
|
||||||
getCacheFolderCommand: 'go env GOMODCACHE'
|
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should return path to the cache folder which specified package manager uses', async () => {
|
it('should return path to the cache folders which specified package manager uses', async () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
return new Promise<exec.ExecOutput>(resolve => {
|
||||||
|
@ -85,7 +85,7 @@ describe('getCacheDirectoryPath', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const expectedResult = 'path/to/cache/folder';
|
const expectedResult = ['path/to/cache/folder', 'path/to/cache/folder'];
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
return cacheUtils
|
return cacheUtils
|
||||||
|
|
30
dist/cache-save/index.js
vendored
30
dist/cache-save/index.js
vendored
|
@ -4036,11 +4036,12 @@ 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 = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
|
||||||
if (!stdout) {
|
const emptyPaths = pathList.filter(item => !item);
|
||||||
throw new Error(`Could not get cache folder path.`);
|
if (emptyPaths.length) {
|
||||||
|
throw new Error(`Could not get cache folder paths.`);
|
||||||
}
|
}
|
||||||
return stdout;
|
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');
|
||||||
|
@ -49168,7 +49169,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.run = void 0;
|
exports.logWarning = exports.run = void 0;
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const cache = __importStar(__webpack_require__(692));
|
const cache = __importStar(__webpack_require__(692));
|
||||||
const fs_1 = __importDefault(__webpack_require__(747));
|
const fs_1 = __importDefault(__webpack_require__(747));
|
||||||
|
@ -49201,16 +49202,20 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const state = core.getState(constants_1.State.CacheMatchedKey);
|
const state = core.getState(constants_1.State.CacheMatchedKey);
|
||||||
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 cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
||||||
if (!fs_1.default.existsSync(cachePath)) {
|
const nonExistingPaths = cachePaths.filter(cachePath => !fs_1.default.existsSync(cachePath));
|
||||||
throw new Error(`Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`);
|
if (nonExistingPaths.length === cachePaths.length) {
|
||||||
|
throw new Error(`No cache folders exist on disk`);
|
||||||
|
}
|
||||||
|
if (nonExistingPaths.length) {
|
||||||
|
logWarning(`Cache folder path is retrieved but doesn't exist on disk: ${nonExistingPaths.join(', ')}`);
|
||||||
}
|
}
|
||||||
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(cachePaths, primaryKey);
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
@ -49225,6 +49230,11 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
function logWarning(message) {
|
||||||
|
const warningPrefix = '[warning]';
|
||||||
|
core.info(`${warningPrefix}${message}`);
|
||||||
|
}
|
||||||
|
exports.logWarning = logWarning;
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
||||||
|
@ -49315,7 +49325,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']
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
15
dist/setup/index.js
vendored
15
dist/setup/index.js
vendored
|
@ -4298,11 +4298,12 @@ 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 = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
|
||||||
if (!stdout) {
|
const emptyPaths = pathList.filter(item => !item);
|
||||||
throw new Error(`Could not get cache folder path.`);
|
if (emptyPaths.length) {
|
||||||
|
throw new Error(`Could not get cache folder paths.`);
|
||||||
}
|
}
|
||||||
return stdout;
|
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');
|
||||||
|
@ -37248,7 +37249,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
|
||||||
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
|
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
const versionSpec = core.getInput('go-version');
|
const versionSpec = core.getInput('go-version');
|
||||||
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
||||||
const dependencyFilePath = cacheDependencyPath
|
const dependencyFilePath = cacheDependencyPath
|
||||||
? cacheDependencyPath
|
? cacheDependencyPath
|
||||||
: findDependencyFile(packageManagerInfo);
|
: findDependencyFile(packageManagerInfo);
|
||||||
|
@ -37259,7 +37260,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(cachePaths, 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 +51206,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']
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ export const restoreCache = async (
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
const versionSpec = core.getInput('go-version');
|
const versionSpec = core.getInput('go-version');
|
||||||
|
|
||||||
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
|
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
||||||
|
|
||||||
const dependencyFilePath = cacheDependencyPath
|
const dependencyFilePath = cacheDependencyPath
|
||||||
? cacheDependencyPath
|
? cacheDependencyPath
|
||||||
|
@ -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(cachePaths, primaryKey);
|
||||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||||
|
|
||||||
if (!cacheKey) {
|
if (!cacheKey) {
|
||||||
|
|
|
@ -33,11 +33,21 @@ const cachePackages = async () => {
|
||||||
|
|
||||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||||
|
|
||||||
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
|
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
||||||
|
|
||||||
if (!fs.existsSync(cachePath)) {
|
const nonExistingPaths = cachePaths.filter(
|
||||||
throw new Error(
|
cachePath => !fs.existsSync(cachePath)
|
||||||
`Cache folder path is retrieved but doesn't exist on disk: ${cachePath}`
|
);
|
||||||
|
|
||||||
|
if (nonExistingPaths.length === cachePaths.length) {
|
||||||
|
throw new Error(`No cache folders exist on disk`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nonExistingPaths.length) {
|
||||||
|
logWarning(
|
||||||
|
`Cache folder path is retrieved but doesn't exist on disk: ${nonExistingPaths.join(
|
||||||
|
', '
|
||||||
|
)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +59,7 @@ const cachePackages = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await cache.saveCache([cachePath], primaryKey);
|
await cache.saveCache(cachePaths, 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) {
|
||||||
|
@ -62,4 +72,9 @@ const cachePackages = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function logWarning(message: string): void {
|
||||||
|
const warningPrefix = '[warning]';
|
||||||
|
core.info(`${warningPrefix}${message}`);
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import path from 'path';
|
||||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
||||||
|
|
||||||
export const getCommandOutput = async (toolCommand: string) => {
|
export const getCommandOutput = async (toolCommand: string) => {
|
||||||
|
@ -34,15 +35,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 = await Promise.all(
|
||||||
packageManagerInfo.getCacheFolderCommand
|
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
||||||
|
getCommandOutput(command)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!stdout) {
|
const emptyPaths = pathList.filter(item => !item);
|
||||||
throw new Error(`Could not get cache folder path.`);
|
|
||||||
|
if (emptyPaths.length) {
|
||||||
|
throw new Error(`Could not get cache folder paths.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stdout;
|
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…
Add table
Reference in a new issue