This commit is contained in:
Anton Troshin
2025-01-21 16:01:51 -06:00
committed by GitHub
3 changed files with 59 additions and 4 deletions

View File

@@ -4,9 +4,10 @@ import * as glob from '@actions/glob';
import path from 'path';
import fs from 'fs';
import {State, Outputs} from './constants';
import {Outputs, State} from './constants';
import {PackageManagerInfo} from './package-managers';
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
import {getCacheDirectoryPath, getCommandOutput, getPackageManagerInfo} from './cache-utils';
import os from "os";
export const restoreCache = async (
versionSpec: string,
@@ -50,6 +51,34 @@ export const restoreCache = async (
core.info(`Cache restored from key: ${cacheKey}`);
};
export const setWindowsCacheDirectories = async () => {
if (os.platform() !== 'win32') return;
let goCache = await getCommandOutput(`go env GOCACHE`);
core.info(`GOCACHE: ${goCache}`);
goCache = goCache.replace('C:', 'D:').replace('c:', 'd:');
if (!fs.existsSync(goCache)) {
core.info(`${goCache} does not exist. Creating`);
fs.mkdirSync(goCache, {recursive: true});
}
const setOutput = await getCommandOutput(`go env -w GOCACHE=${goCache}`);
core.info(`go env -w GOCACHE output: ${setOutput}`);
let goModCache = await getCommandOutput(`go env GOMODCACHE`);
core.info(`GOMODCACHE: ${goModCache}`);
goModCache = goModCache.replace('C:', 'D:').replace('c:', 'd:');
if (!fs.existsSync(goModCache)) {
core.info(`${goModCache} does not exist. Creating`);
fs.mkdirSync(goModCache, {recursive: true});
}
const setModOutput = await getCommandOutput(`go env -w GOMODCACHE=${goModCache}`);
core.info(`go env -w GOMODCACHE output: ${setModOutput}`);
};
const findDependencyFile = (packageManager: PackageManagerInfo) => {
const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE!;

View File

@@ -3,7 +3,7 @@ import * as io from '@actions/io';
import * as installer from './installer';
import * as semver from 'semver';
import path from 'path';
import {restoreCache} from './cache-restore';
import {restoreCache, setWindowsCacheDirectories} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import cp from 'child_process';
import fs from 'fs';
@@ -11,6 +11,7 @@ import os from 'os';
export async function run() {
try {
await setWindowsCacheDirectories();
//
// versionSpec is optional. If supplied, install / use from the tool cache
// If not supplied then problem matchers will still be setup. Useful for self-hosted.