actions / actions/setup-go

Feature request: cache the Go build cache

Open
#596 9 comments 3 reactions 1 assignee View on GitHub

@v-gowridurgad is already working on this.

Since Sep 9, 2026.

feature request
Dominant language
TypeScript
Stars
1.8k
Forks
673
Avg merge
6d 28m
Merged PRs (30d)
4

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 :)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.