mirror of https://github.com/actions/setup-go.git
feat: Add `cache-key-prefix` option
This commit is contained in:
parent
41c2024c46
commit
089c1d9041
25
README.md
25
README.md
|
@ -153,6 +153,7 @@ The `cache` input is optional, and caching is turned on by default.
|
||||||
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of
|
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of
|
||||||
the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located
|
the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located
|
||||||
in different subdirectories.
|
in different subdirectories.
|
||||||
|
If you use `setup-go` with caching from multiple concurrent jobs, you might want to specify the `cache-key-prefix` input to ensure that the cache is not shared between jobs.
|
||||||
|
|
||||||
If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.
|
If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.
|
||||||
|
|
||||||
|
@ -169,6 +170,30 @@ steps:
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Caching wwith multiple concurrent jobs**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: "1.20"
|
||||||
|
cache-key-prefix: build-cache-
|
||||||
|
- run: go build
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: "1.20"
|
||||||
|
cache-key-prefix: test-cache-
|
||||||
|
- run: go test ./...
|
||||||
|
```
|
||||||
|
|
||||||
## Getting go version from the go.mod file
|
## Getting go version from the go.mod file
|
||||||
|
|
||||||
The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be
|
The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be
|
||||||
|
|
|
@ -17,6 +17,8 @@ inputs:
|
||||||
default: true
|
default: true
|
||||||
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:
|
||||||
|
description: 'A prefix to add to the cache key. Useful if you have multiple concurrent jobs that need different caches.'
|
||||||
architecture:
|
architecture:
|
||||||
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
||||||
outputs:
|
outputs:
|
||||||
|
|
|
@ -63043,7 +63043,8 @@ const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awa
|
||||||
if (!fileHash) {
|
if (!fileHash) {
|
||||||
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
||||||
}
|
}
|
||||||
const primaryKey = `setup-go-${platform}-go-${versionSpec}-${fileHash}`;
|
const cacheKeyPrefix = core.getInput('cache-key-prefix') || '';
|
||||||
|
const primaryKey = `${cacheKeyPrefix}setup-go-${platform}-go-${versionSpec}-${fileHash}`;
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
||||||
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
|
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
|
||||||
|
|
|
@ -29,7 +29,8 @@ export const restoreCache = async (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const primaryKey = `setup-go-${platform}-go-${versionSpec}-${fileHash}`;
|
const cacheKeyPrefix = core.getInput('cache-key-prefix') || '';
|
||||||
|
const primaryKey = `${cacheKeyPrefix}setup-go-${platform}-go-${versionSpec}-${fileHash}`;
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
core.debug(`primary key is ${primaryKey}`);
|
||||||
|
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||||
|
|
Loading…
Reference in New Issue