Skip to content

Commit

Permalink
Update for building on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Dec 6, 2024
1 parent 23fa18d commit 3686fd6
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ set -eo pipefail

trap 'echo -e "\033[33;5mBuild failed on build.sh:$LINENO\033[0m"' ERR

for arg in "$@"
do
case "$arg" in
--all|-a) LINT=1; TEST=1; RACE=-race ;;
--lint|-l) LINT=1 ;;
--race|-r) TEST=1; RACE=-race ;;
--test|-t) TEST=1 ;;
--help|-h)
echo "$0 [options]"
echo " -a, --all Equivalent to --lint --test --race"
echo " -l, --lint Run the linters"
echo " -r, --race Run the tests with race-checking enabled"
echo " -t, --test Run the tests"
echo " -h, --help This help text"
exit 0
;;
*)
echo "Invalid argument: $arg"
exit 1
;;
esac
for arg in "$@"; do
case "$arg" in
--all | -a)
LINT=1
TEST=1
RACE=-race
;;
--lint | -l)
LINT=1
;;
--race | -r)
TEST=1
RACE=-race
;;
--test | -t)
TEST=1
;;
--help | -h)
echo "$0 [options]"
echo " -a, --all Equivalent to --lint --test --race"
echo " -l, --lint Run the linters"
echo " -r, --race Run the tests with race-checking enabled"
echo " -t, --test Run the tests"
echo " -h, --help This help text"
exit 0
;;
*)
echo "Invalid argument: $arg"
exit 1
;;
esac
done

# Build the code
Expand All @@ -32,25 +42,25 @@ go build -v ./...

# Run the linters
if [ "$LINT"x == "1x" ]; then
GOLANGCI_LINT_VERSION=$(curl --head -s https://github.com/golangci/golangci-lint/releases/latest | grep location: | sed 's/^.*v//' | tr -d '\r\n' )
TOOLS_DIR=$(go env GOPATH)/bin
if [ ! -e "$TOOLS_DIR/golangci-lint" ] || [ "$("$TOOLS_DIR/golangci-lint" version 2>&1 | awk '{ print $4 }' || true)x" != "${GOLANGCI_LINT_VERSION}x" ]; then
echo -e "\033[33mInstalling version $GOLANGCI_LINT_VERSION of golangci-lint into $TOOLS_DIR...\033[0m"
mkdir -p "$TOOLS_DIR"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOLS_DIR" v$GOLANGCI_LINT_VERSION
fi
echo -e "\033[33mLinting...\033[0m"
"$TOOLS_DIR/golangci-lint" run
GOLANGCI_LINT_VERSION=$(curl --head -s https://github.com/golangci/golangci-lint/releases/latest | grep -i location: | sed 's/^.*v//' | tr -d '\r\n')
TOOLS_DIR=$(go env GOPATH)/bin
if [ ! -e "$TOOLS_DIR/golangci-lint" ] || [ "$("$TOOLS_DIR/golangci-lint" version 2>&1 | awk '{ print $4 }' || true)x" != "${GOLANGCI_LINT_VERSION}x" ]; then
echo -e "\033[33mInstalling version $GOLANGCI_LINT_VERSION of golangci-lint into $TOOLS_DIR...\033[0m"
mkdir -p "$TOOLS_DIR"
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$TOOLS_DIR" v$GOLANGCI_LINT_VERSION
fi
echo -e "\033[33mLinting...\033[0m"
"$TOOLS_DIR/golangci-lint" run
fi

# Run the tests
if [ "$TEST"x == "1x" ]; then
if [ -n "$RACE" ]; then
echo -e "\033[33mTesting with -race enabled...\033[0m"
else
echo -e "\033[33mTesting...\033[0m"
fi
go test $RACE ./...
if [ -n "$RACE" ]; then
echo -e "\033[33mTesting with -race enabled...\033[0m"
else
echo -e "\033[33mTesting...\033[0m"
fi
go test $RACE ./...
fi

# Install executables
Expand Down

0 comments on commit 3686fd6

Please sign in to comment.