From 29ad6db3bd189e3ff7b3553ef335d6f3eda08555 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 6 Feb 2026 17:13:52 +0800 Subject: [PATCH] ci: validate gofmt, tidy, and generated files before test (#2022) Check - gofmt - go mod tidy - generated files before tests. --- .github/workflows/ci.yml | 32 +++++++++++++++++++++++++++----- cmd/utils/flags.go | 6 +++--- core/tracing/hooks.go | 2 +- go.mod | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be4b301861..6a56560f30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,12 +5,12 @@ on: types: [opened, synchronize, reopened] push: branches: - - '*' + - "*" tags: - - '*' + - "*" env: - GOPROXY: https://proxy.golang.org + GOPROXY: https://proxy.golang.org,direct GO111MODULE: on tf_version: "1.3.0" tf_init_cli_options: "-input=false" @@ -51,11 +51,33 @@ jobs: uses: actions/checkout@v4 with: path: ${{ env.GOPATH }}/src/XDPoSChain + # Cache build tools to avoid downloading them each time + - uses: actions/cache@v4 + with: + path: ${{ env.GOPATH }}/src/XDPoSChain/build/cache + key: ${{ runner.os }}-build-tools-cache-${{ hashFiles('**/build/checksums.txt') }} - name: Set up Go uses: actions/setup-go@v5 with: cache: false - go-version: '1.25.x' + go-version: "1.25.x" + - name: Check gofmt + run: | + unformatted=$(git ls-files '*.go' | xargs -r gofmt -l) + if [ -n "$unformatted" ]; then + echo "Unformatted files:" + echo "$unformatted" + exit 1 + fi + echo "All Go files are properly formatted." + - name: Check go mod tidy + run: | + set -euo pipefail + go mod tidy -diff 2>&1 | sed '/^go: downloading/d' + echo "go.mod and go.sum are tidy." + - name: Validate generated files + run: | + go run build/ci.go generate - name: Run tests run: ${{ matrix.script }} env: @@ -109,7 +131,7 @@ jobs: - name: Set up kubectl uses: azure/setup-kubectl@v4 with: - version: 'v1.19.11' + version: "v1.19.11" - name: Apply new image version to Kubernetes deployments run: | mkdir -p $HOME/.kube diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c3b1a6ffd0..7e4d2d78ce 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -408,9 +408,9 @@ var ( Category: flags.APICategory, } RPCGlobalLogQueryLimit = &cli.IntFlag{ - Name: "rpc-logquerylimit", - Usage: "Maximum number of alternative addresses or topics allowed per search position in eth_getLogs filter criteria (0 = no cap)", - Value: ethconfig.Defaults.LogQueryLimit, + Name: "rpc-logquerylimit", + Usage: "Maximum number of alternative addresses or topics allowed per search position in eth_getLogs filter criteria (0 = no cap)", + Value: ethconfig.Defaults.LogQueryLimit, Category: flags.APICategory, } RPCGlobalRangeLimitFlag = &cli.Uint64Flag{ diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 2bcea0696c..12a436dff1 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -198,7 +198,7 @@ type Hooks struct { // for tracing and reporting. type BalanceChangeReason byte -//go:generate stringer -type=BalanceChangeReason -output gen_balance_change_reason_stringer.go +//go:generate go run golang.org/x/tools/cmd/stringer -type=BalanceChangeReason -output gen_balance_change_reason_stringer.go const ( BalanceChangeUnspecified BalanceChangeReason = 0 diff --git a/go.mod b/go.mod index 044819a52b..eb016ad64f 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,7 @@ require ( require ( github.com/Microsoft/go-winio v0.6.2 + github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260124092617-829590d2c921 github.com/btcsuite/btcd/btcec/v2 v2.2.0 github.com/consensys/gnark-crypto v0.10.0 github.com/deckarep/golang-set/v2 v2.7.0 @@ -64,7 +65,6 @@ require ( ) require ( - github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260124092617-829590d2c921 // indirect github.com/StackExchange/wmi v1.2.1 // indirect github.com/bits-and-blooms/bitset v1.5.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect