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

Better support for go submodules #74

Open
8tomat8 opened this issue Aug 21, 2020 · 5 comments
Open

Better support for go submodules #74

8tomat8 opened this issue Aug 21, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@8tomat8
Copy link

8tomat8 commented Aug 21, 2020

Context:
We have a repository which has a structure similar to

- root module
-- pkgA submodule
-- pkgB submodule
-- etc...

root module has no go files.
Each pkg{A,B,...} module has code+tests and separate go.mod+go.sum+vendor files.

Issue:
On every PR we are running

jobs:
  test:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-go@v1
      with:
        go-version: '1.15.x'
    - name: Run tests
      # Go into each folder in the repo and run tests 10 times with the race detector
      run: for d in ./*/ ; do (cd "$d" && go test -race -count 10 ./...); done

  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install golangci-lint
        uses: golangci/[email protected]
        with:
          version: v1.26
          args: --modules-download-mode vendor --config ./.golangci.yml ./...

But it fails with ERRO Running error: context loading failed: no go files to analyze

Question:
Is there a way to use this action to run linter in all the folders but without creating separate jobs with a matrix?

@SVilgelm
Copy link
Member

The workaround is creating a step for every project and using the working-directory parameter:

  golangci:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Check golangci-lint for pkgA
        uses: golangci/[email protected]
        with:
          version: v1.29
          working-directory: pkgA
          args: --modules-download-mode vendor --config ./.golangci.yml ./...
      - name: Check golangci-lint for pkgB
        uses: golangci/[email protected]
        with:
          version: v1.29
          working-directory: pkgB
          args: --modules-download-mode vendor --config ./.golangci.yml ./...

@8tomat8
Copy link
Author

8tomat8 commented Aug 21, 2020

This is exactly what we are trying to avoid :)
The issue here that every step has to be manually added and devs will definitely forget to update it 🤷

@mrigankakb
Copy link

mrigankakb commented Oct 2, 2020

I am facing the same issue with my monorepo. Seems this is not an issue with the action implementation, but default behaviour of golangci-lint cmd. However, it will be really helpful to have this capability for this to be used seamlessly in a monorepo.

@torkelrogstad
Copy link

Here's a rather nice approach for doing this using the matrix property in your actions config: golangci/golangci-lint#828 (comment)

@ldez
Copy link
Member

ldez commented Jun 22, 2024

I added examples for Go workspace and the GitHub Action: https://github.com/golangci/golangci-lint-action?tab=readme-ov-file#how-to-use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants