diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 66058a88bbed..c427c4fdf11c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -22,6 +22,20 @@ jobs: check-latest: true - uses: technote-space/get-diff-action@v6.1.2 id: git_diff + with: + PATTERNS: | + Makefile + **/Makefile + .golangci.yml + - name: run linting (long) + if: env.GIT_DIFF + id: lint_long + run: | + nix develop -c make lint + env: + NIX: 1 + - uses: technote-space/get-diff-action@v6.1.2 + if: steps.lint_long.outcome == 'skipped' with: PATTERNS: | **/*.go @@ -29,33 +43,11 @@ jobs: go.sum **/go.mod **/go.sum - # with: - # PATTERNS: | - # Makefile - # **/Makefile - # .golangci.yml - - name: run linting (long) - # if: env.GIT_DIFF - # id: lint_long + - name: run linting (short) + if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF run: | nix develop -c make lint env: + GIT_DIFF: ${{ env.GIT_DIFF }} + LINT_DIFF: 1 NIX: 1 - # - uses: technote-space/get-diff-action@v6.1.2 - # if: steps.lint_long.outcome == 'skipped' - # id: git_diff_all - # with: - # PATTERNS: | - # **/*.go - # go.mod - # go.sum - # **/go.mod - # **/go.sum - # - name: run linting (short) - # if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF - # run: | - # nix develop -c make lint - # env: - # GIT_DIFF: ${{ env.GIT_DIFF }} - # LINT_DIFF: 1 - # NIX: 1 diff --git a/scripts/go-lint-all.bash b/scripts/go-lint-all.bash index 2f7ad6b47d0a..601a51df390f 100755 --- a/scripts/go-lint-all.bash +++ b/scripts/go-lint-all.bash @@ -5,16 +5,23 @@ set -e -o pipefail REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" export REPO_ROOT +LINT_TAGS="e2e,ledger,test_ledger_mock" +if [[ ! -z "${NIX:-}" ]]; then + LINT_TAGS+=",rocksdb" +fi +export LINT_TAGS + lint_module() { local root="$1" shift - cd "$(dirname "$root")" && - echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" && - if [[ -z "${NIX:-}" ]]; then - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=e2e,ledger,test_ledger_mock + if [ -f $root ]; then + cd "$(dirname "$root")" else - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=rocksdb,e2e,ledger,test_ledger_mock + cd "$REPO_ROOT/$root" fi + echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS} + # always lint simapp with app_v1 build tag, otherwise it never gets linted if [[ "$(grep "^module" go.mod)" == "module cosmossdk.io/simapp" ]]; then golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1 @@ -24,11 +31,10 @@ export -f lint_module # if LINT_DIFF env is set, only lint the files in the current commit otherwise lint all files if [[ -z "${LINT_DIFF:-}" ]]; then - find "${REPO_ROOT}" -type f -name go.mod -print0 | - xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@" + find "${REPO_ROOT}" -type f -name go.mod -print0 | xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@" else if [[ -z $GIT_DIFF ]]; then - GIT_DIFF=$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$) || true + GIT_DIFF=$(git diff --name-only) || true fi if [[ -z "$GIT_DIFF" ]]; then @@ -36,19 +42,20 @@ else exit 0 fi - for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do - echo "linting $f [$(date -Iseconds -u)]" && - cd $f && - if [[ (-z "${NIX:-}" && $f != store) || $f == "tools/"* ]]; then - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=e2e,ledger,test_ledger_mock - else - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=rocksdb,e2e,ledger,test_ledger_mock - fi + GIT_DIFF=$(echo $GIT_DIFF | tr -d "'" | tr ' ' '\n' | grep '\.go$' | grep -v '\.pb\.go$' | grep -Eo '^[^/]+\/[^/]+' | uniq) - if [[ $f == simapp || $f == simapp/simd/cmd ]]; then - golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1 + lint_sdk=false + for dir in ${GIT_DIFF[@]}; do + if [[ ! -f "$REPO_ROOT/$dir/go.mod" ]]; then + lint_sdk=true + else + lint_module $dir "$@" fi - - cd $REPO_ROOT done -fi + + if [[ $lint_sdk ]]; then + cd "$REPO_ROOT" + echo "linting github.com/cosmos/cosmos-sdk [$(date -Iseconds -u)]" + golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS} + fi +fi \ No newline at end of file diff --git a/x/auth/client/cli/tx_sign.go b/x/auth/client/cli/tx_sign.go index eac15934e29d..6ed9537ccaa7 100644 --- a/x/auth/client/cli/tx_sign.go +++ b/x/auth/client/cli/tx_sign.go @@ -149,7 +149,10 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { // sign the txs from, _ := cmd.Flags().GetString(flags.FlagFrom) - sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey) + err := sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey) + if err != nil { + return err + } sigOnly, _ := cmd.Flags().GetBool(flagSigOnly) json, err := marshalSignatureJSON(txCfg, txBuilder.GetTx(), sigOnly) @@ -170,7 +173,10 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { // sign the txs from, _ := cmd.Flags().GetString(flags.FlagFrom) - sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey) + err = sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey) + if err != nil { + return err + } printSigOnly, _ := cmd.Flags().GetBool(flagSigOnly) json, err := marshalSignatureJSON(txCfg, txBuilder.GetTx(), printSigOnly) @@ -185,7 +191,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error { } } -func sigTxOrMultisig(clientCtx client.Context, txBuilder client.TxBuilder, txFactory tx.Factory, from string, multisigKey string) (err error) { +func sigTxOrMultisig(clientCtx client.Context, txBuilder client.TxBuilder, txFactory tx.Factory, from, multisigKey string) (err error) { if multisigKey == "" { err = sign(clientCtx, txBuilder, txFactory, from) } else { diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 0d2cfdac8786..6750c5dea802 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -19,12 +19,11 @@ import ( // SubmitProposal creates a new proposal given an array of messages func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, expedited bool) (v1.Proposal, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - -// This method checks that all message metadata, summary and title -// has te expected length defined in the module configuration. + // This method checks that all message metadata, summary and title + // has te expected length defined in the module configuration. if err := keeper.validateProposalLengths(metadata, title, summary); err != nil { - return v1.Proposal{}, err + return v1.Proposal{}, err } // Will hold a string slice of all Msg type URLs. diff --git a/x/mint/autocli.go b/x/mint/autocli.go index bb97ea525899..9b096043b5e3 100644 --- a/x/mint/autocli.go +++ b/x/mint/autocli.go @@ -5,6 +5,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" mintv1beta1 "cosmossdk.io/api/cosmos/mint/v1beta1" + "github.com/cosmos/cosmos-sdk/version" ) diff --git a/x/staking/keeper/cons_pubkey.go b/x/staking/keeper/cons_pubkey.go index 6c4a92618481..690fcedbf196 100644 --- a/x/staking/keeper/cons_pubkey.go +++ b/x/staking/keeper/cons_pubkey.go @@ -20,7 +20,6 @@ func (k Keeper) setConsPubKeyRotationHistory( ctx context.Context, valAddr sdk.ValAddress, oldPubKey, newPubKey *codectypes.Any, fee sdk.Coin, ) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) height := uint64(sdkCtx.BlockHeight()) history := types.ConsPubKeyRotationHistory{