From 9858689671a3d714ac570518385c8f15240714e5 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 20 Jan 2022 14:40:40 -0800 Subject: [PATCH 1/3] Update CI project checks to use containerd project action Signed-off-by: Derek McGowan --- .github/workflows/ci.yml | 95 +++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba6c18774..5ad4014d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,56 @@ on: branches: [ main ] jobs: + # + # golangci-lint + # + linters: + name: Linters + runs-on: ${{ matrix.os }} + timeout-minutes: 10 + + strategy: + matrix: + go-version: [1.17] + os: [ubuntu-18.04, macos-10.15, windows-2019] + + steps: + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - uses: actions/checkout@v2 + - uses: golangci/golangci-lint-action@v2 + with: + version: v1.42.0 + args: --timeout=5m + skip-go-installation: true + + # + # Project checks + # + project: + name: Project Checks + runs-on: ubuntu-18.04 + timeout-minutes: 5 + steps: + - uses: actions/setup-go@v2 + with: + go-version: '1.17' + + - uses: actions/checkout@v2 + with: + path: src/github.com/containerd/ttrpc + fetch-depth: 25 + + - uses: containerd/project-checks@v1 + with: + working-directory: src/github.com/containerd/ttrpc + + # + # Build and Test project + # build: strategy: fail-fast: false @@ -18,17 +67,9 @@ jobs: timeout-minutes: 5 steps: - - name: Set up Go 1.15 - uses: actions/setup-go@v2 + - uses: actions/setup-go@v2 with: - go-version: 1.15 - id: go - - - name: Setup Go binary path - shell: bash - run: | - echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV - echo "${{ github.workspace }}/bin" >> $GITHUB_PATH + go-version: '1.17' - name: Check out code uses: actions/checkout@v2 @@ -36,37 +77,6 @@ jobs: path: src/github.com/containerd/ttrpc fetch-depth: 25 - - name: Checkout project - uses: actions/checkout@v2 - with: - repository: containerd/project - path: src/github.com/containerd/project - - - name: Install dependencies - env: - GO111MODULE: off - run: | - go get -u github.com/vbatts/git-validation - go get -u github.com/kunalkushwaha/ltag - - - name: Check DCO/whitespace/commit message - env: - GITHUB_COMMIT_URL: ${{ github.event.pull_request.commits_url }} - DCO_VERBOSITY: "-q" - DCO_RANGE: "" - working-directory: src/github.com/containerd/ttrpc - run: | - if [ -z "${GITHUB_COMMIT_URL}" ]; then - DCO_RANGE=$(jq -r '.before +".."+ .after' ${GITHUB_EVENT_PATH}) - else - DCO_RANGE=$(curl ${GITHUB_COMMIT_URL} | jq -r '.[0].parents[0].sha +".."+ .[-1].sha') - fi - ../project/script/validate/dco - - - name: Check file headers - run: ../project/script/validate/fileheader ../project/ - working-directory: src/github.com/containerd/ttrpc - - name: Test working-directory: src/github.com/containerd/ttrpc run: | @@ -76,6 +86,9 @@ jobs: run: bash <(curl -s https://codecov.io/bash) working-directory: src/github.com/containerd/ttrpc + # + # Run Protobuild + # protobuild: name: Run Protobuild runs-on: ubuntu-20.04 From f7a2e09ef8345436f34a18d979989b7c4a49220f Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 20 Jan 2022 15:06:40 -0800 Subject: [PATCH 2/3] Fix lint issues Cleanup server test Signed-off-by: Derek McGowan --- .github/workflows/ci.yml | 20 +++++++----- .golangci.yml | 54 +++++++++++++++++++++++++++++++++ client.go | 2 +- client_test.go | 2 +- example/cmd/handshaker_other.go | 1 + handshake.go | 2 +- interceptor.go | 2 +- server_test.go | 38 +++++++++++++++-------- types.go | 2 -- unixcreds_linux.go | 6 +--- 10 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ad4014d5..858695c20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,10 @@ on: pull_request: branches: [ main ] +permissions: + contents: read + pull-requests: read + jobs: # # golangci-lint @@ -18,19 +22,19 @@ jobs: strategy: matrix: go-version: [1.17] - os: [ubuntu-18.04, macos-10.15, windows-2019] + os: [ubuntu-latest, macos-latest, windows-latest] steps: - - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v2 - - uses: golangci/golangci-lint-action@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 with: - version: v1.42.0 + version: v1.43.0 args: --timeout=5m - skip-go-installation: true + only-new-issues: true + - name: golangci-lint errors + run: golangci-lint run + if: ${{ failure() }} # # Project checks diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..c8be4980c --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,54 @@ +linters: + enable: + - structcheck + - varcheck + - staticcheck + - unconvert + - gofmt + - goimports + - revive + - ineffassign + - vet + - unused + - misspell + disable: + - errcheck + +linters-settings: + revive: + ignore-generated-headers: true + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + arguments: [["UID", "GID"], []] + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + +issues: + include: + - EXC0002 + +run: + timeout: 8m + skip-dirs: + - example diff --git a/client.go b/client.go index 26c3dd2a9..d755a1469 100644 --- a/client.go +++ b/client.go @@ -123,7 +123,7 @@ func (c *Client) Call(ctx context.Context, service, method string, req, resp int } if dl, ok := ctx.Deadline(); ok { - creq.TimeoutNano = dl.Sub(time.Now()).Nanoseconds() + creq.TimeoutNano = time.Until(dl).Nanoseconds() } info := &UnaryClientInfo{ diff --git a/client_test.go b/client_test.go index 9114159f3..779d744f0 100644 --- a/client_test.go +++ b/client_test.go @@ -62,7 +62,7 @@ func TestUserOnCloseWait(t *testing.T) { t.Fatalf("expected error %v, but got %v", context.DeadlineExceeded, err) } - _ = <-dataCh + <-dataCh if err := client.UserOnCloseWait(ctx); err != nil { t.Fatalf("expected error nil , but got %v", err) diff --git a/example/cmd/handshaker_other.go b/example/cmd/handshaker_other.go index 5ea1a90ea..3d1360bf9 100644 --- a/example/cmd/handshaker_other.go +++ b/example/cmd/handshaker_other.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux /* diff --git a/handshake.go b/handshake.go index a424b67a4..3c6b610d3 100644 --- a/handshake.go +++ b/handshake.go @@ -45,6 +45,6 @@ func (fn handshakerFunc) Handshake(ctx context.Context, conn net.Conn) (net.Conn return fn(ctx, conn) } -func noopHandshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) { +func noopHandshake(_ context.Context, conn net.Conn) (net.Conn, interface{}, error) { return conn, nil, nil } diff --git a/interceptor.go b/interceptor.go index c1219dac6..c6a4a8d43 100644 --- a/interceptor.go +++ b/interceptor.go @@ -41,7 +41,7 @@ type UnaryServerInterceptor func(context.Context, Unmarshaler, *UnaryServerInfo, // UnaryClientInterceptor specifies the interceptor function for client request/response type UnaryClientInterceptor func(context.Context, *Request, *Response, *UnaryClientInfo, Invoker) error -func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, info *UnaryServerInfo, method Method) (interface{}, error) { +func defaultServerInterceptor(ctx context.Context, unmarshal Unmarshaler, _ *UnaryServerInfo, method Method) (interface{}, error) { return method(ctx, unmarshal) } diff --git a/server_test.go b/server_test.go index dbfe936f3..ef8092c59 100644 --- a/server_test.go +++ b/server_test.go @@ -123,16 +123,23 @@ func TestServer(t *testing.T) { go server.Serve(ctx, listener) defer server.Shutdown(ctx) - const calls = 2 - results := make(chan callResult, 2) - go roundTrip(ctx, t, tclient, "bar", results) - go roundTrip(ctx, t, tclient, "baz", results) + testCases := []string{"bar", "baz"} + results := make(chan callResult, len(testCases)) + for _, tc := range testCases { + go func(expected string) { + results <- roundTrip(ctx, tclient, expected) + }(tc) + } - for i := 0; i < calls; i++ { + for i := 0; i < len(testCases); { result := <-results + if result.err != nil { + t.Fatalf("(%s): %v", result.name, result.err) + } if !reflect.DeepEqual(result.received, result.expected) { - t.Fatalf("unexpected response: %+#v != %+#v", result.received, result.expected) + t.Fatalf("(%s): unexpected response: %+#v != %+#v", result.name, result.received, result.expected) } + i++ } } @@ -483,29 +490,34 @@ func checkServerShutdown(t *testing.T, server *Server) { } type callResult struct { + name string + err error input *testPayload expected *testPayload received *testPayload } -func roundTrip(ctx context.Context, t *testing.T, client *testingClient, value string, results chan callResult) { - t.Helper() +func roundTrip(ctx context.Context, client *testingClient, name string) callResult { var ( tp = &testPayload{ - Foo: "bar", + Foo: name, } ) - ctx = WithMetadata(ctx, MD{"foo": []string{"bar"}}) + ctx = WithMetadata(ctx, MD{"foo": []string{name}}) resp, err := client.Test(ctx, tp) if err != nil { - t.Fatal(err) + return callResult{ + name: name, + err: err, + } } - results <- callResult{ + return callResult{ + name: name, input: tp, - expected: &testPayload{Foo: strings.Repeat(tp.Foo, 2), Metadata: "bar"}, + expected: &testPayload{Foo: strings.Repeat(tp.Foo, 2), Metadata: name}, received: resp, } } diff --git a/types.go b/types.go index 9a1c19a72..c4dcb82b5 100644 --- a/types.go +++ b/types.go @@ -51,8 +51,6 @@ func (r *StringList) Reset() { *r = StringList{} } func (r *StringList) String() string { return fmt.Sprintf("%+#v", r) } func (r *StringList) ProtoMessage() {} -func makeStringList(item ...string) StringList { return StringList{List: item} } - type KeyValue struct { Key string `protobuf:"bytes,1,opt,name=key,proto3"` Value string `protobuf:"bytes,2,opt,name=value,proto3"` diff --git a/unixcreds_linux.go b/unixcreds_linux.go index a59dad60c..11bc9f9a7 100644 --- a/unixcreds_linux.go +++ b/unixcreds_linux.go @@ -29,7 +29,7 @@ import ( type UnixCredentialsFunc func(*unix.Ucred) error -func (fn UnixCredentialsFunc) Handshake(ctx context.Context, conn net.Conn) (net.Conn, interface{}, error) { +func (fn UnixCredentialsFunc) Handshake(_ context.Context, conn net.Conn) (net.Conn, interface{}, error) { uc, err := requireUnixSocket(conn) if err != nil { return nil, nil, fmt.Errorf("ttrpc.UnixCredentialsFunc: require unix socket: %w", err) @@ -88,10 +88,6 @@ func UnixSocketRequireSameUser() UnixCredentialsFunc { return UnixSocketRequireUidGid(euid, egid) } -func requireRoot(ucred *unix.Ucred) error { - return requireUidGid(ucred, 0, 0) -} - func requireUidGid(ucred *unix.Ucred, uid, gid int) error { if (uid != -1 && uint32(uid) != ucred.Uid) || (gid != -1 && uint32(gid) != ucred.Gid) { return fmt.Errorf("ttrpc: invalid credentials: %v", syscall.EPERM) From ad4afc0343bad3715e1c675a476dcc557c9717b8 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 21 Jan 2022 12:10:45 -0800 Subject: [PATCH 3/3] Update to latest os for build and test Signed-off-by: Derek McGowan --- .github/workflows/ci.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 858695c20..a1bf74128 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-18.04, macos-10.15] + os: [ubuntu-latest, macos-latest, windows-latest] name: ${{ matrix.os }} runs-on: ${{ matrix.os }} timeout-minutes: 5 @@ -84,11 +84,7 @@ jobs: - name: Test working-directory: src/github.com/containerd/ttrpc run: | - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - - - name: Codecov - run: bash <(curl -s https://codecov.io/bash) - working-directory: src/github.com/containerd/ttrpc + go test -v -race ./... # # Run Protobuild