build: run tests natively on ARM, Mac, and Windows in CI (#111)
This commit is contained in:
@ -1,67 +1,121 @@
|
|||||||
version: "2.1"
|
version: "2.1"
|
||||||
|
|
||||||
|
executors:
|
||||||
|
linux-amd64:
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202104-01
|
||||||
|
|
||||||
|
linux-arm64:
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202104-01
|
||||||
|
resource_class: arm.medium
|
||||||
|
|
||||||
|
mac:
|
||||||
|
macos:
|
||||||
|
xcode: 12.4.0
|
||||||
|
resource_class: medium
|
||||||
|
shell: /bin/bash -eo pipefail
|
||||||
|
|
||||||
|
windows:
|
||||||
|
machine:
|
||||||
|
image: windows-server-2019-vs2019:stable
|
||||||
|
resource_class: windows.medium
|
||||||
|
shell: bash.exe -eo pipefail
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
build:
|
build-and-test:
|
||||||
jobs:
|
jobs:
|
||||||
- lint
|
- lint
|
||||||
- check-openapi
|
- check-openapi
|
||||||
- build
|
- build-all
|
||||||
- test
|
- test:
|
||||||
|
matrix:
|
||||||
|
parameters:
|
||||||
|
executor:
|
||||||
|
- linux-amd64
|
||||||
|
- linux-arm64
|
||||||
|
- mac
|
||||||
|
- windows
|
||||||
|
|
||||||
|
commands:
|
||||||
|
setup:
|
||||||
|
steps:
|
||||||
|
- run:
|
||||||
|
name: Install system dependencies
|
||||||
|
command: ./scripts/ci/setup-system.sh
|
||||||
|
- run:
|
||||||
|
name: Install Go
|
||||||
|
command: |
|
||||||
|
./scripts/ci/install-go.sh ${HOME}/.tools
|
||||||
|
echo 'export PATH=${HOME}/.tools/go/bin:${PATH}' >> $BASH_ENV
|
||||||
|
- run:
|
||||||
|
name: Set GOPATH and GOCACHE
|
||||||
|
command: |
|
||||||
|
GOPATH=${HOME}/go
|
||||||
|
echo "export GOPATH=${GOPATH}" >> $BASH_ENV
|
||||||
|
mkdir -p ${GOPATH}/bin
|
||||||
|
echo 'export PATH=${GOPATH}/bin:${PATH}' >> $BASH_ENV
|
||||||
|
mkdir -p ${HOME}/.cache
|
||||||
|
echo 'export GOCACHE=${HOME}/.cache' >> $BASH_ENV
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
docker:
|
executor: linux-amd64
|
||||||
- image: cimg/go:1.16.3
|
|
||||||
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
- setup
|
||||||
- run: make vet
|
- run: make vet
|
||||||
- run: make checkfmt
|
- run: make checkfmt
|
||||||
- run: make checktidy
|
- run: make checktidy
|
||||||
- run: make staticcheck
|
- run: make staticcheck
|
||||||
|
|
||||||
check-openapi:
|
check-openapi:
|
||||||
machine: true
|
executor: linux-amd64
|
||||||
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
- setup
|
||||||
- run:
|
- run:
|
||||||
name: Init openapi submodule
|
name: Init openapi submodule
|
||||||
command: git submodule update --init --recursive
|
command: git submodule update --init --recursive
|
||||||
- run:
|
|
||||||
name: Upgrade Go
|
|
||||||
command: |
|
|
||||||
wget https://golang.org/dl/go1.16.3.linux-amd64.tar.gz
|
|
||||||
tar -C ${HOME} -xzf go1.16.3.linux-amd64.tar.gz
|
|
||||||
echo 'export PATH=${HOME}/go/bin:${PATH}' >> $BASH_ENV
|
|
||||||
- run: make checkopenapi
|
- run: make checkopenapi
|
||||||
|
|
||||||
build:
|
build-all:
|
||||||
docker:
|
executor: linux-amd64
|
||||||
- image: cimg/go:1.16.3
|
|
||||||
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
- setup
|
||||||
- run: make crossbuild
|
- run: make crossbuild
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: dist
|
path: dist
|
||||||
|
|
||||||
test:
|
test:
|
||||||
docker:
|
parameters:
|
||||||
- image: cimg/go:1.16.3
|
executor:
|
||||||
working_directory: /home/circleci/go/src/github.com/influxdata/influx-cli
|
type: executor
|
||||||
|
executor: << parameters.executor >>
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
|
- setup
|
||||||
|
- run:
|
||||||
|
name: Download gotestsum
|
||||||
|
command: |
|
||||||
|
GOTESTSUM_VERSION=1.6.4
|
||||||
|
GOTESTSUM_ARCHIVE=gotestsum_${GOTESTSUM_VERSION}_$(go env GOOS)_$(go env GOARCH).tar.gz
|
||||||
|
GOTESTSUM_URL=https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/${GOTESTSUM_ARCHIVE}
|
||||||
|
|
||||||
|
wget ${GOTESTSUM_URL}
|
||||||
|
tar xzf ${GOTESTSUM_ARCHIVE}
|
||||||
|
install gotestsum ${GOPATH}/bin/
|
||||||
- run:
|
- run:
|
||||||
name: Run parallel race tests
|
name: Run parallel race tests
|
||||||
command: |
|
command: |
|
||||||
mkdir -p /tmp/test-results
|
mkdir -p test-results
|
||||||
GO_TEST_CMD="gotestsum --format standard-quiet --junitfile /tmp/test-results/gotestsum.xml --"
|
GO_TEST_CMD="gotestsum --format standard-quiet --junitfile ./test-results/gotestsum.xml --"
|
||||||
TESTFILES=($(go list ./... | circleci tests split --split-by=timings))
|
TESTFILES=($(go list ./... | circleci tests split --split-by=timings))
|
||||||
make GO_TEST="$GO_TEST_CMD" GO_TEST_PATHS="${TESTFILES[*]}" test-race
|
make GO_TEST="$GO_TEST_CMD" GO_TEST_PATHS="${TESTFILES[*]}" test-race
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: /tmp/test-results
|
path: ./test-results
|
||||||
destination: raw-test-output
|
destination: raw-test-output
|
||||||
- store_test_results:
|
- store_test_results:
|
||||||
path: /tmp/test-results
|
path: ./test-results
|
||||||
|
3
Makefile
3
Makefile
@ -91,9 +91,10 @@ mock: ./internal/mock/gen.go
|
|||||||
go generate ./internal/mock/
|
go generate ./internal/mock/
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GO_TEST) $(GO_TEST_PATHS)
|
CGO_ENABLED=0 $(GO_TEST) $(GO_TEST_PATHS)
|
||||||
|
|
||||||
test-race:
|
test-race:
|
||||||
|
# Race-checking requires CGO.
|
||||||
$(GO_TEST) -v -race -count=1 $(GO_TEST_PATHS)
|
$(GO_TEST) -v -race -count=1 $(GO_TEST_PATHS)
|
||||||
|
|
||||||
### List of all targets that don't produce a file
|
### List of all targets that don't produce a file
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//+build !windows
|
||||||
|
|
||||||
package signals
|
package signals
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
55
scripts/ci/install-go.sh
Executable file
55
scripts/ci/install-go.sh
Executable file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
declare -r GO_VERSION=1.16.5
|
||||||
|
|
||||||
|
function install_go_linux () {
|
||||||
|
ARCHIVE=go${GO_VERSION}.linux-$(dpkg --print-architecture).tar.gz
|
||||||
|
wget https://golang.org/dl/${ARCHIVE}
|
||||||
|
tar -C $1 -xzf ${ARCHIVE}
|
||||||
|
rm ${ARCHIVE}
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_go_mac () {
|
||||||
|
ARCHIVE=go${GO_VERSION}.darwin-amd64.tar.gz
|
||||||
|
wget https://golang.org/dl/${ARCHIVE}
|
||||||
|
tar -C $1 -xzf ${ARCHIVE}
|
||||||
|
rm ${ARCHIVE}
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_go_windows () {
|
||||||
|
ARCHIVE=go${GO_VERSION}.windows-amd64.zip
|
||||||
|
wget https://golang.org/dl/${ARCHIVE}
|
||||||
|
unzip -qq -d $1 ${ARCHIVE}
|
||||||
|
rm ${ARCHIVE}
|
||||||
|
}
|
||||||
|
|
||||||
|
function main () {
|
||||||
|
if [[ $# != 1 ]]; then
|
||||||
|
>&2 echo Usage: $0 '<install-dir>'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local -r install_dir=$1
|
||||||
|
|
||||||
|
rm -rf "$install_dir"
|
||||||
|
mkdir -p "$install_dir"
|
||||||
|
case $(uname) in
|
||||||
|
Linux)
|
||||||
|
install_go_linux "$install_dir"
|
||||||
|
;;
|
||||||
|
Darwin)
|
||||||
|
install_go_mac "$install_dir"
|
||||||
|
;;
|
||||||
|
MSYS_NT*)
|
||||||
|
install_go_windows "$install_dir"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
>&2 echo Error: unknown OS $(uname)
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
"${install_dir}/go/bin/go" version
|
||||||
|
}
|
||||||
|
|
||||||
|
main ${@}
|
39
scripts/ci/setup-system.sh
Executable file
39
scripts/ci/setup-system.sh
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
function setup_linux () {
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y --no-install-recommends make
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup_mac () {
|
||||||
|
# Python and TCL both come pre-installed on Circle's mac executors, and both depend on wget in some way.
|
||||||
|
# Homebrew will auto-upgrade both of them when wget is installed/upgraded, triggering a chain of upgrades.
|
||||||
|
# Uninstall them both before adding wget to avoid burning time in CI for things we don't need.
|
||||||
|
brew remove --force python@3.9 tcl-tk
|
||||||
|
HOMEBREW_NO_AUTO_UPDATE=1 brew install wget
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup_windows () {
|
||||||
|
choco install make mingw wget
|
||||||
|
}
|
||||||
|
|
||||||
|
function main () {
|
||||||
|
case $(uname) in
|
||||||
|
Linux)
|
||||||
|
setup_linux
|
||||||
|
;;
|
||||||
|
Darwin)
|
||||||
|
setup_mac
|
||||||
|
;;
|
||||||
|
MSYS_NT*)
|
||||||
|
setup_windows
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
>&2 echo Error: unknown OS $(uname)
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main ${@}
|
Reference in New Issue
Block a user