Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching broken when go.mod not at top level #370

Closed
gary-lloyd opened this issue Nov 19, 2021 · 2 comments
Closed

Caching broken when go.mod not at top level #370

gary-lloyd opened this issue Nov 19, 2021 · 2 comments

Comments

@gary-lloyd
Copy link

I'm trying to run the action in a sub directory of my mono repo but it seems that the caching isn't working properly meaning my linting job is always slow as it has to build from scratch.

Step defined as

- name: golangci-lint
   uses: golangci/golangci-lint-action@v2
     with:
       version: v1.41
       working-directory: service

I noticed the following in the post Job action log
Cache hit occurred on the primary key golangci-lint.cache-2707-nogomod, not saving cache.

which surprised me as I do have a go.mod file.

Looking at the code for the action I think it is because the cache key build doesn't respect the change of working directory and as the linter is running in the top level of the repository looks for the go.mod file there.

I've been able to work around by handling caching myself as below but would reduce complexity if the listing action could handle this.

golang-lint-with-cache:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: actions/setup-go@v2
        with:
          go-version: '^1.17.3'

      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"

      - name: Go Build Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}

      - name: Go Mod Cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v2
        with:
          version: v1.41
          working-directory: service
          skip-pkg-cache: true
          skip-build-cache: true
          skip-go-installation: true
@okonos
Copy link

okonos commented Apr 1, 2022

I think the caching worked for you, it even says so in the message: "Cache hit occurred". Not entirely as expected, though, as it ignores the go.mod, as you noticed. This seems to be due to the working-directory input being used only for running the linter ("run golangci-lint"), but not for restoring the cache (happens in "prepare environment"), during which go.mod existence is checked, and which runs in the repository root.

if (await pathExists(`go.mod`)) {

I suppose either working-directory input should be respected during environment preparation or another input should be provided.

@ldez ldez mentioned this issue Jun 12, 2023
@ldez
Copy link
Member

ldez commented May 4, 2024

Fixed by #629

@ldez ldez closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants