Skip to content

Commit 0dd3083

Browse files
authored
Add options to skip caching of folders. (#154)
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 e1ae6cf commit 0dd3083

File tree

5 files changed

+63
-4
lines changed

5 files changed

+63
-4
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"

dist/post_run/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49992,7 +49992,22 @@ const getLintCacheDir = () => {
4999249992
};
4999349993
const getCacheDirs = () => {
4999449994
// Not existing dirs are ok here: it works.
49995-
return [getLintCacheDir(), path_1.default.resolve(`${process.env.HOME}/.cache/go-build`), path_1.default.resolve(`${process.env.HOME}/go/pkg`)];
49995+
const skipPkgCache = core.getInput(`skip-pkg-cache`, { required: true }).trim();
49996+
const skipBuildCache = core.getInput(`skip-build-cache`, { required: true }).trim();
49997+
const dirs = [getLintCacheDir()];
49998+
if (skipBuildCache.toLowerCase() == "true") {
49999+
core.info(`Omitting ~/.cache/go-build from cache directories`);
50000+
}
50001+
else {
50002+
dirs.push(path_1.default.resolve(`${process.env.HOME}/.cache/go-build`));
50003+
}
50004+
if (skipPkgCache.toLowerCase() == "true") {
50005+
core.info(`Omitting ~/go/pkg from cache directories`);
50006+
}
50007+
else {
50008+
dirs.push(path_1.default.resolve(`${process.env.HOME}/go/pkg`));
50009+
}
50010+
return dirs;
4999650011
};
4999750012
const getIntervalKey = (invalidationIntervalDays) => {
4999850013
const now = new Date();

dist/run/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50002,7 +50002,22 @@ const getLintCacheDir = () => {
5000250002
};
5000350003
const getCacheDirs = () => {
5000450004
// Not existing dirs are ok here: it works.
50005-
return [getLintCacheDir(), path_1.default.resolve(`${process.env.HOME}/.cache/go-build`), path_1.default.resolve(`${process.env.HOME}/go/pkg`)];
50005+
const skipPkgCache = core.getInput(`skip-pkg-cache`, { required: true }).trim();
50006+
const skipBuildCache = core.getInput(`skip-build-cache`, { required: true }).trim();
50007+
const dirs = [getLintCacheDir()];
50008+
if (skipBuildCache.toLowerCase() == "true") {
50009+
core.info(`Omitting ~/.cache/go-build from cache directories`);
50010+
}
50011+
else {
50012+
dirs.push(path_1.default.resolve(`${process.env.HOME}/.cache/go-build`));
50013+
}
50014+
if (skipPkgCache.toLowerCase() == "true") {
50015+
core.info(`Omitting ~/go/pkg from cache directories`);
50016+
}
50017+
else {
50018+
dirs.push(path_1.default.resolve(`${process.env.HOME}/go/pkg`));
50019+
}
50020+
return dirs;
5000650021
};
5000750022
const getIntervalKey = (invalidationIntervalDays) => {
5000850023
const now = new Date();

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)