Skip to content

Commit

Permalink
ci: optimize linter script (#18480)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Nov 16, 2023
1 parent c106c56 commit 3853e7f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 55 deletions.
44 changes: 18 additions & 26 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,32 @@ 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
go.mod
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
49 changes: 28 additions & 21 deletions scripts/go-lint-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,31 +31,31 @@ 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
echo "no files to lint"
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
12 changes: 9 additions & 3 deletions x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions x/mint/autocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
1 change: 0 additions & 1 deletion x/staking/keeper/cons_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 3853e7f

Please sign in to comment.