github.com/google/go-github/v69@v69.2.0/script/lint.sh (about) 1 #!/bin/sh 2 #/ [ CHECK_GITHUB_OPENAPI=1 ] script/lint.sh runs linters and validates generated files. 3 #/ When CHECK_GITHUB is set, it validates that openapi_operations.yaml is consistent with the 4 #/ descriptions from github.com/github/rest-api-description. 5 6 set -e 7 8 GOLANGCI_LINT_VERSION="1.63.4" 9 10 CDPATH="" cd -- "$(dirname -- "$0")/.." 11 BIN="$(pwd -P)"/bin 12 13 mkdir -p "$BIN" 14 15 EXIT_CODE=0 16 17 fail() { 18 echo "$@" 19 EXIT_CODE=1 20 } 21 22 # install golangci-lint and custom-gcl in ./bin if they don't exist with the correct version 23 if ! "$BIN"/custom-gcl --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then 24 GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" 25 "$BIN"/golangci-lint custom && mv ./custom-gcl "$BIN" 26 fi 27 28 MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)" 29 30 for dir in $MOD_DIRS; do 31 [ "$dir" = "example/newreposecretwithlibsodium" ] && continue 32 echo linting "$dir" 33 ( 34 cd "$dir" 35 # github actions output when running in an action 36 if [ -n "$GITHUB_ACTIONS" ]; then 37 "$BIN"/custom-gcl run --path-prefix "$dir" --out-format colored-line-number 38 else 39 "$BIN"/custom-gcl run --path-prefix "$dir" 40 fi 41 ) || fail "failed linting $dir" 42 done 43 44 if [ -n "$CHECK_GITHUB_OPENAPI" ]; then 45 echo validating openapi_operations.yaml 46 script/metadata.sh update-openapi --validate || fail "failed validating openapi_operations.yaml" 47 fi 48 49 echo validating generated files 50 script/generate.sh --check || fail "failed validating generated files" 51 52 [ -z "$FAILED" ] || exit 1 53 54 exit "$EXIT_CODE"