-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Move lint logic to its own script.
This separates the logic in run_tests.sh that runs all of the linters on all modules in the repository to a separate lint.sh script and updates run_tests.sh to call that script instead. Rather than listing every linter in the script comments, it refers to the .golangci.yml configuration file that specifies them now that it exists. This allows developers to more easily selectively run only the linters without needing to run all of the tests again. It also cleans up the comments in run_test.sh to match reality while here.
- Loading branch information
Showing
3 changed files
with
39 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/env bash | ||
#!/usr/bin/env bash | ||
|
||
display_usage() { | ||
echo -e "Usage: $0 PATH_TO_REPOSITORY_ROOT\n" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
# The script uses golangci-lint (github.com/golangci/golangci-lint) to run all | ||
# linters defined by the configuration in .golangci.yml on every module in the | ||
# repository. | ||
|
||
go version | ||
|
||
# loop all modules | ||
ROOTPKG=$(go list) | ||
ROOTPKGPATTERN=$(echo $ROOTPKG | sed 's,\\,\\\\,g' | sed 's,/,\\/,g') | ||
MODPATHS=$(go list -m all | grep "^$ROOTPKGPATTERN" | cut -d' ' -f1) | ||
for module in $MODPATHS; do | ||
echo "==> lint ${module}" | ||
|
||
# determine module directory | ||
MODNAME=$(echo $module | sed -E -e "s/^$ROOTPKGPATTERN//" \ | ||
-e 's,^/,,' -e 's,/v[0-9]+$,,') | ||
if [ -z "$MODNAME" ]; then | ||
MODNAME=. | ||
fi | ||
|
||
# run commands in the module directory as a subshell | ||
( | ||
cd $MODNAME | ||
|
||
# run linters | ||
golangci-lint run | ||
) | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters