Skip to content

Commit 851c5e4

Browse files
authored
Merge pull request #2346 from timflannagan/add-sanity-check
Introduce a sanity workflow for checking static linting violations in CI
2 parents 2fd0140 + 2246f8a commit 851c5e4

File tree

19 files changed

+50
-19
lines changed

19 files changed

+50
-19
lines changed

.github/workflows/sanity.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
paths:
9+
- '**'
10+
- '!doc/**'
11+
12+
jobs:
13+
sanity:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-go@v2
18+
with:
19+
go-version: '~1.16'
20+
- name: Install goimports
21+
run: go install golang.org/x/tools/cmd/goimports@latest
22+
- name: Run sanity checks
23+
run: make vendor && make lint && make diff

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ clean:
184184
@rm -rf test/e2e/log
185185
@rm -rf e2e.namespace
186186

187+
lint:
188+
find . -name '*.go' -not -path "./vendor/*" -not -path "./pkg/lib/operatorclient/operatorclientmocks/*" | xargs gofmt -w
189+
find . -name '*.go' -not -path "./vendor/*" -not -path "./pkg/lib/operatorclient/operatorclientmocks/*" | xargs goimports -w
187190

188191
# Copy CRD manifests
189192
manifests: vendor

pkg/controller/certs/certs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
)
1717

1818
type CertGenerator interface {
19-
Generate(notAfter time.Time, organization string, ca *KeyPair, hosts []string) (*KeyPair, error)
19+
Generate(notAfter time.Time, organization string, ca *KeyPair, hosts []string) (*KeyPair, error)
2020
}
2121

2222
type CertGeneratorFunc func(notAfter time.Time, organization string, ca *KeyPair, hosts []string) (*KeyPair, error)
2323

24-
func (f CertGeneratorFunc) Generate(notAfter time.Time, organization string, ca *KeyPair, hosts []string) (*KeyPair, error) {
24+
func (f CertGeneratorFunc) Generate(notAfter time.Time, organization string, ca *KeyPair, hosts []string) (*KeyPair, error) {
2525
return f(notAfter, organization, ca, hosts)
2626
}
2727

pkg/controller/operators/catalog/installplan_sync.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66

7-
87
"github.com/sirupsen/logrus"
98
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
109
"k8s.io/apimachinery/pkg/labels"

pkg/controller/operators/openshift/clusteroperator_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package openshift
22

33
import (
44
"fmt"
5+
56
semver "github.com/blang/semver/v4"
67
. "github.com/onsi/ginkgo"
78
. "github.com/onsi/gomega"

pkg/controller/operators/operatorcondition_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
. "github.com/onsi/ginkgo"
88
. "github.com/onsi/gomega"
9-
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
109
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
10+
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
1111
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
1212

1313
appsv1 "k8s.io/api/apps/v1"

pkg/controller/operators/operatorconditiongenerator_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
. "github.com/onsi/ginkgo"
1616
. "github.com/onsi/gomega"
17-
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
1817
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
18+
operatorsv2 "github.com/operator-framework/api/pkg/operators/v2"
1919
)
2020

2121
var _ = Describe("The OperatorConditionsGenerator Controller", func() {

pkg/controller/registry/grpc/source.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package grpc
22

33
import (
44
"context"
5-
"github.com/operator-framework/operator-registry/pkg/client"
65
"sync"
76
"time"
87

8+
"github.com/operator-framework/operator-registry/pkg/client"
9+
910
"github.com/sirupsen/logrus"
1011
"google.golang.org/grpc"
1112
"google.golang.org/grpc/connectivity"
@@ -225,4 +226,4 @@ func (s *SourceStore) ClientsForNamespaces(namespaces ...string) map[registry.Ca
225226

226227
// TODO : remove unhealthy
227228
return refs
228-
}
229+
}

pkg/controller/registry/resolver/rbac.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func generateName(base string, o interface{}) string {
2222
hashutil.DeepHashObject(hasher, o)
2323
hash := utilrand.SafeEncodeString(fmt.Sprint(hasher.Sum32()))
2424
if len(base)+len(hash) > maxNameLength {
25-
base = base[:maxNameLength - len(hash) - 1]
25+
base = base[:maxNameLength-len(hash)-1]
2626
}
2727

2828
return fmt.Sprintf("%s-%s", base, hash)

pkg/controller/registry/resolver/rbac_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ func TestGenerateName(t *testing.T) {
2929
name: "generate",
3030
args: args{
3131
base: "myname",
32-
o: []string{"something"},
32+
o: []string{"something"},
3333
},
3434
want: "myname-9c895f74f",
3535
},
3636
{
3737
name: "truncated",
3838
args: args{
3939
base: strings.Repeat("name", 100),
40-
o: []string{"something", "else"},
40+
o: []string{"something", "else"},
4141
},
4242
want: "namenamenamenamenamenamenamenamenamenamenamenamename-78fd8b4d6b",
4343
},

0 commit comments

Comments
 (0)