github.com/mutagen-io/mutagen@v0.18.0-rc1/scripts/ci/analyze.sh (about)

     1  #!/bin/bash
     2  
     3  # We want all commands to run, but we want to fail the script if any of them
     4  # fail, so we track the exit status of each command instead of using set -e.
     5  FAILURE=0
     6  
     7  # Verify that code is formatted and simplified according to Go standards. We
     8  # skip this check on Windows due to gofmt normalizing Go code to LF endings (and
     9  # thus generating an enormous and pointless diff).
    10  if [[ "$(go env GOOS)" != "windows" ]]; then
    11      gofmt -s -l -d . | tee gofmt.log
    12      if [[ -s gofmt.log ]]; then
    13          echo "Code is not go fmt'd" 1>&2
    14          FAILURE=1
    15      fi
    16      rm gofmt.log
    17  fi
    18  
    19  # Ensure that a go mod tidy operation doesn't change go.mod or go.sum. We skip
    20  # this check on Windows due to go mod tidy normalizing module files to LF
    21  # endings (and thus triggering a false positive).
    22  if [[ "$(go env GOOS)" != "windows" ]]; then
    23      PRE_TIDY_GO_MOD_SUM=$(cat go.mod | openssl dgst -sha256)
    24      PRE_TIDY_GO_SUM_SUM=$(cat go.sum | openssl dgst -sha256)
    25      go mod tidy || FAILURE=1
    26      POST_TIDY_GO_MOD_SUM=$(cat go.mod | openssl dgst -sha256)
    27      POST_TIDY_GO_SUM_SUM=$(cat go.sum | openssl dgst -sha256)
    28      if [[ "${POST_TIDY_GO_MOD_SUM}" != "${PRE_TIDY_GO_MOD_SUM}" ]]; then
    29          echo "go.mod changed with go mod tidy operation" 1>&2
    30          FAILURE=1
    31      fi
    32      if [[ "${POST_TIDY_GO_SUM_SUM}" != "${PRE_TIDY_GO_SUM_SUM}" ]]; then
    33          echo "go.sum changed with go mod tidy operation" 1>&2
    34          FAILURE=1
    35      fi
    36  fi
    37  
    38  # Perform static analysis.
    39  VETFLAGS="-composites=false"
    40  go vet ${VETFLAGS} ./pkg/... || FAILURE=1
    41  go vet ${VETFLAGS} ./cmd/... || FAILURE=1
    42  go vet ${VETFLAGS} ./scripts/... || FAILURE=1
    43  go vet ${VETFLAGS} ./tools/... || FAILURE=1
    44  
    45  # Perform static analysis on SSPL code.
    46  go vet -tags mutagensspl ./sspl/... || FAILURE=1
    47  
    48  # TODO: Add spell checking. The https://github.com/client9/misspell tool is what
    49  # we've used historically (via Go Report Card), but it seems like it's no longer
    50  # maintained and it's installation is a little non-trivial.
    51  
    52  # TODO: Add custom code/comment structure validation.
    53  
    54  # Done.
    55  exit $FAILURE