bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/build/validate.sh (about)

     1  #!/bin/bash
     2  DIRS=`find . -maxdepth 1 -type d -iregex './[^._].*'`
     3  PKGS=`go list bosun.org/...`
     4  export GO111MODULE=on
     5  
     6  O=bosun-monitor
     7  R=bosun
     8  ORIGINALGOOS=$GOOS
     9  SHA=${TRAVIS_COMMIT}
    10  BUILDMSG=""
    11  
    12  echo -e "\nBuilding/..."
    13  GOBUILDRESULT=0
    14  GBUILDRESULT=0
    15  for GOOS in darwin windows linux ; do
    16  	export GOOS=$GOOS
    17  	export CGO_ENABLED=0
    18  	echo $GOOS
    19  	go build bosun.org/...
    20  	GBUILDRESULT=$?
    21  	if [ "$GBUILDRESULT" != 0 ]; then
    22  		BUILDMSG="${BUILDMSG}Does not build on ${GOOS}. "
    23  		GOBUILDRESULT=$GBUILDRESULT
    24  	fi
    25  done
    26  export GOOS=$ORIGINALGOOS
    27  
    28  echo -e "\nChecking gofmt -s -w for all folders that don't start with . or _"
    29  GOFMTRESULT=0
    30  GOFMTOUT=$(gofmt -l -s -w $DIRS);
    31  if [ "$GOFMTOUT" != '' ]; then
    32      echo "The following files need 'gofmt -s -w':"
    33      echo "$GOFMTOUT"
    34      GOFMTRESULT=1
    35  	BUILDMSG="${BUILDMSG}go fmt -s needed. "
    36  fi
    37  
    38  echo -e "\nRunning go vet bosun.org/..."
    39  go vet $PKGS
    40  GOVETRESULT=$?
    41  if [ "$GOVETRESULT" != 0 ]; then
    42  	BUILDMSG="${BUILDMSG}go vet found problems. "
    43  fi
    44  
    45  echo -e "\nRunning go generate bosun.org/..."
    46  go generate $PKGS
    47  GOGENERATERESULT=$?
    48  GOGENERATEDIFF=$(git diff --exit-code --name-only)
    49  GOGENERATEDIFFRESULT=0
    50  if [ "$GOGENERATEDIFF" != '' ]; then
    51      echo "Go generate needs to be run. The following files have changed:"
    52      echo "$GOGENERATEDIFF"
    53  	BUILDMSG="${BUILDMSG}go generate needs to run. "
    54      GOGENERATEDIFFRESULT=1
    55      git diff
    56  fi
    57  
    58  echo -e "\nRunning go test bosun.org/..."
    59  go test -v $PKGS
    60  GOTESTRESULT=$?
    61  if [ "$GOTESTRESULT" != 0 ]; then
    62  	BUILDMSG="${BUILDMSG}tests fail."
    63  fi
    64  
    65  echo -e "\nTesting that bosun starts and stops cleanly"
    66  #TODO: save linux build from above? cant seem to find where it is though.
    67  cd cmd/bosun
    68  go build .
    69  echo -e 'RuleFilePath = "rule.conf"' > bosun.toml
    70  echo "" > rule.conf
    71  timeout 30 ./bosun & bosunpid=$! #Run bosun in background with a 30s timeout and capture the pid
    72  BOSUN_START_RESULT=$?
    73  sleep 5
    74  kill -SIGTERM $bosunpid
    75  BOSUN_SIGNAL_RESULT=$?
    76  wait $bosunpid
    77  BOSUN_STOP_RESULT=$?
    78  if [ "$BOSUN_START_RESULT" != 0 ]; then
    79      echo "Failed to start bosun cleanly. Exit code $BOSUN_START_RESULT"
    80  fi
    81  if [ "$BOSUN_SIGNAL_RESULT" != 0 ]; then
    82      echo "Failed to signal bosun to stop cleanly. Likely crashed before signal sent."
    83  fi
    84  if [ "$BOSUN_STOP_RESULT" != 1 ]; then
    85      echo "Failed to stop bosun cleanly. Exit code $BOSUN_STOP_RESULT (124=60s test timeout reached)"
    86  else # Expected is 1, so reset to 0 if it worked
    87      BOSUN_STOP_RESULT=0
    88  fi
    89  let "RUN_BOSUN = $BOSUN_START_RESULT | $BOSUN_SIGNAL_RESULT | $BOSUN_STOP_RESULT"
    90  if [ "$RUN_BOSUN" != 0 ]; then
    91      BUILDMSG="${BUILDMSG}clean start/signal/stop failed. "
    92  fi
    93  
    94  BUILDSTATUS=failure
    95  if [ "$BUILDMSG" == '' ]; then
    96  	BUILDMSG="All checks Passed!"
    97  	BUILDSTATUS=success
    98  fi
    99  
   100  let "RESULT = $GOBUILDRESULT | $GOFMTRESULT | $GOVETRESULT | $GOTESTRESULT | $GOGENERATERESULT | $GOGENERATEDIFFRESULT | $RUN_BOSUN"
   101  exit $RESULT