mirror of
https://github.com/actions/setup-go.git
synced 2026-04-26 23:14:24 +00:00
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:
parent
f21630a9ad
commit
cf0b11600c
9 changed files with 198948 additions and 67104 deletions
|
|
@ -4,6 +4,7 @@ import * as glob from '@actions/glob';
|
||||||
|
|
||||||
import * as cacheRestore from '../src/cache-restore';
|
import * as cacheRestore from '../src/cache-restore';
|
||||||
import * as cacheUtils from '../src/cache-utils';
|
import * as cacheUtils from '../src/cache-utils';
|
||||||
|
import * as hashdir from '../src/hashdir';
|
||||||
import {PackageManagerInfo} from '../src/package-managers';
|
import {PackageManagerInfo} from '../src/package-managers';
|
||||||
|
|
||||||
describe('restoreCache', () => {
|
describe('restoreCache', () => {
|
||||||
|
|
@ -21,7 +22,11 @@ describe('restoreCache', () => {
|
||||||
const packageManager = 'default';
|
const packageManager = 'default';
|
||||||
const cacheDependencyPath = 'path';
|
const cacheDependencyPath = 'path';
|
||||||
|
|
||||||
|
const computeMetaHashSpy = jest.spyOn(hashdir, 'computeMetaHash');
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
process.env['INPUT_CACHE-BUILD'] = 'false';
|
||||||
|
computeMetaHashSpy.mockReturnValue('mock_build_hash');
|
||||||
getCacheDirectoryPathSpy.mockImplementation(
|
getCacheDirectoryPathSpy.mockImplementation(
|
||||||
(PackageManager: PackageManagerInfo) => {
|
(PackageManager: PackageManagerInfo) => {
|
||||||
return new Promise<string[]>(resolve => {
|
return new Promise<string[]>(resolve => {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ inputs:
|
||||||
cache:
|
cache:
|
||||||
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
||||||
default: true
|
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:
|
cache-dependency-path:
|
||||||
description: 'Used to specify the path to a dependency file - go.sum'
|
description: 'Used to specify the path to a dependency file - go.sum'
|
||||||
cache-key-prefix:
|
cache-key-prefix:
|
||||||
|
|
@ -28,7 +31,7 @@ outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit'
|
description: 'A boolean value to indicate if a cache was hit'
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node24'
|
||||||
main: 'dist/setup/index.js'
|
main: 'dist/setup/index.js'
|
||||||
post: 'dist/cache-save/index.js'
|
post: 'dist/cache-save/index.js'
|
||||||
post-if: success()
|
post-if: success()
|
||||||
|
|
|
||||||
132785
dist/cache-save/index.js
vendored
132785
dist/cache-save/index.js
vendored
File diff suppressed because one or more lines are too long
132325
dist/setup/index.js
vendored
132325
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
896
package-lock.json
generated
896
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "setup-go",
|
"name": "setup-go",
|
||||||
"version": "5.0.0",
|
"version": "6.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup go action",
|
"description": "setup go action",
|
||||||
"main": "lib/setup-go.js",
|
"main": "lib/setup-go.js",
|
||||||
|
|
@ -25,18 +25,18 @@
|
||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^4.0.3",
|
"@actions/cache": "^5.0.1",
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/glob": "^0.5.0",
|
"@actions/glob": "^0.5.0",
|
||||||
"@actions/http-client": "^2.2.1",
|
"@actions/http-client": "^2.2.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.2",
|
||||||
"semver": "^7.6.3"
|
"semver": "^7.7.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
"@types/node": "^20.11.28",
|
"@types/node": "^22.15.3",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||||
"@typescript-eslint/parser": "^8.31.1",
|
"@typescript-eslint/parser": "^8.31.1",
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,12 @@ export const restoreCache = async (
|
||||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||||
const platform = process.env.RUNNER_OS;
|
const platform = process.env.RUNNER_OS;
|
||||||
const arch = process.arch;
|
const arch = process.arch;
|
||||||
|
const cacheBuild = core.getBooleanInput('cache-build');
|
||||||
|
|
||||||
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
const cachePaths = await getCacheDirectoryPath(
|
||||||
|
packageManagerInfo,
|
||||||
|
cacheBuild
|
||||||
|
);
|
||||||
|
|
||||||
const dependencyFilePath = cacheDependencyPath
|
const dependencyFilePath = cacheDependencyPath
|
||||||
? cacheDependencyPath
|
? cacheDependencyPath
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,12 @@ const cachePackages = async () => {
|
||||||
const prevBuildHash = core.getState(State.CacheBuildHash);
|
const prevBuildHash = core.getState(State.CacheBuildHash);
|
||||||
|
|
||||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
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(
|
const nonExistingPaths = cachePaths.filter(
|
||||||
cachePath => !fs.existsSync(cachePath)
|
cachePath => !fs.existsSync(cachePath)
|
||||||
|
|
@ -73,7 +77,8 @@ const cachePackages = async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildHash = computeMetaHash([cachePaths[1]]);
|
const buildHash =
|
||||||
|
cachePaths.length > 1 ? computeMetaHash([cachePaths[1]]) : '';
|
||||||
|
|
||||||
if (primaryKey === state && buildHash === prevBuildHash) {
|
if (primaryKey === state && buildHash === prevBuildHash) {
|
||||||
core.info(
|
core.info(
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,15 @@ export const getPackageManagerInfo = async (packageManager: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCacheDirectoryPath = async (
|
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(
|
const pathOutputs = await Promise.allSettled(
|
||||||
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
commands.map(async command => getCommandOutput(command))
|
||||||
getCommandOutput(command)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = pathOutputs.map(item => {
|
const results = pathOutputs.map(item => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue