Pārlūkot izejas kodu

Lint golang changes on push (#3375)

Stefan McShane 2 gadi atpakaļ
vecāks
revīzija
d0b5b4d0e4
3 mainītis faili ar 32 papildinājumiem un 10 dzēšanām
  1. 4 6
      .github/golangci-lint.yaml
  2. 23 3
      .github/workflows/pr_push_checks.yaml
  3. 5 1
      Taskfile.yaml

+ 4 - 6
.github/golangci-lint.yaml

@@ -5,23 +5,21 @@ run:
   build-tags:
     - codeanalysis
 
-# enable exported entity commenting lint rule
 issues:
-  exclude:
-    - EXC0012
+  new-from-rev: origin/master # default: HEAD, this will only show linting changes in the current change
   exclude-use-default: false
 linters-settings:
   revive:
     rules:
       - name: exported
         severity: error
-  # gocyclo:
-  #   min-complexity: 15
+  gocyclo:
+    min-complexity: 15
   gomoddirectives:
     replace-local: false
   gosec:
     excludes:
-    - G307
+    - G307 # exclude duplicated errcheck checks
 
 linters:
   # disable all default-enabled linters so nothing is mysterious

+ 23 - 3
.github/workflows/pr_push_checks.yaml

@@ -26,11 +26,31 @@ jobs:
         with:
           go-version-file: go.mod
           cache: false
-          go-version: '1.20.5'
-      - name: Run Go vet
-        run: go vet ./${{ matrix.folder }}/...
       - name: Run Go tests
         run: go test ./${{ matrix.folder }}/...
+  linting:
+    name: Go Linter
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/setup-go@v4
+        with:
+          cache: false
+      - uses: actions/checkout@v3
+      - name: Setup Go Cache
+        uses: actions/cache@v3
+        with:
+          path: |
+            ~/.cache/go-build
+            ~/go/pkg/mod
+          key: porter-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: porter-go-`
+      - name: golangci-lint
+        uses: golangci/golangci-lint-action@v3
+        with:
+          version: latest
+          args: -c .github/golangci-lint.yaml --verbose
+          skip-pkg-cache: true
+          only-new-issues: true # this is needed until the following is merged: https://github.com/golangci/golangci-lint-action/issues/820
   build-npm:
     name: Running smoke test npm build
     runs-on: ubuntu-latest

+ 5 - 1
Taskfile.yaml

@@ -17,4 +17,8 @@ tasks:
       ignore_error: false
       silent: true
  
-
+  lint:
+    desc: Run all available linters. This mimics any checks performed in Pull Request pre-merge checks
+    cmd: golangci-lint run -c .github/golangci-lint.yaml
+    env:
+      GOWORK: off