You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
GitHub Action
Golang with cache
v2
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.17
- 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@v2
with:
go-version: ~1.17
Action correctly sets the build and module cache paths for Linux, macOS and Windows runners as per the Golang cache examples.
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@v2
with:
go-version: ~1.17
cache-key-suffix: -apples
# cache key: ${{ runner.os }}-golang-apples-${{ hashFiles('**/go.sum') }}
# restore key: ${{ runner.os }}-golang-apples-