Description
Description:
It doesn't look like setup-go
caches the Go build cache, only Go modules and other relevant things.
To speed up subsequent builds, should the go-build
directories (OS dependent) also be cached automatically in this action?
Some background available in this blog post https://500.keboola.com/in-depth-of-go-build-cache/
Justification:
I had a job that was taking 3+mins for go test
to start, turns out it was because of how long it took to "build" the tests before executing them.
By implementing at least the actions/cache@v4
parts suggested in https://500.keboola.com/in-depth-of-go-build-cache/ that 3mins became single digit seconds.
I suspect this may speed up other peoples builds too.
Example logic:
What I ended up doing in Github Actions in addition to setup-go
, differed a little from the blog post (cache based on Go version dynamically being fetched, plus OS + CPU architecture)
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Get go version for build cache key
run: |
echo "GO_VERSION=$(go version | cut -d ' ' -f 3 | cut -d 'o' -f 2)" >> $GITHUB_ENV
- name: Load Go build cache
id: load-go-cache
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
key: ${{ runner.os }}-${{ runner.arch }}-go-${{ env.GO_VERSION }}-somethingunique-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-go-${{ env.GO_VERSION }}-somethingunique-
Are you willing to submit a PR?
Not right now - I implemented this in my own actions logic for now :)