Skip to content

Commit

Permalink
ci: Integrate GitHub Action for golangci-lint Annotations (#106)
Browse files Browse the repository at this point in the history
This PR adds a GitHub action check with annotations supported by golangci-lint.

For now I have set `-issues-exit-code=1` (workflow shows failure if even a single lint error) and to show all lint error annotations (this works for us because we will always be in a lint-error free state). In case we want to suppress lint errors we just use `nolint:xyz` (also won't show up in annotations either).
  • Loading branch information
shahzadlone committed Jan 11, 2022
1 parent 4e89168 commit 6765046
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
gotestsum --junitfile /tmp/test-reports/unit-tests.xml
- store_test_results:
path: /tmp/test-reports
- run:
name: Run the Lint Check
command: make lint

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: golangci-lint

on:
pull_request:

push:
tags:
- v*
branches:
- master
- develop

permissions:
# Optional: allow read access to pull request. Need this if we use the `only-new-issues` option.
pull-requests: read
contents: read

jobs:
golangci:
strategy:
matrix:
go-version: [1.17.5]
os: [ubuntu-latest]

name: lint
runs-on: ${{ matrix.os }}

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

- name: golangci-lint
uses: golangci/golangci-lint-action@v2

with:
# Required: the version of golangci-lint is required.
# Note: The version should not pick the patch version as the latest patch
# version is what will always be used.
version: v1.43

# Optional: working directory, useful for monorepos or if we wanted to run this
# on a non-root directory.
# working-directory: ./

# Optional: golangci-lint command line arguments.
# Note: we can set `--issues-exit-code=0` if we want a successcode always,
# indicating that the linter ran successfully (weather or not linter errors
# exist or not doesn't matter). But the good think is that the annotations
# will still show up. I think this can be useful if we don't want the pipeline
# to stop just because we had some linter errors.
args: --issues-exit-code=1 --config .golangci.sourceinc.yaml

# Optional: we can set the below to `true` if we only want to see newly introduced
# linter errors, however I found that in practive that option is a bit gimmicky,
# as it passes the linter check despite having new linter errors in some cases.
# So we opt in for all annotations of linter errors to show up, this is actually
# nicer because we suppress our linter errors manually anyways so there shouldn't
# be any linter errors anyways. The enforces us to always have a clean lint state.
only-new-issues: false

0 comments on commit 6765046

Please sign in to comment.