Skip to content

Commit 3853e7f

Browse files
authored
ci: optimize linter script (#18480)
1 parent c106c56 commit 3853e7f

6 files changed

Lines changed: 59 additions & 55 deletions

File tree

.github/workflows/lint.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,32 @@ jobs:
2222
check-latest: true
2323
- uses: technote-space/get-diff-action@v6.1.2
2424
id: git_diff
25+
with:
26+
PATTERNS: |
27+
Makefile
28+
**/Makefile
29+
.golangci.yml
30+
- name: run linting (long)
31+
if: env.GIT_DIFF
32+
id: lint_long
33+
run: |
34+
nix develop -c make lint
35+
env:
36+
NIX: 1
37+
- uses: technote-space/get-diff-action@v6.1.2
38+
if: steps.lint_long.outcome == 'skipped'
2539
with:
2640
PATTERNS: |
2741
**/*.go
2842
go.mod
2943
go.sum
3044
**/go.mod
3145
**/go.sum
32-
# with:
33-
# PATTERNS: |
34-
# Makefile
35-
# **/Makefile
36-
# .golangci.yml
37-
- name: run linting (long)
38-
# if: env.GIT_DIFF
39-
# id: lint_long
46+
- name: run linting (short)
47+
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
4048
run: |
4149
nix develop -c make lint
4250
env:
51+
GIT_DIFF: ${{ env.GIT_DIFF }}
52+
LINT_DIFF: 1
4353
NIX: 1
44-
# - uses: technote-space/get-diff-action@v6.1.2
45-
# if: steps.lint_long.outcome == 'skipped'
46-
# id: git_diff_all
47-
# with:
48-
# PATTERNS: |
49-
# **/*.go
50-
# go.mod
51-
# go.sum
52-
# **/go.mod
53-
# **/go.sum
54-
# - name: run linting (short)
55-
# if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
56-
# run: |
57-
# nix develop -c make lint
58-
# env:
59-
# GIT_DIFF: ${{ env.GIT_DIFF }}
60-
# LINT_DIFF: 1
61-
# NIX: 1

scripts/go-lint-all.bash

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ set -e -o pipefail
55
REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
66
export REPO_ROOT
77

8+
LINT_TAGS="e2e,ledger,test_ledger_mock"
9+
if [[ ! -z "${NIX:-}" ]]; then
10+
LINT_TAGS+=",rocksdb"
11+
fi
12+
export LINT_TAGS
13+
814
lint_module() {
915
local root="$1"
1016
shift
11-
cd "$(dirname "$root")" &&
12-
echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" &&
13-
if [[ -z "${NIX:-}" ]]; then
14-
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=e2e,ledger,test_ledger_mock
17+
if [ -f $root ]; then
18+
cd "$(dirname "$root")"
1519
else
16-
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=rocksdb,e2e,ledger,test_ledger_mock
20+
cd "$REPO_ROOT/$root"
1721
fi
22+
echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]"
23+
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS}
24+
1825
# always lint simapp with app_v1 build tag, otherwise it never gets linted
1926
if [[ "$(grep "^module" go.mod)" == "module cosmossdk.io/simapp" ]]; then
2027
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1
@@ -24,31 +31,31 @@ export -f lint_module
2431

2532
# if LINT_DIFF env is set, only lint the files in the current commit otherwise lint all files
2633
if [[ -z "${LINT_DIFF:-}" ]]; then
27-
find "${REPO_ROOT}" -type f -name go.mod -print0 |
28-
xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@"
34+
find "${REPO_ROOT}" -type f -name go.mod -print0 | xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@"
2935
else
3036
if [[ -z $GIT_DIFF ]]; then
31-
GIT_DIFF=$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$) || true
37+
GIT_DIFF=$(git diff --name-only) || true
3238
fi
3339

3440
if [[ -z "$GIT_DIFF" ]]; then
3541
echo "no files to lint"
3642
exit 0
3743
fi
3844

39-
for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do
40-
echo "linting $f [$(date -Iseconds -u)]" &&
41-
cd $f &&
42-
if [[ (-z "${NIX:-}" && $f != store) || $f == "tools/"* ]]; then
43-
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=e2e,ledger,test_ledger_mock
44-
else
45-
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=rocksdb,e2e,ledger,test_ledger_mock
46-
fi
45+
GIT_DIFF=$(echo $GIT_DIFF | tr -d "'" | tr ' ' '\n' | grep '\.go$' | grep -v '\.pb\.go$' | grep -Eo '^[^/]+\/[^/]+' | uniq)
4746

48-
if [[ $f == simapp || $f == simapp/simd/cmd ]]; then
49-
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=app_v1
47+
lint_sdk=false
48+
for dir in ${GIT_DIFF[@]}; do
49+
if [[ ! -f "$REPO_ROOT/$dir/go.mod" ]]; then
50+
lint_sdk=true
51+
else
52+
lint_module $dir "$@"
5053
fi
51-
52-
cd $REPO_ROOT
5354
done
54-
fi
55+
56+
if [[ $lint_sdk ]]; then
57+
cd "$REPO_ROOT"
58+
echo "linting github.com/cosmos/cosmos-sdk [$(date -Iseconds -u)]"
59+
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS}
60+
fi
61+
fi

x/auth/client/cli/tx_sign.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error {
149149

150150
// sign the txs
151151
from, _ := cmd.Flags().GetString(flags.FlagFrom)
152-
sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey)
152+
err := sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey)
153+
if err != nil {
154+
return err
155+
}
153156

154157
sigOnly, _ := cmd.Flags().GetBool(flagSigOnly)
155158
json, err := marshalSignatureJSON(txCfg, txBuilder.GetTx(), sigOnly)
@@ -170,7 +173,10 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error {
170173

171174
// sign the txs
172175
from, _ := cmd.Flags().GetString(flags.FlagFrom)
173-
sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey)
176+
err = sigTxOrMultisig(clientCtx, txBuilder, txFactory, from, multisigKey)
177+
if err != nil {
178+
return err
179+
}
174180

175181
printSigOnly, _ := cmd.Flags().GetBool(flagSigOnly)
176182
json, err := marshalSignatureJSON(txCfg, txBuilder.GetTx(), printSigOnly)
@@ -185,7 +191,7 @@ func makeSignBatchCmd() func(cmd *cobra.Command, args []string) error {
185191
}
186192
}
187193

188-
func sigTxOrMultisig(clientCtx client.Context, txBuilder client.TxBuilder, txFactory tx.Factory, from string, multisigKey string) (err error) {
194+
func sigTxOrMultisig(clientCtx client.Context, txBuilder client.TxBuilder, txFactory tx.Factory, from, multisigKey string) (err error) {
189195
if multisigKey == "" {
190196
err = sign(clientCtx, txBuilder, txFactory, from)
191197
} else {

x/gov/keeper/proposal.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ import (
1919
// SubmitProposal creates a new proposal given an array of messages
2020
func (keeper Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata, title, summary string, proposer sdk.AccAddress, expedited bool) (v1.Proposal, error) {
2121
sdkCtx := sdk.UnwrapSDKContext(ctx)
22-
2322

24-
// This method checks that all message metadata, summary and title
25-
// has te expected length defined in the module configuration.
23+
// This method checks that all message metadata, summary and title
24+
// has te expected length defined in the module configuration.
2625
if err := keeper.validateProposalLengths(metadata, title, summary); err != nil {
27-
return v1.Proposal{}, err
26+
return v1.Proposal{}, err
2827
}
2928

3029
// Will hold a string slice of all Msg type URLs.

x/mint/autocli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
77
mintv1beta1 "cosmossdk.io/api/cosmos/mint/v1beta1"
8+
89
"github.com/cosmos/cosmos-sdk/version"
910
)
1011

x/staking/keeper/cons_pubkey.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ func (k Keeper) setConsPubKeyRotationHistory(
2020
ctx context.Context, valAddr sdk.ValAddress,
2121
oldPubKey, newPubKey *codectypes.Any, fee sdk.Coin,
2222
) error {
23-
2423
sdkCtx := sdk.UnwrapSDKContext(ctx)
2524
height := uint64(sdkCtx.BlockHeight())
2625
history := types.ConsPubKeyRotationHistory{

0 commit comments

Comments
 (0)