Skip to content

Commit e3f3aaa

Browse files
committed
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.
1 parent 125ac48 commit e3f3aaa

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ jobs:
4848
# Optional: show only new issues if it's a pull request. The default value is `false`.
4949
# only-new-issues: true
5050

51-
# Optional: if set to true then the action will use pre-installed Go
51+
# Optional: if set to true then the action will use pre-installed Go.
5252
# skip-go-installation: true
53+
54+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
55+
# skip-pkg-cache: true
56+
57+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
58+
# skip-build-cache: true
5359
```
5460

5561
We recommend running this action in a job separate from other jobs (`go test`, etc)

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ inputs:
2424
description: "if set to true then action uses pre-installed Go"
2525
default: false
2626
required: true
27+
skip-pkg-cache:
28+
description: "if set to true then the action don't cache or restore ~/go/pkg."
29+
default: false
30+
required: true
31+
skip-build-cache:
32+
description: "if set to true then the action don't cache or restore ~/.cache/go-build."
33+
default: false
34+
required: true
2735
runs:
2836
using: "node12"
2937
main: "dist/run/index.js"

src/cache.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ const getLintCacheDir = (): string => {
2525

2626
const getCacheDirs = (): string[] => {
2727
// Not existing dirs are ok here: it works.
28-
return [getLintCacheDir(), path.resolve(`${process.env.HOME}/.cache/go-build`), path.resolve(`${process.env.HOME}/go/pkg`)]
28+
const skipPkgCache = core.getInput(`skip-pkg-cache`, { required: true }).trim()
29+
const skipBuildCache = core.getInput(`skip-build-cache`, { required: true }).trim()
30+
const dirs = [getLintCacheDir()]
31+
32+
if (skipBuildCache.toLowerCase() == "true") {
33+
core.info(`Omitting ~/.cache/go-build from cache directories`)
34+
} else {
35+
dirs.push(path.resolve(`${process.env.HOME}/.cache/go-build`))
36+
}
37+
if (skipPkgCache.toLowerCase() == "true") {
38+
core.info(`Omitting ~/go/pkg from cache directories`)
39+
} else {
40+
dirs.push(path.resolve(`${process.env.HOME}/go/pkg`))
41+
}
42+
43+
return dirs
2944
}
3045

3146
const getIntervalKey = (invalidationIntervalDays: number): string => {

0 commit comments

Comments
 (0)