mirror of
https://github.com/actions/setup-go.git
synced 2025-07-16 20:15:14 -06:00
Add logic for modules caching
Such files as cache-restore.ts, cache-utils.ts, constants.ts, cache-save.ts we added. Main.ts file now incorporates logic for using files mentioned above.
This commit is contained in:
parent
5ba3482d38
commit
25a133c257
7 changed files with 198 additions and 2 deletions
49
src/cache-utils.ts
Normal file
49
src/cache-utils.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
export interface PackageManagerInfo {
|
||||
goSumFilePattern: string;
|
||||
getCacheFolderCommand: string;
|
||||
}
|
||||
|
||||
export const defaultPackageManager: PackageManagerInfo = {
|
||||
goSumFilePattern: 'go.sum',
|
||||
getCacheFolderCommand: 'go env GOMODCACHE',
|
||||
};
|
||||
|
||||
export const getCommandOutput = async (toolCommand: string) => {
|
||||
let {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||
toolCommand,
|
||||
undefined,
|
||||
{ignoreReturnCode: true}
|
||||
);
|
||||
|
||||
if (exitCode) {
|
||||
stderr = !stderr.trim()
|
||||
? `The '${toolCommand}' command failed with exit code: ${exitCode}`
|
||||
: stderr;
|
||||
throw new Error(stderr);
|
||||
}
|
||||
|
||||
return stdout.trim();
|
||||
};
|
||||
|
||||
export const getPackageManagerInfo = async () => {
|
||||
|
||||
return defaultPackageManager;
|
||||
|
||||
};
|
||||
|
||||
export const getCacheDirectoryPath = async (
|
||||
packageManagerInfo: PackageManagerInfo,
|
||||
) => {
|
||||
const stdout = await getCommandOutput(
|
||||
packageManagerInfo.getCacheFolderCommand
|
||||
);
|
||||
|
||||
if (!stdout) {
|
||||
throw new Error(`Could not get cache folder path.`);
|
||||
}
|
||||
|
||||
return stdout;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue