From 2972025e443ca382ee2c11d21468c78e63410a3e Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:01:29 -0500 Subject: [PATCH 01/13] Revert "Use slices from stdlib over golang.org/x/exp/slices (#134)" This reverts commit d4541f4dacb55959f056039e9838ee52f372d55a. --- tools/go.mod | 1 + tools/go.sum | 2 ++ .../protovalidate-conformance/internal/results/result.go | 9 ++++----- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/go.mod b/tools/go.mod index 8e5fcda0..b33822f6 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -6,6 +6,7 @@ require ( github.com/bufbuild/protocompile v0.6.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 golang.org/x/sync v0.5.0 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/tools/go.sum b/tools/go.sum index a8dba8c5..3fffb5ae 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -11,6 +11,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/tools/protovalidate-conformance/internal/results/result.go b/tools/protovalidate-conformance/internal/results/result.go index d2fed486..c7cc94b1 100644 --- a/tools/protovalidate-conformance/internal/results/result.go +++ b/tools/protovalidate-conformance/internal/results/result.go @@ -15,13 +15,12 @@ package results import ( - "cmp" "fmt" - "slices" "strings" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/harness" + "golang.org/x/exp/slices" ) type Result interface { @@ -224,10 +223,10 @@ func (u unexpectedErrorResult) IsSuccessWith(_ Result, _ *harness.ResultOptions) } func SortViolations(violations []*validate.Violation) { - slices.SortFunc(violations, func(a, b *validate.Violation) int { + slices.SortFunc(violations, func(a, b *validate.Violation) bool { if a.GetConstraintId() == b.GetConstraintId() { - return cmp.Compare(a.GetFieldPath(), b.GetFieldPath()) + return a.GetFieldPath() < b.GetFieldPath() } - return cmp.Compare(a.GetConstraintId(), b.GetConstraintId()) + return a.GetConstraintId() < b.GetConstraintId() }) } From 2040ed8a1b083a4511d1ad1d0fcb46bc42979c5c Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:05:00 -0500 Subject: [PATCH 02/13] ci run on all branches --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c21ae140..fbc0cd0c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,7 +1,7 @@ name: CI on: push: - branches: [main] + branches: ['*'] pull_request: branches: [main] workflow_dispatch: {} # support manual runs From a179325f05ec1e23a46b2067b18b73b01c7e5a32 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:08:21 -0500 Subject: [PATCH 03/13] branch back to main --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fbc0cd0c..c21ae140 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,7 +1,7 @@ name: CI on: push: - branches: ['*'] + branches: [main] pull_request: branches: [main] workflow_dispatch: {} # support manual runs From bc258e1fd17cfba50397bc7ab6581955decd9b0e Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:14:15 -0500 Subject: [PATCH 04/13] use make lint-go --- .github/workflows/ci.yaml | 10 +--------- Makefile | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c21ae140..892e37c6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,12 +48,4 @@ jobs: - name: Test run: make test - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.53 - skip-pkg-cache: true - only-new-issues: true - args: > - --modules-download-mode=readonly - --timeout=3m0s - ./tools/... + run: make lint-go diff --git a/Makefile b/Makefile index 4ba2fbdc..87d0ff3c 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ lint: lint-proto lint-go ## Lint code and protos .PHONY: lint-go lint-go: $(BIN)/golangci-lint - $(BIN)/golangci-lint run ./tools/... + $(BIN)/golangci-lint run --modules-download-mode=readonly --timeout=3m0s ./tools/... .PHONY: lint-proto lint-proto: $(BIN)/buf From 96868bb3201e722ddfd78b7cd29a1c06fd76d474 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:34:17 -0500 Subject: [PATCH 05/13] add make lint-go-fix and run it --- Makefile | 4 ++++ go.work | 2 +- go.work.sum | 1 + tools/go.mod | 3 +-- tools/go.sum | 3 +-- .../protovalidate-conformance/internal/results/result.go | 9 +++++---- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 87d0ff3c..6404619b 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,10 @@ lint: lint-proto lint-go ## Lint code and protos lint-go: $(BIN)/golangci-lint $(BIN)/golangci-lint run --modules-download-mode=readonly --timeout=3m0s ./tools/... +.PHONY: lint-go-fix +lint-go-fix: $(BIN)/golangci-lint + $(BIN)/golangci-lint run --fix --modules-download-mode=readonly --timeout=3m0s ./tools/... + .PHONY: lint-proto lint-proto: $(BIN)/buf $(BIN)/buf lint diff --git a/go.work b/go.work index 934e6373..99173284 100644 --- a/go.work +++ b/go.work @@ -1,4 +1,4 @@ -go 1.18 +go 1.21 use ( ./tools diff --git a/go.work.sum b/go.work.sum index 31e44ff0..770f72f5 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,5 +1,6 @@ github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE= diff --git a/tools/go.mod b/tools/go.mod index b33822f6..26166ac9 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -1,12 +1,11 @@ module github.com/bufbuild/protovalidate/tools -go 1.18 +go 1.21 require ( github.com/bufbuild/protocompile v0.6.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 golang.org/x/sync v0.5.0 google.golang.org/protobuf v1.31.0 gopkg.in/yaml.v3 v3.0.1 diff --git a/tools/go.sum b/tools/go.sum index 3fffb5ae..e196bebd 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -5,14 +5,13 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/tools/protovalidate-conformance/internal/results/result.go b/tools/protovalidate-conformance/internal/results/result.go index c7cc94b1..e52c2329 100644 --- a/tools/protovalidate-conformance/internal/results/result.go +++ b/tools/protovalidate-conformance/internal/results/result.go @@ -18,9 +18,10 @@ import ( "fmt" "strings" + "cmp" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/harness" - "golang.org/x/exp/slices" + "slices" ) type Result interface { @@ -223,10 +224,10 @@ func (u unexpectedErrorResult) IsSuccessWith(_ Result, _ *harness.ResultOptions) } func SortViolations(violations []*validate.Violation) { - slices.SortFunc(violations, func(a, b *validate.Violation) bool { + slices.SortFunc(violations, func(a, b *validate.Violation) int { if a.GetConstraintId() == b.GetConstraintId() { - return a.GetFieldPath() < b.GetFieldPath() + return cmp.Compare(a.GetFieldPath(), b.GetFieldPath()) } - return a.GetConstraintId() < b.GetConstraintId() + return cmp.Compare(a.GetConstraintId(), b.GetConstraintId()) }) } From 3cd8ac79d43404dd840f78a8e9af908c2033915e Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:45:01 -0500 Subject: [PATCH 06/13] ignore gci in for result go --- .golangci.yml | 4 ++++ tools/protovalidate-conformance/internal/results/result.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 07488bb2..b5daa114 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -65,6 +65,10 @@ issues: linters: - gosec - forbidigo + # gci is confused by "slices" and suggests to move it to the end of the import list + - path: tools/protovalidate-conformance/internal/results/result.go + linters: + - gci # Building the conformance test suites - path: tools/protovalidate-conformance/internal/cases/ linters: diff --git a/tools/protovalidate-conformance/internal/results/result.go b/tools/protovalidate-conformance/internal/results/result.go index e52c2329..dd6c805c 100644 --- a/tools/protovalidate-conformance/internal/results/result.go +++ b/tools/protovalidate-conformance/internal/results/result.go @@ -19,9 +19,10 @@ import ( "strings" "cmp" + "slices" + "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/harness" - "slices" ) type Result interface { From 0b048980988b09336ec5b2cd31c3d083cba621c4 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Mon, 20 Nov 2023 20:45:36 -0500 Subject: [PATCH 07/13] import list --- tools/protovalidate-conformance/internal/results/result.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/protovalidate-conformance/internal/results/result.go b/tools/protovalidate-conformance/internal/results/result.go index dd6c805c..d2fed486 100644 --- a/tools/protovalidate-conformance/internal/results/result.go +++ b/tools/protovalidate-conformance/internal/results/result.go @@ -15,11 +15,10 @@ package results import ( - "fmt" - "strings" - "cmp" + "fmt" "slices" + "strings" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate" "github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/harness" From 3614a005a85de0456b2fecbb9ed6cbf5a0ab2ca6 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Tue, 21 Nov 2023 09:56:25 -0500 Subject: [PATCH 08/13] go back to golangci-lint action, but with only-new-issues set to false --- .github/workflows/ci.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 892e37c6..87b99efd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,4 +48,11 @@ jobs: - name: Test run: make test - name: Lint - run: make lint-go + uses: golangci/golangci-lint-action@v3 + with: + version: v1.53 + skip-pkg-cache: true + args: > + --modules-download-mode=readonly + --timeout=3m0s + ./tools/... From f9b8cc3cac3b644f2523f5af565c54826e2ac213 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Tue, 21 Nov 2023 10:31:29 -0500 Subject: [PATCH 09/13] try skip-cache --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 87b99efd..d39a7ab9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,7 +51,7 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.53 - skip-pkg-cache: true + skip-cache: true args: > --modules-download-mode=readonly --timeout=3m0s From e014d09b045ebdd3bde5db4e82f6f779f384dc01 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Tue, 21 Nov 2023 10:50:32 -0500 Subject: [PATCH 10/13] try go install --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d39a7ab9..0298cbbf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -52,6 +52,7 @@ jobs: with: version: v1.53 skip-cache: true + install-mode: "goinstall" args: > --modules-download-mode=readonly --timeout=3m0s From 2580957ab2a8ff296ee9bc6b2987251c28dbf47d Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Tue, 21 Nov 2023 10:56:53 -0500 Subject: [PATCH 11/13] change other options back --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0298cbbf..5ff9bf4e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,8 +51,9 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.53 - skip-cache: true install-mode: "goinstall" + skip-pkg-cache: true + only-new-issues: false args: > --modules-download-mode=readonly --timeout=3m0s From 4ef8ee30bc2007b10ba644617cdb637d0ce9a952 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Tue, 21 Nov 2023 11:07:06 -0500 Subject: [PATCH 12/13] remove quotes --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5ff9bf4e..20bd3459 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,7 +51,7 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: v1.53 - install-mode: "goinstall" + install-mode: goinstall skip-pkg-cache: true only-new-issues: false args: > From 96150b575efcf42a08af97572edcd01137098936 Mon Sep 17 00:00:00 2001 From: Oliver Sun Date: Tue, 21 Nov 2023 11:36:32 -0500 Subject: [PATCH 13/13] make lint-go --- .github/workflows/ci.yaml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 20bd3459..892e37c6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -48,13 +48,4 @@ jobs: - name: Test run: make test - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.53 - install-mode: goinstall - skip-pkg-cache: true - only-new-issues: false - args: > - --modules-download-mode=readonly - --timeout=3m0s - ./tools/... + run: make lint-go