ci: lint only new changes (#23710)
This commit is contained in:
parent
b4bae1a55c
commit
8be3016158
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
if: env.GIT_DIFF
|
||||
id: lint_long
|
||||
run: |
|
||||
make lint
|
||||
make lint-changes
|
||||
- uses: technote-space/get-diff-action@v6.1.2
|
||||
if: steps.lint_long.outcome == 'skipped'
|
||||
with:
|
||||
@ -41,7 +41,7 @@ jobs:
|
||||
- name: run linting (short)
|
||||
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
|
||||
run: |
|
||||
make lint
|
||||
make lint-changes
|
||||
env:
|
||||
GIT_DIFF: ${{ env.GIT_DIFF }}
|
||||
LINT_DIFF: 1
|
||||
|
||||
5
Makefile
5
Makefile
@ -383,6 +383,11 @@ lint:
|
||||
$(MAKE) lint-install
|
||||
@./scripts/go-lint-all.bash --timeout=15m
|
||||
|
||||
lint-changes:
|
||||
@echo "--> Running linter"
|
||||
$(MAKE) lint-install
|
||||
@./scripts/go-lint-changes.bash --timeout=15m
|
||||
|
||||
lint-fix:
|
||||
@echo "--> Running linter"
|
||||
$(MAKE) lint-install
|
||||
|
||||
@ -10,7 +10,7 @@ lint_module() {
|
||||
shift
|
||||
cd "$(dirname "$root")" &&
|
||||
echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" &&
|
||||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@"
|
||||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --new-from-rev=HEAD~
|
||||
}
|
||||
export -f lint_module
|
||||
|
||||
@ -31,7 +31,7 @@ else
|
||||
for f in $(dirname $(echo "$GIT_DIFF" | tr -d "'") | uniq); do
|
||||
echo "linting $f [$(date -Iseconds -u)]" &&
|
||||
cd $f &&
|
||||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" &&
|
||||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --new-from-rev=HEAD~ &&
|
||||
cd $REPO_ROOT
|
||||
done
|
||||
fi
|
||||
37
scripts/go-lint-changes.bash
Executable file
37
scripts/go-lint-changes.bash
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e -o pipefail
|
||||
|
||||
REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )"
|
||||
export REPO_ROOT
|
||||
|
||||
lint_module() {
|
||||
local root="$1"
|
||||
shift
|
||||
cd "$(dirname "$root")" &&
|
||||
echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" &&
|
||||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --new-from-rev=HEAD~
|
||||
}
|
||||
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 "$@"' _ {} "$@"
|
||||
else
|
||||
if [[ -z $GIT_DIFF ]]; then
|
||||
GIT_DIFF=$(git diff --name-only --diff-filter=d | grep \.go$ | grep -v \.pb\.go$) || 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 &&
|
||||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --new-from-rev=HEAD~ &&
|
||||
cd $REPO_ROOT
|
||||
done
|
||||
fi
|
||||
@ -6,7 +6,7 @@ toolchain go1.24.0
|
||||
|
||||
require (
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
|
||||
github.com/cosmos/cosmos-sdk v0.50.11
|
||||
github.com/cosmos/cosmos-sdk v0.50.11 // indirect
|
||||
github.com/cosmos/gogogateway v1.2.0 // indirect
|
||||
github.com/cosmos/gogoproto v1.7.0 // indirect
|
||||
github.com/cosmos/iavl v1.2.2 // indirect
|
||||
@ -61,7 +61,7 @@ require (
|
||||
github.com/cockroachdb/pebble v1.1.2 // indirect
|
||||
github.com/cockroachdb/redact v1.1.5 // indirect
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/cometbft/cometbft v0.38.15 // indirect
|
||||
github.com/cometbft/cometbft v0.38.17 // indirect
|
||||
github.com/cometbft/cometbft-db v0.14.1 // indirect
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1 // indirect
|
||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||
|
||||
@ -135,8 +135,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/cometbft/cometbft v0.38.15 h1:5veFd8k1uXM27PBg9sMO3hAfRJ3vbh4OmmLf6cVrqXg=
|
||||
github.com/cometbft/cometbft v0.38.15/go.mod h1:+wh6ap6xctVG+JOHwbl8pPKZ0GeqdPYqISu7F4b43cQ=
|
||||
github.com/cometbft/cometbft v0.38.17 h1:FkrQNbAjiFqXydeAO81FUzriL4Bz0abYxN/eOHrQGOk=
|
||||
github.com/cometbft/cometbft v0.38.17/go.mod h1:5l0SkgeLRXi6bBfQuevXjKqML1jjfJJlvI1Ulp02/o4=
|
||||
github.com/cometbft/cometbft-db v0.14.1 h1:SxoamPghqICBAIcGpleHbmoPqy+crij/++eZz3DlerQ=
|
||||
github.com/cometbft/cometbft-db v0.14.1/go.mod h1:KHP1YghilyGV/xjD5DP3+2hyigWx0WTp9X+0Gnx0RxQ=
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1 h1:GtdXwDGlqwHYs16A4egjwylfYOMYyEacLBrs3Zvpt7g=
|
||||
|
||||
Loading…
Reference in New Issue
Block a user