open-vault/.circleci/config.yml

206 lines
5.9 KiB
YAML
Raw Normal View History

version: 2
references:
images:
go: &GOLANG_IMAGE golang:1.12.4-stretch # Pin Go to patch version (ex: 1.2.3)
node: &NODE_IMAGE node:10-stretch # Pin Node.js to major version (ex: 10)
environment: &ENVIRONMENT
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_VERSION: 1.12.4 # Pin Go to patch version (ex: 1.2.3)
GOTESTSUM_VERSION: 0.3.3 # Pin gotestsum to patch version (ex: 1.2.3)
2019-05-14 20:27:34 +00:00
cache:
go-sum: &GO_SUM_CACHE_KEY go-sum-v1-{{ checksum "go.sum" }}
yarn-lock: &YARN_LOCK_CACHE_KEY yarn-lock-v1-{{ checksum "ui/yarn.lock" }}
jobs:
install-ui-dependencies:
docker:
- image: *NODE_IMAGE
2019-05-14 20:27:34 +00:00
working_directory: /src
steps:
2019-05-14 20:27:34 +00:00
- checkout
- restore_cache:
2019-05-14 20:27:34 +00:00
key: *YARN_LOCK_CACHE_KEY
- run:
name: Install UI dependencies
command: |
set -eux -o pipefail
2019-05-14 20:27:34 +00:00
cd ui
yarn install --ignore-optional
npm rebuild node-sass
- save_cache:
2019-05-14 20:27:34 +00:00
key: *YARN_LOCK_CACHE_KEY
paths:
- ui/node_modules
2019-05-14 20:27:34 +00:00
go-mod-download:
docker:
- image: *GOLANG_IMAGE
2019-05-14 20:27:34 +00:00
working_directory: /src
steps:
- checkout
- restore_cache:
2019-05-14 20:27:34 +00:00
key: *GO_SUM_CACHE_KEY
- run:
2019-05-14 20:27:34 +00:00
name: Download Go modules
command: go mod download
- run:
2019-05-14 20:27:34 +00:00
name: Verify checksums of Go modules
command: go mod verify
- save_cache:
2019-05-14 20:27:34 +00:00
key: *GO_SUM_CACHE_KEY
paths:
2019-05-14 20:27:34 +00:00
- /go/pkg/mod
build-go-dev:
docker:
- image: *GOLANG_IMAGE
2019-05-14 20:27:34 +00:00
working_directory: /src
steps:
- checkout
2019-05-14 20:27:34 +00:00
- restore_cache:
key: *GO_SUM_CACHE_KEY
- run:
name: Build dev binary
command: |
set -eux -o pipefail
# Move dev UI assets to expected location
rm -rf ./pkg
mkdir ./pkg
# Build dev binary
make bootstrap dev
- persist_to_workspace:
root: .
paths:
- bin
test-ui:
docker:
- image: *NODE_IMAGE
2019-05-14 20:27:34 +00:00
working_directory: /src
resource_class: medium+
steps:
2019-05-14 20:27:34 +00:00
- checkout
- restore_cache:
key: *YARN_LOCK_CACHE_KEY
- attach_workspace:
2019-05-14 20:27:34 +00:00
at: .
- run:
name: Test UI
command: |
set -eux -o pipefail
# Install Chrome
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub \
| apt-key add -
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" \
| tee /etc/apt/sources.list.d/google-chrome.list
apt-get update
apt-get -y install google-chrome-stable
rm /etc/apt/sources.list.d/google-chrome.list
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
# Add ./bin to the PATH so vault binary can be run by Ember tests
2019-05-14 20:27:34 +00:00
export PATH="${PWD}"/bin:${PATH}
# Run Ember tests
2019-05-14 20:27:34 +00:00
cd ui
mkdir -p test-results/qunit
yarn run test-oss
- store_artifacts:
2019-05-14 20:27:34 +00:00
path: ui/test-results
- store_test_results:
2019-05-14 20:27:34 +00:00
path: ui/test-results
test-go:
machine: true
environment:
<<: *ENVIRONMENT
GO_TAGS:
parallelism: 2
2019-05-14 20:27:34 +00:00
working_directory: ~/src
steps:
- checkout
2019-05-14 20:27:34 +00:00
- run:
name: Allow circleci user to restore Go modules cache
command: |
set -eux -o pipefail
sudo mkdir /go
sudo chown -R circleci:circleci /go
- restore_cache:
key: *GO_SUM_CACHE_KEY
- run:
name: Run Go tests
no_output_timeout: 20m
command: |
set -eux -o pipefail
# Install Go
curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
rm -f "go${GO_VERSION}.linux-amd64.tar.gz"
2019-05-14 20:27:34 +00:00
export GOPATH=/go
export PATH="${PATH}:${GOPATH}/bin:/usr/local/go/bin"
# Install CircleCI CLI
curl -sSL \
"https://github.com/CircleCI-Public/circleci-cli/releases/download/v${CIRCLECI_CLI_VERSION}/circleci-cli_${CIRCLECI_CLI_VERSION}_linux_amd64.tar.gz" \
| sudo tar --overwrite -xz \
-C /usr/local/bin \
"circleci-cli_${CIRCLECI_CLI_VERSION}_linux_amd64/circleci"
# Split Go tests by prior test times
package_names=$(go list \
-tags "${GO_TAGS}" \
./... \
| grep -v /vendor/ \
| sort \
| circleci tests split --split-by=timings --timings-type=classname)
# Install gotestsum
curl -sSL "https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/gotestsum_${GOTESTSUM_VERSION}_linux_amd64.tar.gz" \
| sudo tar --overwrite -xz -C /usr/local/bin gotestsum
# Run tests
make prep
mkdir -p test-results/go-test
CGO_ENABLED= \
VAULT_ADDR= \
VAULT_TOKEN= \
VAULT_DEV_ROOT_TOKEN_ID= \
VAULT_ACC= \
gotestsum --format=short-verbose --junitfile test-results/go-test/results.xml -- \
-tags "${GO_TAGS}" \
-timeout=40m \
-parallel=20 \
${package_names}
- store_artifacts:
path: test-results
- store_test_results:
path: test-results
workflows:
version: 2
ci:
jobs:
- install-ui-dependencies
2019-05-14 20:27:34 +00:00
- go-mod-download
- build-go-dev:
requires:
2019-05-14 20:27:34 +00:00
- go-mod-download
- test-ui:
requires:
- install-ui-dependencies
- build-go-dev
- test-go:
requires:
- build-go-dev