github.com/google/go-github/v74@v74.0.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="2.2.2"
     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/v2/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      "$BIN"/custom-gcl run --path-prefix "$dir"
    36    ) || fail "failed linting $dir"
    37  done
    38  
    39  if [ -n "$CHECK_GITHUB_OPENAPI" ]; then
    40    echo validating openapi_operations.yaml
    41    script/metadata.sh update-openapi --validate || fail "failed validating openapi_operations.yaml"
    42  fi
    43  
    44  echo validating generated files
    45  script/generate.sh --check || fail "failed validating generated files"
    46  
    47  [ -z "$FAILED" ] || exit 1
    48  
    49  exit "$EXIT_CODE"