ci: optimize linter script (#18480)
This commit is contained in:
parent
c106c5600b
commit
3853e7ff70
44
.github/workflows/lint.yml
vendored
44
.github/workflows/lint.yml
vendored
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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 {
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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"
|
||||
)
|
||||
|
||||
|
||||
@ -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{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user