2017-10-10 10:02:39 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
# Runs the linters against dendrite
|
|
|
|
|
|
|
|
# The linters can take a lot of resources and are slow, so they can be
|
2019-06-19 13:05:03 +00:00
|
|
|
# configured using the following environment variables:
|
2017-10-10 10:02:39 +00:00
|
|
|
#
|
|
|
|
# - `DENDRITE_LINT_CONCURRENCY` - number of concurrent linters to run,
|
2019-06-19 13:05:03 +00:00
|
|
|
# golangci-lint defaults this to NumCPU
|
|
|
|
# - `GOGC` - how often to perform garbage collection during golangci-lint runs.
|
2020-12-07 11:23:01 +00:00
|
|
|
# Essentially a ratio of memory/speed. See https://golangci-lint.run/usage/performance/#memory-usage
|
2019-06-19 13:05:03 +00:00
|
|
|
# for more info.
|
2017-10-10 10:02:39 +00:00
|
|
|
|
|
|
|
|
2017-12-12 10:25:38 +00:00
|
|
|
set -eux
|
|
|
|
|
2020-05-21 13:40:13 +00:00
|
|
|
cd `dirname $0`/../..
|
2017-10-10 10:02:39 +00:00
|
|
|
|
|
|
|
args=""
|
|
|
|
if [ ${1:-""} = "fast" ]
|
2019-06-19 13:05:03 +00:00
|
|
|
then args="--fast"
|
2017-10-10 10:02:39 +00:00
|
|
|
fi
|
|
|
|
|
2019-06-19 13:05:03 +00:00
|
|
|
echo "Installing golangci-lint..."
|
2019-07-12 13:23:27 +00:00
|
|
|
|
|
|
|
# Make a backup of go.{mod,sum} first
|
|
|
|
cp go.mod go.mod.bak && cp go.sum go.sum.bak
|
2022-04-29 07:55:35 +00:00
|
|
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
|
2017-10-10 10:02:39 +00:00
|
|
|
|
2019-12-25 18:14:58 +00:00
|
|
|
# Run linting
|
2017-10-10 10:02:39 +00:00
|
|
|
echo "Looking for lint..."
|
2019-12-25 18:14:58 +00:00
|
|
|
|
|
|
|
# Capture exit code to ensure go.{mod,sum} is restored before exiting
|
|
|
|
exit_code=0
|
|
|
|
|
2022-04-29 07:55:35 +00:00
|
|
|
PATH="$PATH:$(go env GOPATH)/bin" golangci-lint run $args || exit_code=1
|
2019-07-12 13:23:27 +00:00
|
|
|
|
|
|
|
# Restore go.{mod,sum}
|
|
|
|
mv go.mod.bak go.mod && mv go.sum.bak go.sum
|
2019-12-25 18:14:58 +00:00
|
|
|
|
|
|
|
exit $exit_code
|