1+ name : Code Quality Check
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+ types : [ opened, synchronize, reopened, edited, ready_for_review ]
9+ workflow_dispatch :
10+
11+ permissions :
12+ contents : read
13+
14+ concurrency :
15+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+ cancel-in-progress : true
17+
18+ env :
19+ GO_VERSION : ' 1.21'
20+ GOPATH : ${{ github.workspace }}/.go
21+ GOBIN : ${{ github.workspace }}/.go/bin
22+
23+ jobs :
24+ code_quality :
25+ runs-on : ubuntu-latest
26+ steps :
27+ - name : Checkout code
28+ uses : actions/checkout@v4
29+ with :
30+ fetch-depth : 0
31+
32+ - name : Set up Go
33+ uses : actions/setup-go@v5
34+ with :
35+ go-version : ${{ env.GO_VERSION }}
36+ cache : true
37+
38+ - name : Setup GOPATH/PATH
39+ run : |
40+ echo "GOPATH=${GOPATH}" >> "$GITHUB_ENV"
41+ echo "${GOBIN}" >> "$GITHUB_PATH"
42+
43+ - name : Install dependencies
44+ run : make depend
45+
46+ - name : Formatting check (read-only)
47+ run : |
48+ set -eo pipefail
49+ command -v goimports >/dev/null || go install golang.org/x/tools/cmd/goimports@latest
50+ files=$(git ls-files '*.go')
51+ if [ -z "$files" ]; then
52+ echo "No Go files found. Skipping formatting check."
53+ exit 0
54+ fi
55+ CHANGED=$(goimports -l $files)
56+ if [ -n "$CHANGED" ]; then
57+ echo "$CHANGED"
58+ echo "### Formatting issues" >> "$GITHUB_STEP_SUMMARY"
59+ echo "$CHANGED" | sed 's/^/- /' >> "$GITHUB_STEP_SUMMARY"
60+ echo "Please run \`make format\` on your local machine" >> "$GITHUB_STEP_SUMMARY"
61+ exit 1
62+ fi
63+
64+ - name : GolangCI-Lint (no PR annotations)
65+ run : |
66+ set -eo pipefail
67+ command -v golangci-lint >/dev/null || go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2
68+ OUTPUT=$(golangci-lint run --tests=false --out-format=colored-line-number || true)
69+ if [ -n "$OUTPUT" ]; then
70+ echo "$OUTPUT"
71+ echo "### GolangCI-Lint issues" >> "$GITHUB_STEP_SUMMARY"
72+ echo "$OUTPUT" | sed 's/^/- /' >> "$GITHUB_STEP_SUMMARY"
73+ exit 1
74+ fi
0 commit comments