actions / setup-go

Set up your GitHub Actions workflow with a specific version of Go
MIT License
1.41k stars 531 forks source link

Dependencies file is not found. Supported file pattern: go.sum #476

Closed fmunteanu closed 4 months ago

fmunteanu commented 6 months ago

Description: I'm getting this warning, on my workflow:

Warning: Restore cache failed: Dependencies file is not found in /home/runner/work/hugo-test/hugo-test. Supported file pattern: go.sum

image

There is a previous issue https://github.com/actions/setup-go/issues/281, where the solution was to have the checkout executed prior setup-go, which is not the case for my workflow.

Action version: setup-go@v5

Platform:

Runner type:

Tools version: go1.22.2 linux/amd64

Repro steps:
See the related Setup Go step, into workflow details.

Expected behavior: No warnings should be generated.

Actual behavior: Workflow output:

Run actions/setup-go@v5
  with:
    go-version: 1.22.x
    check-latest: false
    token: ***
    cache: true
Setup go version spec 1.22.x
Found in cache @ /opt/hostedtoolcache/go/1.22.2/x64
Added go to the path
Successfully set up Go version 1.22.x
/opt/hostedtoolcache/go/1.22.2/x64/bin/go env GOMODCACHE
/opt/hostedtoolcache/go/1.22.2/x64/bin/go env GOCACHE
/home/runner/.cache/go-build
/home/runner/go/pkg/mod
Warning: Restore cache failed: Dependencies file is not found in /home/runner/work/hugo-test/hugo-test. Supported file pattern: go.sum
go version go1.22.2 linux/amd64
fmunteanu commented 6 months ago

I'm not sure what effect has disabling the cache related to build time, but when I do this, the warning is gone. From my understanding, starting with v4, caching is enabled by default. New step, with cache disabled:

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          cache: false
          go-version: 1.22.x

Workflow build step has no more warnings:

image

HarithaVattikuti commented 6 months ago

Hello @fmunteanu Thank you for creating this issue. We will investigate it and get back to you as soon as we have some feedback.

peterbourgon commented 6 months ago

See #478.

fmunteanu commented 6 months ago

Setting the step to (docs reference):

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          cache: true
          cache-dependency-path: |
            **/go.mod
            **/go.sum

Produces another warning, see Post Setup Go step in workflow:

Post job cleanup.
/opt/hostedtoolcache/go/1.22.2/x64/bin/go env GOMODCACHE
/opt/hostedtoolcache/go/1.22.2/x64/bin/go env GOCACHE
/home/runner/go/pkg/mod
/home/runner/.cache/go-build
Warning: Cache folder path is retrieved but doesn't exist on disk: /home/runner/go/pkg/mod
Cache hit occurred on the primary key setup-go-Linux-ubuntu22-go-1.22.2-2e41450b046298d453631013dd695b7dd7b55d9f5c798193b859fd911bbdba7a, not saving cache.
tamird commented 5 months ago

This also happens in https://github.com/petermattis/goid because that library has no dependencies, and Go doesn't create a go.sum file unless there are at least some dependencies.

It would be good to avoid the warning in such cases.

KathiravanKrish commented 5 months ago

Hi @fmunteanu, The below workflow file have resolved the warning message issue. By adding steps to create the mod cache directory and cache the modules, we ensured that the cache folder path exists before it's accessed by the cache action. This eliminates the warning about the cache folder path not existing on the disk. Going forward, this setup should provide a smoother run for your Go workflows. If you encounter any more issues or have other questions, don't hesitate to ask.

  - name: Check out code into the Go module directory
      uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: 1.22.x
        cache: true

    - name: Create mod cache directory
      run: mkdir -p /home/runner/go/pkg/mod

    - name: Cache modules
      uses: actions/cache@v2
      with:
        path: /home/runner/go/pkg/mod
        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-
    - name: Build
      run: go build -v ./...

    - name: Test
      run: go test -v ./...
KathiravanKrish commented 4 months ago

Hello @fmunteanu Just a gentle reminder!

KathiravanKrish commented 4 months ago

Hello @fmunteanu Just a gentle reminder!

PDX84 commented 4 months ago

https://policies.google.com/terms?hl=en&fg=1