debian-mirror-gitlab/doc/ci/examples/test-scala-application.md

82 lines
2.7 KiB
Markdown
Raw Normal View History

2019-09-04 21:01:54 +05:30
---
2020-06-23 00:09:42 +05:30
stage: Verify
group: Continuous Integration
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
2019-09-04 21:01:54 +05:30
type: tutorial
---
2019-07-07 11:18:12 +05:30
# Test and deploy a Scala application to Heroku
2016-06-22 15:30:34 +05:30
2020-04-22 19:07:51 +05:30
This example demonstrates the integration of GitLab CI/CD with Scala
2019-09-04 21:01:54 +05:30
applications using SBT. You can view or fork the [example project](https://gitlab.com/gitlab-examples/scala-sbt)
and view the logs of its past [CI jobs](https://gitlab.com/gitlab-examples/scala-sbt/-/jobs?scope=finished).
2016-06-22 15:30:34 +05:30
2017-08-17 22:00:37 +05:30
## Add `.gitlab-ci.yml` file to project
2016-06-22 15:30:34 +05:30
The following `.gitlab-ci.yml` should be added in the root of your
repository to trigger CI:
``` yaml
2020-05-24 23:13:21 +05:30
image: openjdk:8
2016-06-22 15:30:34 +05:30
2017-08-17 22:00:37 +05:30
stages:
- test
- deploy
2016-06-22 15:30:34 +05:30
before_script:
- apt-get update -y
- apt-get install apt-transport-https -y
2017-08-17 22:00:37 +05:30
## Install SBT
2016-06-22 15:30:34 +05:30
- 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
2018-12-13 13:39:08 +05:30
- sbt sbtVersion
2016-06-22 15:30:34 +05:30
test:
2017-08-17 22:00:37 +05:30
stage: test
2016-06-22 15:30:34 +05:30
script:
- sbt clean coverage test coverageReport
2017-08-17 22:00:37 +05:30
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
2016-06-22 15:30:34 +05:30
```
2019-09-04 21:01:54 +05:30
In the above configuration:
2019-09-30 21:07:59 +05:30
- The `before_script` installs [SBT](https://www.scala-sbt.org/) and
displays the version that is being used.
2019-09-04 21:01:54 +05:30
- The `test` stage executes SBT to compile and test the project.
2019-09-30 21:07:59 +05:30
- [sbt-scoverage](https://github.com/scoverage/sbt-scoverage) is used as an SBT
plugin to measure test coverage.
2019-09-04 21:01:54 +05:30
- The `deploy` stage automatically deploys the project to Heroku using dpl.
2016-06-22 15:30:34 +05:30
You can use other versions of Scala and SBT by defining them in
`build.sbt`.
2017-08-17 22:00:37 +05:30
## Display test coverage in job
2016-06-22 15:30:34 +05:30
Add the `Coverage was \[\d+.\d+\%\]` regular expression in the
2017-09-10 17:25:29 +05:30
**Settings ➔ Pipelines ➔ Coverage report** project setting to
2020-04-08 14:13:33 +05:30
retrieve the [test coverage](../pipelines/settings.md#test-coverage-report-badge)
2019-07-07 11:18:12 +05:30
rate from the build trace and have it displayed with your jobs.
2017-08-17 22:00:37 +05:30
**Pipelines** must be enabled for this option to appear.
## 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
2020-05-24 23:13:21 +05:30
[account](https://dashboard.heroku.com/account). Add a [protected variable](../variables/README.md#protect-a-custom-variable) with
2017-08-17 22:00:37 +05:30
this value in **Project ➔ Variables** with key `HEROKU_API_KEY`.