terraform/.circleci/config.yml

180 lines
4.7 KiB
YAML
Raw Normal View History

2020-03-27 17:48:57 +01:00
version: 2.1
2020-03-27 15:41:33 +01:00
executors:
go:
2020-03-27 17:48:57 +01:00
docker:
- image: circleci/golang:1.14
2020-03-27 15:41:33 +01:00
environment:
CONSUL_VERSION: 1.7.2
GOMAXPROCS: 4
GO111MODULE: "on"
GOPROXY: https://proxy.golang.org/
TEST_RESULTS_DIR: &TEST_RESULTS_DIR /tmp/test-results
ARTIFACTS_DIR: &ARTIFACTS_DIR /tmp/artifacts
GOFLAGS: "-mod=vendor"
jobs:
go-checks:
executor:
name: go
steps:
- checkout
- run: go mod verify
- run: make fmtcheck generate
- run:
name: verify no code was generated
command: |
if [[ -z $(git status --porcelain) ]]; then
echo "clean"
else
echo "dirty"
git status --porcelain
exit 1
fi
go-test:
executor:
name: go
parallelism: 4
steps:
- checkout
- attach_workspace:
at: .
- run:
name: install consul
command: |
curl -sLo consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip
unzip consul.zip
mkdir -p ~/bin
mv consul ~/bin
echo 'export PATH="~/bin:$PATH"'
- run: mkdir -p $TEST_RESULTS_DIR
2020-03-31 23:56:30 +02:00
- run:
name: Run Go Tests
command: |
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
echo $PACKAGE_NAMES
gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -p 2 -cover -coverprofile=cov_$CIRCLE_NODE_INDEX.part $PACKAGE_NAMES
2020-03-27 15:41:33 +01:00
# save coverage report parts
- persist_to_workspace:
root: .
paths:
- cov_*.part
- store_test_results:
path: *TEST_RESULTS_DIR
- store_artifacts:
path: *TEST_RESULTS_DIR
go-test-e2e:
executor:
name: go
environment:
TF_ACC: 1
2020-03-27 17:48:57 +01:00
steps:
2020-03-27 15:41:33 +01:00
- checkout
- attach_workspace:
at: .
- run: mkdir -p $TEST_RESULTS_DIR
2020-03-31 23:56:30 +02:00
- run:
name: Run Go E2E Tests
command: |
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
echo "Running $(echo $PACKAGE_NAMES | wc -w) packages"
echo $PACKAGE_NAMES
gotestsum --format=short-verbose --junitfile $TEST_RESULTS_DIR/gotestsum-report.xml -- -p 2 -cover -coverprofile=cov_e2e.part ./command/e2etest
2020-03-27 15:41:33 +01:00
# save coverage report parts
- persist_to_workspace:
root: .
paths:
- cov_*.part
- store_test_results:
path: *TEST_RESULTS_DIR
- store_artifacts:
path: *TEST_RESULTS_DIR
# combine code coverage results from the parallel circleci executors
coverage-merge:
executor:
name: go
steps:
- checkout
- attach_workspace:
at: .
- run: mkdir -p $TEST_RESULTS_DIR
- run:
name: merge coverage reports
command: |
echo "mode: set" > coverage.out
grep -h -v "mode: set" cov_*.part >> coverage.out
go tool cover -html=coverage.out -o $TEST_RESULTS_DIR/coverage.html
- run:
name: codecov upload
command: bash <(curl -s https://codecov.io/bash) -v -C $CIRCLE_SHA1
- store_artifacts:
path: *TEST_RESULTS_DIR
# build all distros
build-distros: &build-distros
executor: go
environment: &build-env
TF_RELEASE: 1
steps:
- run: go get -u github.com/mitchellh/gox # go get gox before detecting go mod
- checkout
- run: ./scripts/build.sh
- run: mkdir -p $ARTIFACTS_DIR
- run: cp pkg/*.zip /tmp/artifacts
# save dev build to CircleCI
- store_artifacts:
path: *ARTIFACTS_DIR
# build all 386 architecture supported OS binaries
build-386:
<<: *build-distros
environment:
<<: *build-env
XC_OS: "freebsd linux openbsd windows"
XC_ARCH: "386"
# build all amd64 architecture supported OS binaries
build-amd64:
<<: *build-distros
environment:
<<: *build-env
XC_OS: "darwin freebsd linux solaris windows"
XC_ARCH: "amd64"
# build all arm architecture supported OS binaries
build-arm:
<<: *build-distros
environment:
<<: *build-env
XC_OS: "freebsd linux"
XC_ARCH: "arm"
2020-03-27 17:48:57 +01:00
workflows:
version: 2
2020-03-27 15:41:33 +01:00
test:
jobs:
- go-checks
- go-test:
requires:
- go-checks
- go-test-e2e:
requires:
- go-checks
- coverage-merge:
requires:
- go-test
- go-test-e2e
build-distros:
2020-03-27 17:48:57 +01:00
jobs:
2020-03-27 15:41:33 +01:00
- build-386
- build-amd64
- build-arm