diff --git a/.github/scripts/go-imports.sh b/.github/scripts/go-imports.sh new file mode 100755 index 00000000000..bc5e6db3f86 --- /dev/null +++ b/.github/scripts/go-imports.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +formatted_files="$(docker run -v "$(pwd)":/ibc-go --rm -w "/ibc-go" --entrypoint="" cytopia/goimports goimports -l -local 'github.com/cosmos/ibc-go' /ibc-go)" + +exit_code=0 +for f in $formatted_files +do + # we don't care about formatting in pb.go files. + if [ "${f: -5}" == "pb.go" ]; then + continue + fi + exit_code=1 + echo "formatted file ${f}..." +done + +if [ "${exit_code}" == 1 ]; then + echo "not all files were correctly formated, run the following:" + echo "make goimports" +fi + +exit $exit_code diff --git a/.github/workflows/goimports.yaml b/.github/workflows/goimports.yaml new file mode 100644 index 00000000000..b951b17aa1d --- /dev/null +++ b/.github/workflows/goimports.yaml @@ -0,0 +1,9 @@ +name: Goimports +on: pull_request +jobs: + goimports: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: "Go Imports" + run: .github/scripts/go-imports.sh diff --git a/Makefile b/Makefile index df259c5a477..e14171fcec9 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ PACKAGES_NOSIMULATION=$(shell go list ./... | grep -v '/simulation') PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') +CHANGED_GO_FILES := $(shell git diff --name-only | grep .go$$ | grep -v pb.go) +ALL_GO_FILES := $(shell find . -regex ".*\.go$$" | grep -v pb.go) VERSION := $(shell echo $(shell git describe --always) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true @@ -351,6 +353,12 @@ format: find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./client/docs/statik/statik.go" -not -path "./tests/mocks/*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk .PHONY: format +goimports: + $(DOCKER) run -v $(CURDIR):/ibc-go --rm -w "/ibc-go" cytopia/goimports -w -local 'github.com/cosmos/ibc-go' "$(CHANGED_GO_FILES)" &> /dev/null || echo "No changed go files to format" + +goimports-all: + $(DOCKER) run -v $(CURDIR):/ibc-go --rm -w "/ibc-go" cytopia/goimports -w -local 'github.com/cosmos/ibc-go' "$(ALL_GO_FILES)" + ############################################################################### ### Devdoc ### ############################################################################### diff --git a/modules/apps/29-fee/client/cli/query.go b/modules/apps/29-fee/client/cli/query.go index bb6ef67a5d8..815eec4d35b 100644 --- a/modules/apps/29-fee/client/cli/query.go +++ b/modules/apps/29-fee/client/cli/query.go @@ -8,9 +8,10 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" + "github.com/spf13/cobra" + "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" - "github.com/spf13/cobra" ) // GetCmdIncentivizedPacket returns the unrelayed incentivized packet for a given packetID diff --git a/modules/apps/29-fee/keeper/msg_server_test.go b/modules/apps/29-fee/keeper/msg_server_test.go index 73c7caadc9c..e0c84d62c9b 100644 --- a/modules/apps/29-fee/keeper/msg_server_test.go +++ b/modules/apps/29-fee/keeper/msg_server_test.go @@ -3,7 +3,7 @@ package keeper_test import ( sdk "github.com/cosmos/cosmos-sdk/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - + "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 7fb564f0d9d..9e6abfd358b 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported" ) diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index bf12f95784b..93573e354a8 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -4,6 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v4/testing" diff --git a/modules/core/keeper/keeper_test.go b/modules/core/keeper/keeper_test.go index ef00da59032..ec808bdc0e0 100644 --- a/modules/core/keeper/keeper_test.go +++ b/modules/core/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types" ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" diff --git a/testing/chain_test.go b/testing/chain_test.go index 595609ce4ac..5edb189c2f8 100644 --- a/testing/chain_test.go +++ b/testing/chain_test.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/types" + ibctesting "github.com/cosmos/ibc-go/v4/testing" ) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 744e8c96b01..312de2eb624 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -80,6 +80,7 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts" icacontroller "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller" icacontrollerkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/keeper" @@ -102,7 +103,7 @@ import ( ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" ibcmock "github.com/cosmos/ibc-go/v4/testing/mock" - simappparams "github.com/cosmos/ibc-go/v4/testing/simapp/params" + simappparams "github.com/cosmos/ibc-go/v4/testing/simapp/params" authz "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" @@ -164,7 +165,7 @@ var ( ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, ibcfeetypes.ModuleName: nil, icatypes.ModuleName: nil, - ibcmock.ModuleName: nil, + ibcmock.ModuleName: nil, } )