Skip to content

Commit 420b7a1

Browse files
authored
Merge pull request #317 from ydb-platform/auto-style
auto-format script
2 parents 293101e + 82578ac commit 420b7a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+123
-108
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
MESSAGE="$1"
4+
5+
CODE_DIFF="$(git diff)"
6+
if [ -n "$CODE_DIFF" ]; then
7+
echo "$MESSAGE"
8+
echo
9+
echo "$CODE_DIFF"
10+
exit 1;
11+
fi
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
DIR="$1"
6+
7+
cd "$DIR"
8+
9+
export PATH="$(go env GOPATH)/bin:$PATH"
10+
for FILE in $(find . -name '*.go'); do
11+
if [ "YES" == "$(bash ./.github/scripts/is_autogenerated_file.sh "$FILE")" ]; then
12+
echo "Skip autogenerated file: $FILE" >&2
13+
continue
14+
fi
15+
16+
bash ./.github/scripts/format-go-code.sh "$FILE"
17+
done

.github/scripts/format-go-code.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
FILEPATH="$1"
6+
7+
# https://github.com/rinchsan/gosimports
8+
gosimports -local github.com/ydb-platform/ydb-go-sdk/v3 -w "$FILEPATH"
9+
10+
# https://github.com/mvdan/gofumpt
11+
gofumpt -w "$FILEPATH"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
FILEPATH="$1"
4+
5+
grep -q "Code generated by gtrace. DO NOT EDIT." "$FILEPATH" && echo YES && exit 0
6+
grep -q "Code generated by MockGen. DO NOT EDIT." "$FILEPATH" && echo YES && exit 0
7+
8+
echo NO
9+
exit 0

.github/workflows/check-codegen.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,5 @@ jobs:
3636
go generate ./trace
3737
go generate ./...
3838
39-
- name: Check generation
40-
run: |
41-
CODE_DIFF="$(git diff)"
42-
if [ -n "$CODE_DIFF" ]; then
43-
echo "code-generation not equal with committed"
44-
echo
45-
echo "$CODE_DIFF"
46-
exit 1;
47-
fi
39+
- name: Check repository diff
40+
run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "code-generation not equal with committed"

.github/workflows/lint.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,25 @@ jobs:
2121
- name: golangci-lint
2222
uses: golangci/golangci-lint-action@v2
2323
with:
24-
version: v1.46.2
24+
version: v1.46.2
25+
autoformatter:
26+
name: autoformat check
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
31+
- name: Install Go
32+
uses: actions/setup-go@v3
33+
with:
34+
go-version: 1.18
35+
36+
- name: Install utilities
37+
run: |
38+
go install mvdan.cc/[email protected]
39+
go install github.com/rinchsan/gosimports/cmd/[email protected]
40+
41+
- name: format all files with auto-formatter
42+
run: bash ./.github/scripts/format-all-go-code.sh "$PWD"
43+
44+
- name: Check repository diff
45+
run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "auto-format broken"

balancers/config_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/stretchr/testify/require"
77

88
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
9-
109
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
1110
)
1211

config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import (
1010
"google.golang.org/grpc"
1111
grpcCodes "google.golang.org/grpc/codes"
1212

13-
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
14-
1513
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
1614
"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
15+
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
1716
"github.com/ydb-platform/ydb-go-sdk/v3/internal/config"
1817
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
1918
builder "github.com/ydb-platform/ydb-go-sdk/v3/internal/xnet"

config/grpc_credentials.go

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

66
"google.golang.org/grpc"
7-
87
"google.golang.org/grpc/credentials"
98
"google.golang.org/grpc/credentials/insecure"
109
)

connection_e2e_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import (
1111
"testing"
1212
"time"
1313

14-
"google.golang.org/grpc"
15-
"google.golang.org/grpc/metadata"
16-
"google.golang.org/protobuf/proto"
17-
"google.golang.org/protobuf/types/known/durationpb"
18-
1914
"github.com/ydb-platform/ydb-go-genproto/Ydb_Discovery_V1"
2015
"github.com/ydb-platform/ydb-go-genproto/Ydb_Export_V1"
2116
"github.com/ydb-platform/ydb-go-genproto/Ydb_Scripting_V1"
@@ -24,6 +19,10 @@ import (
2419
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Export"
2520
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Operations"
2621
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Scripting"
22+
"google.golang.org/grpc"
23+
"google.golang.org/grpc/metadata"
24+
"google.golang.org/protobuf/proto"
25+
"google.golang.org/protobuf/types/known/durationpb"
2726

2827
"github.com/ydb-platform/ydb-go-sdk/v3"
2928
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"

0 commit comments

Comments
 (0)