180 строки
5.1 KiB
YAML
180 строки
5.1 KiB
YAML
####################
|
|
# CircleCI configuration reference:
|
|
# https://circleci.com/docs/2.0/configuration-reference
|
|
####################
|
|
# CircleCI built-in environment variables:
|
|
# https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
|
|
####################
|
|
|
|
####################
|
|
# Version: determines what features are available.
|
|
####################
|
|
|
|
version: 2.1
|
|
|
|
|
|
####################
|
|
# Templates: see "anchors" in https://learnxinyminutes.com/docs/yaml/
|
|
####################
|
|
|
|
# See available image tags at https://hub.docker.com/r/mozilla/sbt/
|
|
sbt_image: &sbt_image mozilla/sbt:8u171_1.1.6
|
|
|
|
|
|
####################
|
|
# Commands: see https://circleci.com/docs/2.0/reusing-config
|
|
####################
|
|
|
|
commands:
|
|
restore_sbt_cache:
|
|
description: >-
|
|
Restore a cache of sbt dependencies if available.
|
|
steps:
|
|
- run:
|
|
name: Clean directories to restore
|
|
command: |
|
|
rm -r ~/.ivy2 ~/.sbt
|
|
- restore_cache:
|
|
keys:
|
|
- telemetry-batch-view-{{ .Branch }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
|
|
- telemetry-batch-view-{{ .Branch }}
|
|
- telemetry-batch-view-
|
|
|
|
save_sbt_cache:
|
|
description: >-
|
|
Archive ~/.ivy2 and ~/.sbt for reuse on future runs in order to speed
|
|
build times and improve reliability when dependency providers are unavailable.
|
|
Note that only one job in the workflow needs to save the cache (we choose assembly)
|
|
and many jobs can restore that same cache.
|
|
steps:
|
|
- save_cache:
|
|
key: telemetry-batch-view-{{ .Branch }}-{{ .Environment.CIRCLE_WORKFLOW_ID }}
|
|
paths:
|
|
- ~/.ivy2
|
|
- ~/.sbt
|
|
|
|
# CircleCI generally only triggers builds on commits to the main repository,
|
|
# so PRs coming from branches of the main repo simply reference builds for existing commits
|
|
# (CIRCLE_BRANCH=branchname and CIRCLE_PR_NUMBER is unset);
|
|
# The only time PRs will trigger a build is when the PR is referencing a fork
|
|
# (CIRCLE_BRANCH=pull/XXX and CIRCLE_PR_NUMBER=XXX).
|
|
early_return_for_forked_pull_requests:
|
|
description: >-
|
|
If this build is from a fork, stop executing the current job and return success.
|
|
This is useful to avoid steps that will fail due to missing credentials.
|
|
steps:
|
|
- run:
|
|
name: Early return if this build is from a forked PR
|
|
command: |
|
|
if [ -n "$CIRCLE_PR_NUMBER" ]; then
|
|
echo "Nothing to upload for forked PRs, so marking this step successful"
|
|
circleci step halt
|
|
fi
|
|
|
|
early_return_for_skip_tests:
|
|
description: >-
|
|
If the latest non-merge commit message contains "[skip-tests]", stop executing
|
|
the current job and return success.
|
|
steps:
|
|
- run:
|
|
name: Early return if the latest commit contains "[skip-tests]"
|
|
command: |
|
|
COMMIT_MESSAGE=$(git log --format=%B --no-merges -n 1)
|
|
if [[ "$COMMIT_MESSAGE" =~ "[skip-tests]" ]]; then
|
|
echo "Skipping tests due to [skip-tests] flag, so marking this step successful"
|
|
circleci step halt
|
|
fi
|
|
|
|
|
|
####################
|
|
# Executors: see https://circleci.com/docs/2.0/reusing-config
|
|
####################
|
|
|
|
executors:
|
|
sbt_executor:
|
|
docker:
|
|
- image: *sbt_image
|
|
working_directory: /telemetry-batch-view
|
|
|
|
|
|
####################
|
|
# Jobs: see https://circleci.com/docs/2.0/jobs-steps/
|
|
####################
|
|
|
|
jobs:
|
|
|
|
test:
|
|
executor: sbt_executor
|
|
steps:
|
|
- checkout
|
|
- early_return_for_skip_tests
|
|
- restore_sbt_cache
|
|
- run:
|
|
name: Scalatest
|
|
command: |
|
|
sbt coverage test coverageReport
|
|
- run:
|
|
name: Submit code coverage data
|
|
command: |
|
|
bash <(curl -s https://codecov.io/bash)
|
|
|
|
lint:
|
|
executor: sbt_executor
|
|
steps:
|
|
- checkout
|
|
- early_return_for_skip_tests
|
|
- restore_sbt_cache
|
|
- run:
|
|
name: Scalastyle
|
|
command: |
|
|
sbt scalastyle test:scalastyle
|
|
|
|
# Publish to Maven in S3 and assemble an uberjar for the deploy step.
|
|
assembly:
|
|
executor: sbt_executor
|
|
steps:
|
|
- early_return_for_forked_pull_requests
|
|
- checkout
|
|
- restore_sbt_cache
|
|
- run:
|
|
name: Publish and Assemble
|
|
command: |
|
|
sbt publish assembly
|
|
- save_sbt_cache
|
|
- persist_to_workspace:
|
|
root: target
|
|
paths:
|
|
- scala-2.11/telemetry-batch-view-1.2.jar
|
|
|
|
# Uses a "workspace" to get access to the assembled uberjar from the previous stage.
|
|
deploy:
|
|
executor: sbt_executor
|
|
steps:
|
|
- early_return_for_forked_pull_requests
|
|
- checkout
|
|
- attach_workspace:
|
|
at: /telemetry-batch-view/target
|
|
- run:
|
|
name: Upload
|
|
command: |
|
|
export JAR=target/scala-2.11/telemetry-batch-view-1.2.jar
|
|
bash .circleci/deploy.sh
|
|
|
|
|
|
####################
|
|
# Workflows: see https://circleci.com/docs/2.0/workflows/
|
|
####################
|
|
|
|
workflows:
|
|
version: 2
|
|
build:
|
|
jobs:
|
|
- test
|
|
- lint
|
|
- assembly
|
|
- deploy:
|
|
requires:
|
|
- test
|
|
- lint
|
|
- assembly
|