|
40 | 40 | echo "running go linters for $OS_NAME" |
41 | 41 | fi |
42 | 42 |
|
43 | | -# Check gofmt |
44 | | -run_gofmt=true |
45 | | -if [[ "$SKIP_LINTERS" != "" ]]; then |
46 | | - run_gofmt=false |
47 | | -fi |
48 | | -if [[ "$OS_NAME" == "windows" ]]; then |
49 | | - run_gofmt=false |
50 | | -fi |
51 | | -if [[ "$run_gofmt" == "true" ]]; then |
52 | | - set +e |
53 | | - code=0 |
54 | | - for file in "${GOFILES[@]}" |
55 | | - do |
56 | | - # Go 1.17 introduced a migration with build constraints |
57 | | - # and they offer a migration with gofmt |
58 | | - # See https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md#transition for more details |
59 | | - if [[ "$file" == "./pkged.go" ]]; |
60 | | - then |
61 | | - gofmt -s -w pkged.go |
62 | | - fi |
63 | | - |
64 | | - # Check the file's formatting |
65 | | - test -z $(gofmt -s -l $file) |
66 | | - if [[ $? != 0 ]]; |
67 | | - then |
68 | | - echo "DEBUG: formatting $file with gofmt" |
69 | | - |
70 | | - test -z $(gofmt -s -w $file) |
71 | | - if [[ $? != 0 ]]; |
72 | | - then |
73 | | - echo "ERROR: problem rewriting $file" |
74 | | - exit 1; |
75 | | - fi |
76 | | - fi |
77 | | - done |
78 | | - set -e |
79 | | - if [[ $code != 0 ]]; |
80 | | - then |
81 | | - exit $code |
82 | | - fi |
83 | | - |
84 | | - echo "finished gofmt check" |
| 43 | +# ONLY_GOLANGCI=yes skips all checks except golangci-lint (and its --fix via GOLANGCI_DO_FIX=true) |
| 44 | +if [[ "$ONLY_GOLANGCI" == "yes" ]]; then |
| 45 | + DISABLE_GITLEAKS=yes |
| 46 | + DISABLE_GOVULNCHECK=yes |
| 47 | + EXPERIMENTAL="" |
| 48 | + SKIP_TESTS=yes |
85 | 49 | fi |
86 | 50 |
|
87 | 51 | # Would be set to 'moov-io' or 'moovfinancial' |
88 | 52 | org=$(go mod why | head -n1 | awk -F'/' '{print $2}') |
89 | 53 |
|
90 | 54 | # Reject moovfinancial dependencies in moov-io projects |
91 | | -if [[ "$org" == "moov-io" ]]; |
| 55 | +if [[ "$ONLY_GOLANGCI" != "yes" && "$org" == "moov-io" ]]; |
92 | 56 | then |
93 | 57 | # Fail our build if we find moovfinancial dependencies |
94 | 58 | if go list -m all | grep moovfinancial; |
|
115 | 79 | fi |
116 | 80 |
|
117 | 81 | # Verify no retracted module versions are in the build |
| 82 | +if [[ "$ONLY_GOLANGCI" == "yes" ]]; then |
| 83 | + retracted_mods=() |
| 84 | +else |
118 | 85 | retracted_mods=($(go list -m -u all | grep retracted | cut -f1 -d' ')) |
119 | 86 | skip_modules=( |
120 | 87 | "github.com/moby/sys/user" |
|
145 | 112 | fi |
146 | 113 | fi |
147 | 114 | done |
| 115 | +fi |
148 | 116 |
|
149 | 117 | # Build the source code (to discover compile errors prior to linting) |
150 | | -if [[ "$SKIP_LINTERS" == "" ]]; then |
| 118 | +if [[ "$SKIP_LINTERS" == "" && "$ONLY_GOLANGCI" != "yes" ]]; then |
151 | 119 | echo "Building Go source code" |
152 | 120 | go build $GORACE $GOTAGS $GOBUILD_FLAGS ./... |
153 | 121 | echo "SUCCESS: Go code built without errors" |
@@ -421,6 +389,12 @@ version: "2" |
421 | 389 | run: |
422 | 390 | tests: false |
423 | 391 | go: "$GO_VERSION" |
| 392 | +formatters: |
| 393 | + enable: |
| 394 | + - gofmt |
| 395 | + settings: |
| 396 | + gofmt: |
| 397 | + simplify: true |
424 | 398 | linters: |
425 | 399 | default: none |
426 | 400 | settings: |
@@ -461,19 +435,14 @@ EOF |
461 | 435 | echo " - pattern: ^fmt\.Print.*$" >> "$configFilepath" |
462 | 436 | fi |
463 | 437 |
|
464 | | - cat <<EOF >> "$configFilepath" |
465 | | - enable: |
466 | | - - $(echo $enabled | sed 's/,/\n - /g') |
467 | | - disable: |
468 | | - - depguard |
469 | | - - errcheck |
470 | | -EOF |
471 | | - if [[ "$DISABLED_GOLANGCI_LINTERS" != "" ]]; |
472 | | - then |
473 | | - cat <<EOF >> "$configFilepath" |
474 | | - - $(echo "$DISABLED_GOLANGCI_LINTERS" | sed 's/,/\n - /g') |
475 | | -EOF |
| 438 | + # Build --enable and --disable flags from env vars rather than config |
| 439 | + GOLANGCI_ENABLE_FLAG="--enable=$enabled" |
| 440 | + |
| 441 | + disabled="depguard,errcheck" |
| 442 | + if [[ "$DISABLED_GOLANGCI_LINTERS" != "" ]]; then |
| 443 | + disabled="$disabled,$DISABLED_GOLANGCI_LINTERS" |
476 | 444 | fi |
| 445 | + GOLANGCI_DISABLE_FLAG="--disable=$disabled" |
477 | 446 |
|
478 | 447 | cat <<EOF >> "$configFilepath" |
479 | 448 | exclusions: |
|
509 | 478 | if [[ "$GOLANGCI_DO_FIX" == "true" ]]; then |
510 | 479 | GOLANGCI_FIX_FLAG="--fix" |
511 | 480 | fi |
512 | | - ./bin/golangci-lint $GOLANGCI_FLAGS run --config="$configFilepath" $GOLANGCI_FIX_FLAG --verbose --timeout=5m $GOLANGCI_TAGS |
| 481 | + ./bin/golangci-lint $GOLANGCI_FLAGS run --config="$configFilepath" $GOLANGCI_FIX_FLAG $GOLANGCI_ENABLE_FLAG $GOLANGCI_DISABLE_FLAG --verbose --timeout=5m $GOLANGCI_TAGS |
513 | 482 |
|
514 | 483 | echo "FINISHED golangci-lint checks" |
515 | 484 |
|
|
0 commit comments