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

Adds linters to Go modules #626

Merged
merged 12 commits into from
Nov 30, 2023
28 changes: 28 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint Go Code

on:
pull_request:
paths:
- '**/*.go'

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
blumamir marked this conversation as resolved.
Show resolved Hide resolved

- name: Set up Go
uses: actions/setup-go@v2
blumamir marked this conversation as resolved.
Show resolved Hide resolved
with:
go-version: 1.19.0
blumamir marked this conversation as resolved.
Show resolved Hide resolved

- name: Install golangci-lint
run: go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is a github action for that which does many awesome things:

We recommend using our GitHub Action for running golangci-lint in CI for GitHub projects. It's fast and uses smart caching inside and it can be much faster than the simple binary installation.

Also, the action creates GitHub annotations for found issues: you don't need to dig into build log to see found by golangci-lint issues

Perhaps we can use it instead?


- name: Run golangci-lint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the documentation for the action:

Note: By default, the .golangci.yml file should be at the root of the repository.

From looking at the reference repo here, it seems to contain a .golangci.yml file as well, but such a file is not added to this repo in this PR.

I wonder if it's intentional

Copy link
Contributor Author

@ankur0904 ankur0904 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blumamir
Sorry for this but I am unable to understand.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blumamir Sorry for this but I am unable to understand.

@ankur0904 I think that you also need to add a .golangci.yml file to the project, which this github actions will look for.

run: golangci-lint run --allow-serial-runners
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving this to Makefile, so the user can execute it locally to get lint output before submitting a PR and running the CI


- name: Fix Go code with golangci-lint (optional)
run: golangci-lint run --fix --allow-serial-runners
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this step will not run if the previous step failed.
If CI step is making changes to files (like lint fix), they have to be committed and pushed to take effect, otherwise, they just go down with the CI container.

My suggestion is to just verify in CI that make lint is successful, and if not, the user will have to run locally make golangci-lint-fix and push a fixed version after linting