gitlab-org--gitlab-foss/doc/ci/examples/test-scala-application.md

74 lines
2.3 KiB
Markdown
Raw Normal View History

# Test and deploy a Scala application to Heroku
2018-09-25 00:57:57 -04:00
This example demonstrates the integration of GitLab CI with Scala
applications using SBT. Checkout the example
[project](https://gitlab.com/gitlab-examples/scala-sbt) and
[build status](https://gitlab.com/gitlab-examples/scala-sbt/builds).
2016-11-18 10:56:25 -05:00
## Add `.gitlab-ci.yml` file to project
The following `.gitlab-ci.yml` should be added in the root of your
repository to trigger CI:
``` yaml
image: java:8
2016-11-18 10:56:25 -05:00
stages:
- test
- deploy
before_script:
- apt-get update -y
- apt-get install apt-transport-https -y
2016-11-18 10:56:25 -05:00
## Install SBT
- echo "deb http://dl.bintray.com/sbt/debian /" | tee -a /etc/apt/sources.list.d/sbt.list
- apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
- apt-get update -y
- apt-get install sbt -y
- sbt sbtVersion
test:
2016-11-18 10:56:25 -05:00
stage: test
script:
- sbt clean coverage test coverageReport
2016-11-18 10:56:25 -05:00
deploy:
stage: deploy
script:
- apt-get update -yq
- apt-get install rubygems ruby-dev -y
- gem install dpl
- dpl --provider=heroku --app=gitlab-play-sample-app --api-key=$HEROKU_API_KEY
```
The `before_script` installs [SBT](http://www.scala-sbt.org/) and
displays the version that is being used. The `test` stage executes SBT
to compile and test the project.
[scoverage](https://github.com/scoverage/sbt-scoverage) is used as an SBT
plugin to measure test coverage.
2016-11-18 10:56:25 -05:00
The `deploy` stage automatically deploys the project to Heroku using dpl.
You can use other versions of Scala and SBT by defining them in
`build.sbt`.
## Display test coverage in job
Add the `Coverage was \[\d+.\d+\%\]` regular expression in the
**Settings ➔ Pipelines ➔ Coverage report** project setting to
2019-03-10 21:47:01 -04:00
retrieve the [test coverage](../../user/project/pipelines/settings.md#test-coverage-report-badge)
rate from the build trace and have it displayed with your jobs.
**Pipelines** must be enabled for this option to appear.
2016-11-18 10:56:25 -05:00
## Heroku application
A Heroku application is required. You can create one through the
[Dashboard](https://dashboard.heroku.com/). Substitute `gitlab-play-sample-app`
in the `.gitlab-ci.yml` file with your application's name.
## Heroku API key
You can look up your Heroku API key in your
2019-03-10 21:47:01 -04:00
[account](https://dashboard.heroku.com/account). Add a [protected variable](../variables/README.md#protected-variables) with
2016-11-18 10:56:25 -05:00
this value in **Project ➔ Variables** with key `HEROKU_API_KEY`.