github.com/boyter/gocodewalker@v1.3.2/check.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # SPDX-License-Identifier: MIT OR Unlicense
     4  
     5  set -e
     6  
     7  if [ -t 1 ]
     8  then
     9    YELLOW='\033[0;33m'
    10    GREEN='\033[0;32m'
    11    RED='\033[0;31m'
    12    NC='\033[0m'
    13  fi
    14  
    15  yellow() { printf "${YELLOW}%s${NC}" "$*"; }
    16  green() { printf "${GREEN}%s${NC}" "$*"; }
    17  red() { printf "${RED}%s${NC}" "$*"; }
    18  
    19  good() {
    20    echo "$(green "● success:")" "$@"
    21  }
    22  
    23  bad() {
    24    ret=$1
    25    shift
    26    echo "$(red "● failed:")" "$@"
    27    exit $ret
    28  }
    29  
    30  try() {
    31    "$@" || bad $? "$@" && good "$@"
    32  }
    33  
    34  
    35  echo "Running go fmt..."
    36  gofmt -s -w ./..
    37  
    38  echo "Running unit tests..."
    39  go test -cover -race ./... || exit
    40  
    41  {
    42    {
    43      opt='shopt -s extglob nullglob'
    44      gofmt='gofmt -s -w -l !(vendor)/ *.go'
    45      notice="    running: ( $opt; $gofmt; )"
    46      prefix="    $(yellow modified)"
    47      trap 'echo "$notice"; $opt; $gofmt | sed -e "s#^#$prefix #g"' EXIT
    48    }
    49  
    50    # comma separate linters (e.g. "gofmt,stylecheck")
    51    additional_linters="gofmt"
    52    try golangci-lint run --enable $additional_linters ./...
    53    trap '' EXIT
    54  }
    55  
    56  echo "Running fuzz tests..."
    57  go test -fuzz=FuzzTestGitIgnore -fuzztime 30s
    58  
    59  echo -e "${GREEN}================================================="
    60  echo -e "ALL CHECKS PASSED"
    61  echo -e "=================================================${NC}"