Skip to content

Commit 1bfb0bd

Browse files
committed
ci: Improve performance of go lint and formatting
- Add additional filters for `find` so it does not need to traverse irrelevant dirs - Allow parallel golangci-lint runs so node/ and sdk/ run at the same time
1 parent 0802921 commit 1bfb0bd

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

node/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: lint
22
lint:
3-
golangci-lint run -c ../.golangci.yml ./...
3+
golangci-lint run -c ../.golangci.yml --allow-parallel-runners ./...
44

55
.PHONY: test
66
test:

scripts/lint.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ format(){
4242
exit 1
4343
fi
4444

45-
# Use -exec because of pitfall #1 in http://mywiki.wooledge.org/BashPitfalls
46-
GOFMT_OUTPUT="$(find "./sdk" "./node" "./wormchain" -type f -name '*.go' -not -path '*.pb.go' -print0 | xargs -r -0 goimports $GOIMPORTS_ARGS 2>&1)"
45+
GOFMT_OUTPUT="$(find "./sdk" "./node" "./wormchain" \
46+
\( -name node_modules -prune \) -o \
47+
\( -name .gocache -prune \) -o \
48+
\( -name target -prune \) -o \
49+
-type f -name '*.go' -not -path '*.pb.go' -print0 | xargs -r -0 goimports $GOIMPORTS_ARGS 2>&1)"
4750

4851
if [ -n "$GOFMT_OUTPUT" ]; then
4952
if [ "$GITHUB_ACTION" == "true" ]; then
@@ -55,25 +58,45 @@ format(){
5558
}
5659

5760
lint(){
61+
LINT_EXIT=0
62+
5863
# === Spell check
5964
if ! command -v cspell >/dev/null 2>&1; then
6065
printf "%s\n" "cspell is not installed. Skipping spellcheck"
6166
else
62-
cspell "*/**.*md"
67+
cspell "*/**.*md" &
68+
CSPELL_PID=$!
6369
fi
64-
70+
6571
# === Go linting
6672
# Check for dependencies
6773
if ! command -v golangci-lint >/dev/null 2>&1; then
6874
printf "%s\n" "Require golangci-lint. You can run this command in a docker container instead with '-c' and not worry about it or install it: https://golangci-lint.run/usage/install/"
6975
fi
7076

7177
# Do the actual linting!
72-
cd "$ROOT"/node
73-
golangci-lint run --timeout=10m $GOLANGCI_LINT_ARGS ./...
78+
(
79+
cd "$ROOT"/node
80+
golangci-lint run --timeout=10m --allow-parallel-runners $GOLANGCI_LINT_ARGS ./...
81+
) &
82+
NODE_PID=$!
83+
84+
(
85+
cd "${ROOT}/sdk"
86+
golangci-lint run --timeout=10m --allow-parallel-runners $GOLANGCI_LINT_ARGS ./...
87+
) &
88+
SDK_PID=$!
89+
90+
wait $NODE_PID || LINT_EXIT=1
91+
wait $SDK_PID || LINT_EXIT=1
92+
93+
if [ -n "${CSPELL_PID:-}" ]; then
94+
wait $CSPELL_PID || LINT_EXIT=1
95+
fi
7496

75-
cd "${ROOT}/sdk"
76-
golangci-lint run --timeout=10m $GOLANGCI_LINT_ARGS ./...
97+
if [ $LINT_EXIT -ne 0 ]; then
98+
exit 1
99+
fi
77100
}
78101

79102
DOCKER="false"

0 commit comments

Comments
 (0)