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

Add CI for golangci-lint #12

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@ jobs:

- name: 'Test'
run: make test
lint:
permissions:
contents: 'read'
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 1

- name: 'Set up Go'
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: 'go.work'
check-latest: true

- name: 'Lint'
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
with:
version: 'v1.56.2'
args: '-v $(go list -f ''{{.Dir}}/...'' -m | xargs)'
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
run:
timeout: 10m
skip-dirs-use-default: true
modules-download-mode: readonly

issues:
# We want to make sure we get a full report every time. Setting these
# to zero disables the limit.
max-issues-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
SHELL = /bin/bash

all: test lint

# There is currently no convenient way to run tests against a whole Go workspace
# https://github.com/golang/go/issues/50745
test:
go list -f '{{.Dir}}/...' -m | xargs go test -cover

# There is currently no convenient way to run golangci-lint against a whole Go workspace
# https://github.com/golang/go/issues/50745
MODULES := $(shell go list -f '{{.Dir}}/...' -m | xargs)
lint:
golangci-lint run -v $(MODULES)
2 changes: 1 addition & 1 deletion frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (f *Frontend) Run(ctx context.Context, stop <-chan struct{}) {
go func() {
<-stop
f.ready.Store(false)
f.server.Shutdown(ctx)
_ = f.server.Shutdown(ctx)
}()
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/arm/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (body *CloudErrorBody) String() string {
if len(body.Details) > 0 {
details = " Details: "
for i, innerErr := range body.Details {
details := innerErr.String()
details += innerErr.String()
mjlshen marked this conversation as resolved.
Show resolved Hide resolved
if i < len(body.Details)-1 {
details += ", "
}
Expand Down
60 changes: 60 additions & 0 deletions internal/api/arm/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package arm

import "testing"

func TestCloudErrorBody_String(t *testing.T) {
tests := []struct {
name string
body *CloudErrorBody
expected string
}{
{
name: "One detail",
body: &CloudErrorBody{
Code: "code",
Message: "message",
Target: "target",
Details: []CloudErrorBody{
{
Code: "innercode",
Message: "innermessage",
Target: "innertarget",
Details: []CloudErrorBody{},
},
},
},
expected: "code: target: message Details: innercode: innertarget: innermessage",
},
{
name: "Two details",
body: &CloudErrorBody{
Code: "code",
Message: "message",
Target: "target",
Details: []CloudErrorBody{
{
Code: "innercode",
Message: "innermessage",
Target: "innertarget",
Details: []CloudErrorBody{},
},
{
Code: "innercode2",
Message: "innermessage2",
Target: "innertarget2",
Details: []CloudErrorBody{},
},
},
},
expected: "code: target: message Details: innercode: innertarget: innermessage, innercode2: innertarget2: innermessage2",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := test.body.String()
if test.expected != actual {
t.Errorf("expected: %v\ngot: %v", test.expected, actual)
}
})
}
}
4 changes: 2 additions & 2 deletions internal/api/hcpopenshiftcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ type NetworkProfile struct {
// NodePoolAutoscaling represents a node pool autoscaling configuration.
// Visibility for the entire struct is "read".
type NodePoolAutoscaling struct {
MinReplicas int32 `json:minReplicas,omitempty"`
MaxReplicas int32 `json:maxReplicas,omitempty"`
MinReplicas int32 `json:"minReplicas,omitempty"`
MaxReplicas int32 `json:"maxReplicas,omitempty"`
}

// NodePoolProfile represents a worker node pool configuration.
Expand Down
2 changes: 1 addition & 1 deletion internal/api/hcpopenshiftclusternodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ type HCPOpenShiftClusterNodePool struct {
// HCPOpenShiftClusterNodePool resource.
type HCPOpenShiftClusterNodePoolProperties struct {
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty" visibility:"read"`
Profile NodePoolProfile `json:profile,omitempty" visibility:"read,create,update"`
Profile NodePoolProfile `json:"profile,omitempty" visibility:"read,create,update"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ type HCPOpenShiftClusterNodePool struct {
// HCPOpenShiftClusterNodePool resource.
type HCPOpenShiftClusterNodePoolProperties struct {
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty" visibility:"read"`
Profile api.VersionedNodePoolProfile `json:profile,omitempty" visibility:"read,create,update"`
Profile api.VersionedNodePoolProfile `json:"profile,omitempty" visibility:"read,create,update"`
}
4 changes: 2 additions & 2 deletions internal/api/v20240610preview/nodepoolprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package v20240610preview
// NodePoolAutoscaling represents a node pool autoscaling configuration.
// Visibility for the entire struct is "read".
type NodePoolAutoscaling struct {
MinReplicas int32 `json:minReplicas,omitempty"`
MaxReplicas int32 `json:maxReplicas,omitempty"`
MinReplicas int32 `json:"minReplicas,omitempty"`
MaxReplicas int32 `json:"maxReplicas,omitempty"`
}

// NodePoolProfile represents a worker node pool configuration.
Expand Down
Loading