chore: run ci tests in parallel and get test insights (#9686)

This commit is contained in:
Sebastian Spaink 2021-09-14 14:42:59 -07:00 committed by GitHub
parent c331669f2e
commit 779ed5ec42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 185 additions and 69 deletions

View File

@ -1,6 +1,6 @@
version: 2.1
orbs:
win: circleci/windows@2.4.0
win: circleci/windows@2.4.0
aws-cli: circleci/aws-cli@1.4.0
executors:
@ -26,27 +26,84 @@ executors:
commands:
check-changed-files-or-halt:
steps:
- run: ./scripts/check-file-changes.sh
check-changed-files-or-halt-windows:
steps:
- run:
command: ./scripts/check-file-changes.sh
shell: bash.exe
steps:
- run: ./scripts/check-file-changes.sh
test-go:
parameters:
goarch:
os:
type: string
default: "amd64"
default: "linux"
gotestsum:
type: string
default: "gotestsum"
cache_version:
type: string
default: "v3"
steps:
- checkout
- check-changed-files-or-halt
- attach_workspace:
at: '/go'
- run: 'GOARCH=<< parameters.goarch >> make'
- run: 'GOARCH=<< parameters.goarch >> make check'
- run: 'GOARCH=<< parameters.goarch >> make check-deps'
- run: 'GOARCH=<< parameters.goarch >> make test'
- when:
condition:
equal: [ linux, << parameters.os >> ]
steps:
- restore_cache:
key: linux-go-<< parameters.cache_version >>-{{ checksum "go.sum" }}
- attach_workspace:
at: '/go'
- when:
condition:
equal: [ darwin, << parameters.os >> ]
steps:
- restore_cache:
key: darwin-go-<< parameters.cache_version >>-{{ checksum "go.sum" }}
- run: 'sh ./scripts/installgo_mac.sh'
- when:
condition:
equal: [ windows, << parameters.os >> ]
steps:
- run: rm -rf /c/Go
- restore_cache:
key: windows-go-<< parameters.cache_version >>-{{ checksum "go.sum" }}
- run: 'sh ./scripts/installgo_windows.sh'
- run: mkdir -p test-results
- run: ./scripts/install_gotestsum.sh << parameters.os >> << parameters.gotestsum >>
- run: |
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
./<< parameters.gotestsum >> --junitfile test-results/gotestsum-report.xml -- -short $PACKAGE_NAMES
- store_test_results:
path: test-results
- when:
condition:
equal: [ linux, << parameters.os >> ]
steps:
- save_cache:
name: 'Saving cache'
key: linux-go-<< parameters.cache_version >>-{{ checksum "go.sum" }}
paths:
- '~/go/src/github.com/influxdata/telegraf/gotestsum'
- when:
condition:
equal: [ darwin, << parameters.os >> ]
steps:
- save_cache:
name: 'Saving cache'
key: darwin-go-<< parameters.cache_version >>-{{ checksum "go.sum" }}
paths:
- '/go/src/github.com/influxdata/telegraf/gotestsum'
- '/usr/local/Cellar/go'
- '/usr/local/bin/go'
- '/usr/local/bin/gofmt'
- when:
condition:
equal: [ windows, << parameters.os >> ]
steps:
- save_cache:
name: 'Saving cache'
key: windows-go-<< parameters.cache_version >>-{{ checksum "go.sum" }}
paths:
- 'C:\Go'
- 'C:\Users\circleci\project\gotestsum.exe'
package-build:
parameters:
release:
@ -65,11 +122,11 @@ commands:
at: '/go'
- when:
condition: << parameters.release >>
steps:
steps:
- run: 'mips=1 mipsel=1 arm64=1 amd64=1 static=1 armel=1 armhf=1 s390x=1 ppc641e=1 i386=1 windows=1 darwin=1 make package'
- when:
condition: << parameters.nightly >>
steps:
steps:
- run: 'mips=1 mipsel=1 arm64=1 amd64=1 static=1 armel=1 armhf=1 s390x=1 ppc641e=1 i386=1 windows=1 darwin=1 NIGHTLY=1 make package'
- run: 'make upload-nightly'
- unless:
@ -96,6 +153,8 @@ jobs:
- check-changed-files-or-halt
- run: 'make deps'
- run: 'make tidy'
- run: 'make check'
- run: 'make check-deps'
- save_cache:
name: 'go module cache'
key: go-mod-v1-{{ checksum "go.sum" }}
@ -109,51 +168,37 @@ jobs:
executor: go-1_16
steps:
- test-go
parallelism: 4
test-go-1_16-386:
executor: go-1_16
steps:
- test-go:
goarch: "386"
- test-go
parallelism: 4
test-go-1_17:
executor: go-1_17
steps:
- test-go
parallelism: 4
test-go-1_17-386:
executor: go-1_17
steps:
- test-go:
goarch: "386"
- test-go
parallelism: 4
test-go-mac:
executor: mac
steps:
- checkout
- restore_cache:
key: mac-go-mod-v0-{{ checksum "go.sum" }}
- check-changed-files-or-halt
- run: 'sh ./scripts/mac_installgo.sh'
- save_cache:
name: 'Saving cache'
key: mac-go-mod-v0-{{ checksum "go.sum" }}
paths:
- '/usr/local/Cellar/go'
- '/usr/local/bin/go'
- '/usr/local/bin/gofmt'
- run: 'make deps'
- run: 'make tidy'
- run: 'make'
- run: 'make check'
- run: 'make test'
- test-go:
os: darwin
parallelism: 4
test-go-windows:
executor:
name: win/default
shell: powershell.exe
shell: bash.exe
steps:
- checkout
- check-changed-files-or-halt-windows
- run: choco upgrade golang --version=1.17.0
- run: choco install make
- run: git config --system core.longpaths true
- run: make test-windows
- test-go:
os: windows
gotestsum: "gotestsum.exe"
parallelism: 4
windows-package:
executor: go-1_17
@ -283,14 +328,14 @@ jobs:
command: |
echo "Go tests complete."
share-artifacts:
executor: aws-cli/default
executor: aws-cli/default
steps:
- run:
command: |
PR=${CIRCLE_PULL_REQUEST##*/}
printf -v payload '{ "pullRequestNumber": "%s" }' "$PR"
curl -X POST "https://182c7jdgog.execute-api.us-east-1.amazonaws.com/prod/shareArtifacts" --data "$payload"
curl -X POST "https://182c7jdgog.execute-api.us-east-1.amazonaws.com/prod/shareArtifacts" --data "$payload"
workflows:
version: 2
check:
@ -331,47 +376,47 @@ workflows:
filters:
tags:
only: /.*/
- 'test-awaiter':
- 'test-awaiter':
requires:
- 'test-go-1_16'
- 'test-go-1_16-386'
- 'test-go-1_17'
- 'test-go-1_17-386'
- 'windows-package':
requires:
requires:
- 'test-go-windows'
- 'darwin-package':
requires:
requires:
- 'test-go-mac'
- 'i386-package':
requires:
requires:
- 'test-awaiter'
- 'ppc641e-package':
requires:
requires:
- 'test-awaiter'
- 's390x-package':
requires:
requires:
- 'test-awaiter'
- 'armel-package':
requires:
requires:
- 'test-awaiter'
- 'amd64-package':
requires:
requires:
- 'test-awaiter'
- 'arm64-package':
requires:
requires:
- 'test-awaiter'
- 'armhf-package':
requires:
requires:
- 'test-awaiter'
- 'static-package':
requires:
- 'test-awaiter'
- 'mipsel-package':
requires:
requires:
- 'test-awaiter'
- 'mips-package':
requires:
requires:
- 'test-awaiter'
- 'share-artifacts':
requires:
@ -412,7 +457,7 @@ workflows:
only: /.*/
- 'package-sign-mac':
requires:
- 'package-sign-windows'
- 'package-sign-windows'
filters:
tags:
only: /.*/

View File

@ -119,10 +119,6 @@ fmtcheck:
exit 1 ;\
fi
.PHONY: test-windows
test-windows:
go test -short ./...
.PHONY: vet
vet:
@echo 'go vet $$(go list ./... | grep -v ./plugins/parsers/influx)'

46
scripts/install_gotestsum.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
set -eux
OS=$1
EXE=$2
VERSION="1.7.0"
WINDOWS_SHA="7ae12ddb171375f0c14d6a09dd27a5c1d1fc72edeea674e3d6e7489a533b40c1"
DARWIN_SHA="a8e2351604882af1a67601cbeeacdcfa9b17fc2f6fbac291cf5d434efdf2d85b"
LINUX_SHA="b5c98cc408c75e76a097354d9487dca114996e821b3af29a0442aa6c9159bd40"
setup_gotestsum () {
echo "installing gotestsum"
curl -L "https://github.com/gotestyourself/gotestsum/releases/download/v${VERSION}/gotestsum_${VERSION}_${OS}_amd64.tar.gz" --output gotestsum.tar.gz
if [ "$OS" = "windows" ]; then
SHA=$WINDOWS_SHA
SHATOOL="sha256sum"
elif [ "$OS" = "darwin" ]; then
SHA=$DARWIN_SHA
SHATOOL="shasum --algorithm 256"
elif [ "$OS" = "linux" ]; then
SHA=$LINUX_SHA
SHATOOL="sha256sum"
fi
if ! echo "${SHA} gotestsum.tar.gz" | ${SHATOOL} --check -; then
echo "Checksum failed" >&2
exit 1
fi
tar --extract --file=gotestsum.tar.gz "${EXE}"
}
if test -f "${EXE}"; then
echo "gotestsum is already installed"
v=$(./"${EXE}" --version)
echo "$v is installed, required version is ${VERSION}"
if [ "$v" != "gotestsum version ${VERSION}" ]; then
setup_gotestsum
${EXE} --version
fi
else
setup_gotestsum
fi

View File

@ -14,16 +14,20 @@ path="/usr/local/Cellar"
setup_go () {
echo "installing go"
curl -L https://golang.org/dl/go${GO_VERSION}.${GO_ARCH}.tar.gz --output go${GO_VERSION}.${GO_ARCH}.tar.gz
echo "${GO_VERSION_SHA} go${GO_VERSION}.${GO_ARCH}.tar.gz" | shasum -a 256 --check
if ! echo "${GO_VERSION_SHA} go${GO_VERSION}.${GO_ARCH}.tar.gz" | shasum --algorithm 256 --check -; then
echo "Checksum failed" >&2
exit 1
fi
sudo rm -rf ${path}/go
sudo tar -C $path -xzf go${GO_VERSION}.${GO_ARCH}.tar.gz
ln -sf ${path}/go/bin/go /usr/local/bin/go
ln -sf ${path}/go/bin/gofmt /usr/local/bin/gofmt
}
if command -v go &> /dev/null; then
if command -v go >/dev/null 2>&1; then
echo "Go is already installed"
v=`go version | { read _ _ v _; echo ${v#go}; }`
v=$(go version | { read -r _ _ v _; echo "${v#go}"; })
echo "$v is installed, required version is ${GO_VERSION}"
if [ "$v" != ${GO_VERSION} ]; then
setup_go

View File

@ -0,0 +1,25 @@
#!/bin/sh
set -eux
GO_VERSION="1.17"
setup_go () {
choco upgrade golang --version=${GO_VERSION}
choco install make
git config --system core.longpaths true
rm -rf /c/Go
cp -r /c/Program\ Files/Go /c/
}
if command -v go >/dev/null 2>&1; then
echo "Go is already installed"
v=$(go version | { read -r _ _ v _; echo "${v#go}"; })
echo "$v is installed, required version is ${GO_VERSION}"
if [ "$v" != ${GO_VERSION} ]; then
setup_go
go version
fi
else
setup_go
fi