github.com/google/go-github/v66@v66.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="1.61.0"
     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 bin/golangci-lint doesn't exist with the correct version
    23  if ! "$BIN"/golangci-lint --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  fi
    26  
    27  MOD_DIRS="$(git ls-files '*go.mod' | xargs dirname | sort)"
    28  
    29  for dir in $MOD_DIRS; do
    30    [ "$dir" = "example/newreposecretwithlibsodium" ] && continue
    31    echo linting "$dir"
    32    (
    33      cd "$dir"
    34      # github actions output when running in an action
    35      if [ -n "$GITHUB_ACTIONS" ]; then
    36        "$BIN"/golangci-lint run --path-prefix "$dir" --out-format colored-line-number
    37      else
    38        "$BIN"/golangci-lint run --path-prefix "$dir"
    39      fi
    40    ) || fail "failed linting $dir"
    41  done
    42  
    43  if [ -n "$CHECK_GITHUB_OPENAPI" ]; then
    44    echo validating openapi_operations.yaml
    45    script/metadata.sh update-openapi --validate || fail "failed validating openapi_operations.yaml"
    46  fi
    47  
    48  echo validating generated files
    49  script/generate.sh --check || fail "failed validating generated files"
    50  
    51  [ -z "$FAILED" ] || exit 1
    52  
    53  exit "$EXIT_CODE"