From e3f3aaaa5947624c71b9eda231ab1abe49021cbe Mon Sep 17 00:00:00 2001 From: Sindre Myren Date: Thu, 28 Jan 2021 12:15:03 +0100 Subject: [PATCH] Add options to skip caching of folders. Add option to skip caching the Go package directory (~/go/pkg). Add option to skip caching the Go build directory (~/.cache/go-build). Update README to mention new options. --- README.md | 8 +++++++- action.yml | 8 ++++++++ src/cache.ts | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2eb315d14a..5578720866 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,14 @@ jobs: # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true - # Optional: if set to true then the action will use pre-installed Go + # Optional: if set to true then the action will use pre-installed Go. # skip-go-installation: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true ``` We recommend running this action in a job separate from other jobs (`go test`, etc) diff --git a/action.yml b/action.yml index c3d50a1a61..35c8c77f11 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,14 @@ inputs: description: "if set to true then action uses pre-installed Go" default: false required: true + skip-pkg-cache: + description: "if set to true then the action don't cache or restore ~/go/pkg." + default: false + required: true + skip-build-cache: + description: "if set to true then the action don't cache or restore ~/.cache/go-build." + default: false + required: true runs: using: "node12" main: "dist/run/index.js" diff --git a/src/cache.ts b/src/cache.ts index 6cebe879fc..85b5b79847 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -25,7 +25,22 @@ const getLintCacheDir = (): string => { const getCacheDirs = (): string[] => { // Not existing dirs are ok here: it works. - return [getLintCacheDir(), path.resolve(`${process.env.HOME}/.cache/go-build`), path.resolve(`${process.env.HOME}/go/pkg`)] + const skipPkgCache = core.getInput(`skip-pkg-cache`, { required: true }).trim() + const skipBuildCache = core.getInput(`skip-build-cache`, { required: true }).trim() + const dirs = [getLintCacheDir()] + + if (skipBuildCache.toLowerCase() == "true") { + core.info(`Omitting ~/.cache/go-build from cache directories`) + } else { + dirs.push(path.resolve(`${process.env.HOME}/.cache/go-build`)) + } + if (skipPkgCache.toLowerCase() == "true") { + core.info(`Omitting ~/go/pkg from cache directories`) + } else { + dirs.push(path.resolve(`${process.env.HOME}/go/pkg`)) + } + + return dirs } const getIntervalKey = (invalidationIntervalDays: number): string => {