perf: add cache-build option and upgrade to v6.2.0

Add `cache-build` input (default: false) to control whether GOCACHE is
included in the cache. This dramatically reduces cache size from ~1.2GB
to ~200-400MB by excluding build artifacts that have low reuse across
code changes.

Also upgrades dependencies (@actions/cache v5, semver v7.7) and runtime
to node24 to align with upstream actions/setup-go.

https://claude.ai/code/session_01CqrWSjzGgd7Zi6LyJkd9XW
This commit is contained in:
Claude 2026-04-04 17:58:19 +00:00
parent f21630a9ad
commit cf0b11600c
No known key found for this signature in database
9 changed files with 198948 additions and 67104 deletions

View file

@ -4,6 +4,7 @@ import * as glob from '@actions/glob';
import * as cacheRestore from '../src/cache-restore';
import * as cacheUtils from '../src/cache-utils';
import * as hashdir from '../src/hashdir';
import {PackageManagerInfo} from '../src/package-managers';
describe('restoreCache', () => {
@ -21,7 +22,11 @@ describe('restoreCache', () => {
const packageManager = 'default';
const cacheDependencyPath = 'path';
const computeMetaHashSpy = jest.spyOn(hashdir, 'computeMetaHash');
beforeEach(() => {
process.env['INPUT_CACHE-BUILD'] = 'false';
computeMetaHashSpy.mockReturnValue('mock_build_hash');
getCacheDirectoryPathSpy.mockImplementation(
(PackageManager: PackageManagerInfo) => {
return new Promise<string[]>(resolve => {

View file

@ -15,6 +15,9 @@ inputs:
cache:
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
default: true
cache-build:
description: 'Whether to cache the Go build cache (GOCACHE) in addition to the module cache (GOMODCACHE). Set to true to include build cache.'
default: false
cache-dependency-path:
description: 'Used to specify the path to a dependency file - go.sum'
cache-key-prefix:
@ -28,7 +31,7 @@ outputs:
cache-hit:
description: 'A boolean value to indicate if a cache was hit'
runs:
using: 'node20'
using: 'node24'
main: 'dist/setup/index.js'
post: 'dist/cache-save/index.js'
post-if: success()

132785
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

132325
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

896
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "setup-go",
"version": "5.0.0",
"version": "6.2.0",
"private": true,
"description": "setup go action",
"main": "lib/setup-go.js",
@ -25,18 +25,18 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/cache": "^4.0.3",
"@actions/cache": "^5.0.1",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.5.0",
"@actions/http-client": "^2.2.1",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^2.0.1",
"semver": "^7.6.3"
"@actions/tool-cache": "^2.0.2",
"semver": "^7.7.3"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.11.28",
"@types/node": "^22.15.3",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^8.31.1",
"@typescript-eslint/parser": "^8.31.1",

View file

@ -17,8 +17,12 @@ export const restoreCache = async (
const packageManagerInfo = await getPackageManagerInfo(packageManager);
const platform = process.env.RUNNER_OS;
const arch = process.arch;
const cacheBuild = core.getBooleanInput('cache-build');
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
const cachePaths = await getCacheDirectoryPath(
packageManagerInfo,
cacheBuild
);
const dependencyFilePath = cacheDependencyPath
? cacheDependencyPath

View file

@ -46,8 +46,12 @@ const cachePackages = async () => {
const prevBuildHash = core.getState(State.CacheBuildHash);
const packageManagerInfo = await getPackageManagerInfo(packageManager);
const cacheBuild = core.getBooleanInput('cache-build');
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
const cachePaths = await getCacheDirectoryPath(
packageManagerInfo,
cacheBuild
);
const nonExistingPaths = cachePaths.filter(
cachePath => !fs.existsSync(cachePath)
@ -73,7 +77,8 @@ const cachePackages = async () => {
return;
}
const buildHash = computeMetaHash([cachePaths[1]]);
const buildHash =
cachePaths.length > 1 ? computeMetaHash([cachePaths[1]]) : '';
if (primaryKey === state && buildHash === prevBuildHash) {
core.info(

View file

@ -32,12 +32,15 @@ export const getPackageManagerInfo = async (packageManager: string) => {
};
export const getCacheDirectoryPath = async (
packageManagerInfo: PackageManagerInfo
packageManagerInfo: PackageManagerInfo,
includeBuildCache = true
) => {
const commands = includeBuildCache
? packageManagerInfo.cacheFolderCommandList
: packageManagerInfo.cacheFolderCommandList.slice(0, 1);
const pathOutputs = await Promise.allSettled(
packageManagerInfo.cacheFolderCommandList.map(async command =>
getCommandOutput(command)
)
commands.map(async command => getCommandOutput(command))
);
const results = pathOutputs.map(item => {