Skip to content

Commit 4fd43f6

Browse files
authored
Merge pull request #1042 from mohamedawnallah/introduce-fmt-check-workflow
multi: Introduce `fmt-check` to CI workflow
2 parents 62c7089 + 4abc517 commit 4fd43f6

File tree

16 files changed

+179
-115
lines changed

16 files changed

+179
-115
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ env:
2020
# go needs absolute directories, using the $HOME variable doesn't work here.
2121
GOCACHE: /home/runner/work/go/pkg/build
2222
GOPATH: /home/runner/work/go
23+
GOBIN: /home/runner/work/go/bin
2324
GO111MODULE: on
2425

25-
GO_VERSION: 1.22.x
26+
GO_VERSION: 1.23.12
2627
BITCOIND_VERSION: '22.0'
2728
BITCOIND_IMAGE: 'lightninglabs/bitcoin-core'
2829

@@ -44,8 +45,8 @@ jobs:
4445
with:
4546
go-version: '${{ env.GO_VERSION }}'
4647

47-
- name: run format
48-
run: make fmt
48+
- name: Check code format
49+
run: make fmt-check
4950

5051
- name: compile code
5152
run: go install -v ./...

Makefile

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
PKG := github.com/btcsuite/btcwallet
2+
TOOLS_DIR := tools
3+
4+
GOCC ?= go
25

36
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
47
GOACC_PKG := github.com/ory/go-acc
5-
GOIMPORTS_PKG := golang.org/x/tools/cmd/goimports
8+
GOIMPORTS_PKG := github.com/rinchsan/gosimports/cmd/gosimports
9+
10+
GO_BIN := $(shell go env GOBIN)
611

7-
GO_BIN := ${GOPATH}/bin
12+
# If GOBIN is not set, default to GOPATH/bin.
13+
ifeq ($(GO_BIN),)
14+
GO_BIN := $(shell go env GOPATH)/bin
15+
endif
16+
17+
GOIMPORTS_BIN := $(GO_BIN)/gosimports
818
LINT_BIN := $(GO_BIN)/golangci-lint
919
GOACC_BIN := $(GO_BIN)/go-acc
1020

@@ -50,6 +60,10 @@ all: build check
5060
# DEPENDENCIES
5161
# ============
5262

63+
$(GOIMPORTS_BIN):
64+
@$(call print, "Installing goimports.")
65+
cd $(TOOLS_DIR); $(GOCC) install -trimpath $(GOIMPORTS_PKG)
66+
5367
$(LINT_BIN):
5468
@$(call print, "Fetching linter")
5569
$(GOINSTALL) $(LINT_PKG)@$(LINT_VERSION)
@@ -58,11 +72,6 @@ $(GOACC_BIN):
5872
@$(call print, "Fetching go-acc")
5973
$(GOINSTALL) $(GOACC_PKG)@$(GOACC_VERSION)
6074

61-
#? goimports: Install goimports
62-
goimports:
63-
@$(call print, "Installing goimports.")
64-
$(GOINSTALL) $(GOIMPORTS_PKG)@${GOIMPORTS_COMMIT}
65-
6675
# ============
6776
# INSTALLATION
6877
# ============
@@ -72,7 +81,7 @@ build:
7281
@$(call print, "Compiling btcwallet.")
7382
$(GOBUILD) $(PKG)/...
7483

75-
#? install: Install btcwallet, dropwtxmgr and sweepaccount, place them in $GOPATH/bin
84+
#? install: Install btcwallet, dropwtxmgr and sweepaccount, place them in $GOBIN
7685
install:
7786
@$(call print, "Installing btcwallet.")
7887
$(GOINSTALL) $(PKG)
@@ -105,13 +114,18 @@ unit-race:
105114
# UTILITIES
106115
# =========
107116

108-
#? fmt: Fix imports and formatting source
109-
fmt: goimports
117+
#? fmt: Fix imports and format source code
118+
fmt: $(GOIMPORTS_BIN)
110119
@$(call print, "Fixing imports.")
111-
goimports -w $(GOFILES_NOVENDOR)
120+
$(GOIMPORTS_BIN) -w $(GOFILES_NOVENDOR)
112121
@$(call print, "Formatting source.")
113122
gofmt -l -w -s $(GOFILES_NOVENDOR)
114123

124+
#? fmt-check: Make sure source code is formatted and imports are correct
125+
fmt-check: fmt
126+
@$(call print, "Checking fmt results.")
127+
if test -n "$$(git status --porcelain)"; then echo "code not formatted correctly, please run `make fmt` again!"; git status; git diff; exit 1; fi
128+
115129
#? lint: Lint source
116130
lint: $(LINT_BIN)
117131
@$(call print, "Linting source.")
@@ -139,6 +153,7 @@ tidy-module-check: tidy-module
139153
unit-cover \
140154
unit-race \
141155
fmt \
156+
fmt-check \
142157
lint \
143158
clean
144159

internal/legacy/keystore/keystore.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
"sync"
2222
"time"
2323

24-
// consider vendoring this deprecated ripemd160 package
25-
"golang.org/x/crypto/ripemd160" // nolint:staticcheck
26-
2724
"github.com/btcsuite/btcd/btcec/v2"
2825
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
2926
"github.com/btcsuite/btcd/btcutil"
@@ -33,6 +30,7 @@ import (
3330
"github.com/btcsuite/btcd/wire"
3431
"github.com/btcsuite/btcwallet/internal/legacy/rename"
3532
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
33+
"golang.org/x/crypto/ripemd160" //nolint:staticcheck
3634
)
3735

3836
const (

rpc/legacyrpc/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func NewServer(opts *Options, walletLoader *wallet.Loader, listeners []net.Liste
164164
// httpBasicAuth returns the UTF-8 bytes of the HTTP Basic authentication
165165
// string:
166166
//
167-
// "Basic " + base64(username + ":" + password)
167+
// "Basic " + base64(username + ":" + password)
168168
func httpBasicAuth(username, password string) []byte {
169169
const header = "Basic "
170170
base64 := base64.StdEncoding

rpc/rpcserver/log.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import (
1818
"os"
1919
"strings"
2020

21-
"google.golang.org/grpc/grpclog"
22-
2321
"github.com/btcsuite/btclog"
22+
"google.golang.org/grpc/grpclog"
2423
)
2524

2625
// UseLogger sets the logger to use for the gRPC server.

rpc/rpcserver/server.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// Full documentation of the API implemented by this package is maintained in a
99
// language-agnostic document:
1010
//
11-
// https://github.com/btcsuite/btcwallet/blob/master/rpc/documentation/api.md
11+
// https://github.com/btcsuite/btcwallet/blob/master/rpc/documentation/api.md
1212
//
1313
// Any API changes must be performed according to the steps listed here:
1414
//
15-
// https://github.com/btcsuite/btcwallet/blob/master/rpc/documentation/serverchanges.md
15+
// https://github.com/btcsuite/btcwallet/blob/master/rpc/documentation/serverchanges.md
1616
package rpcserver
1717

1818
import (
@@ -21,11 +21,6 @@ import (
2121
"sync"
2222
"time"
2323

24-
"golang.org/x/net/context"
25-
"google.golang.org/grpc"
26-
"google.golang.org/grpc/codes"
27-
"google.golang.org/grpc/status"
28-
2924
"github.com/btcsuite/btcd/btcutil"
3025
"github.com/btcsuite/btcd/btcutil/hdkeychain"
3126
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -40,6 +35,10 @@ import (
4035
"github.com/btcsuite/btcwallet/waddrmgr"
4136
"github.com/btcsuite/btcwallet/wallet"
4237
"github.com/btcsuite/btcwallet/walletdb"
38+
"golang.org/x/net/context"
39+
"google.golang.org/grpc"
40+
"google.golang.org/grpc/codes"
41+
"google.golang.org/grpc/status"
4342
)
4443

4544
// Public API version constants
@@ -486,12 +485,12 @@ func (s *walletServer) SignTransaction(ctx context.Context, req *pb.SignTransact
486485
}
487486

488487
// BUGS:
489-
// - The transaction is not inspected to be relevant before publishing using
490-
// sendrawtransaction, so connection errors to btcd could result in the tx
491-
// never being added to the wallet database.
492-
// - Once the above bug is fixed, wallet will require a way to purge invalid
493-
// transactions from the database when they are rejected by the network, other
494-
// than double spending them.
488+
// - The transaction is not inspected to be relevant before publishing using
489+
// sendrawtransaction, so connection errors to btcd could result in the tx
490+
// never being added to the wallet database.
491+
// - Once the above bug is fixed, wallet will require a way to purge invalid
492+
// transactions from the database when they are rejected by the network, other
493+
// than double spending them.
495494
func (s *walletServer) PublishTransaction(ctx context.Context, req *pb.PublishTransactionRequest) (
496495
*pb.PublishTransactionResponse, error) {
497496

rpc/walletrpc/api.pb.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/btcsuite/btcwallet/tools
2+
3+
go 1.23.12
4+
5+
require github.com/rinchsan/gosimports v0.1.5
6+
7+
require (
8+
golang.org/x/mod v0.5.1 // indirect
9+
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
10+
golang.org/x/tools v0.1.8 // indirect
11+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
12+
)

tools/go.sum

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
github.com/rinchsan/gosimports v0.1.5 h1:Z/l9lS79z0xgKC6fLJYmDdY44D0LFwo3MzaMtWvMKpY=
2+
github.com/rinchsan/gosimports v0.1.5/go.mod h1:102/jU2cwf9fpa/YM9D9o4gSen2Vg8Jl80Sxctgd9N0=
3+
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
4+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
6+
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
7+
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
8+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
9+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
10+
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
11+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
12+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
13+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
14+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
15+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
17+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18+
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 h1:5hpz5aRr+W1erYCL5JRhSUBJRph7l9XkNveoExlrKYk=
19+
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
21+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
22+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
23+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
24+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
25+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
26+
golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w=
27+
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
28+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
29+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
30+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
31+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

tools/tools.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build tools
2+
// +build tools
3+
4+
package wallet
5+
6+
// The other imports represent our build tools. Instead of defining a commit we
7+
// want to use for those golang based tools, we use the go mod versioning system
8+
// to unify the way we manage dependencies. So we define our build tool
9+
// dependencies here and pin the version in go.mod.
10+
import (
11+
_ "github.com/rinchsan/gosimports/cmd/gosimports"
12+
)

0 commit comments

Comments
 (0)