|
| 1 | +# 0. Caching dependencies |
| 2 | +Date: 2022-04-13 |
| 3 | + |
| 4 | +Status: Accepted |
| 5 | + |
| 6 | +# Context |
| 7 | +`actions/setup-go` is the one of the most popular action related to Golang in GitHub Actions. Many customers use it in conjunction with [actions/cache](https://github.com/actions/cache) to speed up dependency installation process. |
| 8 | +See more examples on proper usage in [actions/cache documentation](https://github.com/actions/cache/blob/main/examples.md#go---modules). |
| 9 | + |
| 10 | +# Goals & Anti-Goals |
| 11 | +Integration of caching functionality into `actions/setup-go` action will bring the following benefits for action users: |
| 12 | +- Decrease the entry threshold for using the cache for Go dependencies and simplify initial configuration |
| 13 | +- Simplify YAML pipelines because there will be no need for additional steps to enable caching |
| 14 | +- More users will use cache for Go so more customers will have fast builds! |
| 15 | + |
| 16 | +We don't pursue the goal to provide wide customization of caching in scope of `actions/setup-go` action. The purpose of this integration is covering ~90% of basic use-cases. If user needs flexible customization, we should advice them to use `actions/cache` directly. |
| 17 | + |
| 18 | +# Decision |
| 19 | +- Add `cache` input parameter to `actions/setup-go`. For now, input will accept the following values: |
| 20 | + - `true` - enable caching for go dependencies |
| 21 | + - `false`- disable caching for go dependencies. This value will be set as default value |
| 22 | +- Cache feature will be disabled by default to make sure that we don't break existing customers. We will consider enabling cache by default in next major releases |
| 23 | +- Action will try to search a go.sum files in the repository and throw error in the scenario that it was not found |
| 24 | +- The hash of found file will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#go---modules) recommends) |
| 25 | +- The following key cache will be used `${{ runner.os }}-go${{ go-version }}-${{ hashFiles('<go.sum-path>') }}` |
| 26 | +- Action will cache global cache from the `go env GOMODCACHE` and `go env GOCACHE` commands. |
| 27 | +- Add a `cache-dependency-path` input parameter to `actions/setup-go`. The new input will accept an array or regex of dependency files. The field will accept a path (relative to the repository root) to dependency files. If the provided path contains wildcards, the action will search all matching files and calculate a common hash like the ${{ hashFiles('**/go.sum') }} YAML construction does. |
| 28 | + |
| 29 | +# Example of real use-cases |
| 30 | + |
| 31 | + - With cache |
| 32 | + |
| 33 | +```yml |
| 34 | +steps: |
| 35 | +- uses: actions/checkout@v3 |
| 36 | +- uses: actions/setup-go@v3 |
| 37 | + with: |
| 38 | + go-version: '18' |
| 39 | + cache: true |
| 40 | +``` |
| 41 | +
|
| 42 | + - With cache-dependency-path |
| 43 | +
|
| 44 | + ```yml |
| 45 | +steps: |
| 46 | +- uses: actions/checkout@v3 |
| 47 | +- uses: actions/setup-go@v3 |
| 48 | + with: |
| 49 | + go-version: '18' |
| 50 | + cache: true |
| 51 | + cache-dependency-path: **/go.sum |
| 52 | +``` |
| 53 | +
|
| 54 | + ```yml |
| 55 | +steps: |
| 56 | +- uses: actions/checkout@v3 |
| 57 | +- uses: actions/setup-go@v3 |
| 58 | + with: |
| 59 | + go-version: '18' |
| 60 | + cache: true |
| 61 | + cache-dependency-path: | |
| 62 | + **/go.sum |
| 63 | + **/go.mod |
| 64 | +``` |
| 65 | +
|
| 66 | +# Release process |
| 67 | +
|
| 68 | +As soon as functionality is implemented, we will release minor update of action. No need to bump major version since there are no breaking changes for existing users. |
| 69 | +After that, we will update [starter-workflows](https://github.com/actions/starter-workflows/blob/main/ci/go.yml) |
0 commit comments