try different approach by overriding go ENV GOCACHE and GOMODCACHE vars for Windows

Signed-off-by: Anton Troshin <anton@diagrid.io>
This commit is contained in:
Anton Troshin
2024-11-19 21:15:12 -06:00
parent 5b1dffca1b
commit be775566d4
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!;