You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
GitHub Action
Golang with cache
v3
Composite GitHub Action which combines the perfect pairing of actions/setup-go with actions/cache for the caching of both the Golang module and build caches.
Reducing all these workflow steps:
steps:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: ~1.18
- name: Setup Golang caches
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-
down to this:
steps:
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version: ~1.18
or using go-version-file
for version selection:
steps:
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v3
with:
go-version-file: go.mod
Action correctly sets build and module cache paths for Linux, macOS and Windows runners.
In addition an optional cache-key-suffix
input can be used to control the generated cache key - handy where a Golang program is compiled multiple times for different binaries across multiple workflow definitions - resulting in different optimized build cache path contents:
steps:
- name: Testing action
uses: magnetikonline/action-golang-cache@v3
with:
go-version: ~1.18
cache-key-suffix: -apples
# cache key: ${{ runner.os }}-golang-apples-${{ hashFiles('**/go.sum') }}
# restore key: ${{ runner.os }}-golang-apples-