From 3686fd6ece549ba1e5b0ed35ff38a37cfce20e63 Mon Sep 17 00:00:00 2001 From: Richard Wilkes Date: Fri, 6 Dec 2024 13:07:12 -0800 Subject: [PATCH] Update for building on Windows --- build.sh | 82 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/build.sh b/build.sh index ff15f37..31875ac 100755 --- a/build.sh +++ b/build.sh @@ -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 @@ -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