github.com/richardwilkes/toolbox@v1.121.0/build.sh (about) 1 #! /usr/bin/env bash 2 set -eo pipefail 3 4 trap 'echo -e "\033[33;5mBuild failed on build.sh:$LINENO\033[0m"' ERR 5 6 for arg in "$@" 7 do 8 case "$arg" in 9 --all|-a) LINT=1; TEST=1; RACE=-race ;; 10 --lint|-l) LINT=1 ;; 11 --race|-r) TEST=1; RACE=-race ;; 12 --test|-t) TEST=1 ;; 13 --help|-h) 14 echo "$0 [options]" 15 echo " -a, --all Equivalent to --lint --test --race" 16 echo " -l, --lint Run the linters" 17 echo " -r, --race Run the tests with race-checking enabled" 18 echo " -t, --test Run the tests" 19 echo " -h, --help This help text" 20 exit 0 21 ;; 22 *) 23 echo "Invalid argument: $arg" 24 exit 1 25 ;; 26 esac 27 done 28 29 # Build the code 30 echo -e "\033[33mBuilding...\033[0m" 31 go build -v ./... 32 33 # Run the linters 34 if [ "$LINT"x == "1x" ]; then 35 GOLANGCI_LINT_VERSION=$(curl --head -s https://github.com/golangci/golangci-lint/releases/latest | grep location: | sed 's/^.*v//' | tr -d '\r\n' ) 36 TOOLS_DIR=$(go env GOPATH)/bin 37 if [ ! -e "$TOOLS_DIR/golangci-lint" ] || [ "$("$TOOLS_DIR/golangci-lint" version 2>&1 | awk '{ print $4 }' || true)x" != "${GOLANGCI_LINT_VERSION}x" ]; then 38 echo -e "\033[33mInstalling version $GOLANGCI_LINT_VERSION of golangci-lint into $TOOLS_DIR...\033[0m" 39 mkdir -p "$TOOLS_DIR" 40 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOLS_DIR" v$GOLANGCI_LINT_VERSION 41 fi 42 echo -e "\033[33mLinting...\033[0m" 43 "$TOOLS_DIR/golangci-lint" run 44 fi 45 46 # Run the tests 47 if [ "$TEST"x == "1x" ]; then 48 if [ -n "$RACE" ]; then 49 echo -e "\033[33mTesting with -race enabled...\033[0m" 50 else 51 echo -e "\033[33mTesting...\033[0m" 52 fi 53 go test $RACE ./... 54 fi 55 56 # Install executables 57 echo -e "\033[33mInstalling executables...\033[0m" 58 go install -v ./i18n/i18n