mirror of https://github.com/actions/setup-go.git
Unique primaryKey for cache based on buildTargetArch
This commit is contained in:
parent
c0137caad7
commit
af7fba4129
|
@ -44,7 +44,8 @@ describe('restoreCache', () => {
|
|||
await cacheRestore.restoreCache(
|
||||
versionSpec,
|
||||
packageManager,
|
||||
cacheDependencyPath
|
||||
cacheDependencyPath,
|
||||
undefined
|
||||
);
|
||||
}).rejects.toThrow(
|
||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
||||
|
@ -69,7 +70,8 @@ describe('restoreCache', () => {
|
|||
await cacheRestore.restoreCache(
|
||||
versionSpec,
|
||||
packageManager,
|
||||
cacheDependencyPath
|
||||
cacheDependencyPath,
|
||||
undefined
|
||||
);
|
||||
expect(infoSpy).toHaveBeenCalledWith(`Cache is not found`);
|
||||
});
|
||||
|
@ -92,7 +94,8 @@ describe('restoreCache', () => {
|
|||
await cacheRestore.restoreCache(
|
||||
versionSpec,
|
||||
packageManager,
|
||||
cacheDependencyPath
|
||||
cacheDependencyPath,
|
||||
undefined
|
||||
);
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
||||
});
|
||||
|
|
|
@ -17,6 +17,8 @@ inputs:
|
|||
default: true
|
||||
cache-dependency-path:
|
||||
description: 'Used to specify the path to a dependency file - go.sum'
|
||||
buildTarget:
|
||||
description: 'Optional build target architecture (for example arm64 or amd64) used to scope the cache key.'
|
||||
architecture:
|
||||
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
||||
outputs:
|
||||
|
|
|
@ -11,7 +11,8 @@ import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
|||
export const restoreCache = async (
|
||||
versionSpec: string,
|
||||
packageManager: string,
|
||||
cacheDependencyPath?: string
|
||||
cacheDependencyPath?: string,
|
||||
buildTarget?: string
|
||||
) => {
|
||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||
const platform = process.env.RUNNER_OS;
|
||||
|
@ -32,7 +33,9 @@ export const restoreCache = async (
|
|||
|
||||
const linuxVersion =
|
||||
process.env.RUNNER_OS === 'Linux' ? `${process.env.ImageOS}-` : '';
|
||||
const primaryKey = `setup-go-${platform}-${arch}-${linuxVersion}go-${versionSpec}-${fileHash}`;
|
||||
const sanitizedBuildTarget = buildTarget?.trim();
|
||||
const targetSegment = sanitizedBuildTarget ? `${sanitizedBuildTarget}-` : '';
|
||||
const primaryKey = `setup-go-${platform}-${arch}-${targetSegment}${linuxVersion}go-${versionSpec}-${fileHash}`;
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
|
||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||
|
|
|
@ -20,6 +20,7 @@ export async function run() {
|
|||
setGoToolchain();
|
||||
|
||||
const cache = core.getBooleanInput('cache');
|
||||
const buildTarget = core.getInput('buildTarget');
|
||||
core.info(`Setup go version spec ${versionSpec}`);
|
||||
|
||||
let arch = core.getInput('architecture') as Architecture;
|
||||
|
@ -73,7 +74,8 @@ export async function run() {
|
|||
await restoreCache(
|
||||
parseGoVersion(goVersion),
|
||||
packageManager,
|
||||
cacheDependencyPath
|
||||
cacheDependencyPath,
|
||||
buildTarget
|
||||
);
|
||||
} catch (error) {
|
||||
core.warning(`Restore cache failed: ${(error as Error).message}`);
|
||||
|
|
Loading…
Reference in New Issue