# delphi-etl-common

Common functionality for all Delphi ETLs.

# Development Process
## Code Style
Scala language has an official code style guide. Everyone, involved in the current project development
should read it: https://docs.scala-lang.org/style/. We should follow the current guide as much as possible.
It will help us to keep our code readable and well-organized.

Code styling can be verified with following command:
```
sbt scalastyle
```
To verify styling in test sources use:
```
sbt test:scalastyle
```
For convenience, it's possible to check code formatting in the whole project:
```
sbt scalastyle test:scalastyle
```

## Code Formatting
The `scalafmt` tool was configured to the project in order to introduce the same code formatting
rules for all team members involved in the development and keep all code formatted identically.
The configuration might not 100% reflect the Scala style guide due to the tool limitation, but
it covers basic rules.

#### IDE configuration
The following link provides a guide on how to configure
the IDE to use `.scalafmt.conf` as a default formatting rule: https://scalameta.org/scalafmt/docs/installation.html

#### SBT usage
Use the following link for more information about usage with SBT: https://scalameta.org/scalafmt/docs/installation.html#sbt

To check formatting in the project:
```
sbt scalafmtCheckAll
```
To format a single file:
```
sbt scalafmtOnly <file>
```
Reformat all files according to .sclafmt config:
```
sbt scalafmtAll
```

#### Jenkins
The automatic code formatting check was added to `Code Style` step during the build.
The build will be failed when the code was not formatted properly.

## Test Coverage
To run tests with enabled coverage tooling use:
```
sbt clean coverage test
```
To generate coverage report use:
```
sbt coverageReport
```

Coverage HTML and XML reports will be in `target/scala-2.12/coverage-report`.

# Branching Strategy
This project follows so-called "Feature Branching Strategy". It means, that all changes should be implemented in a
separate branch and then merged into the target branch after review and approval by other teammates.

All branches should have a Jira ticket number in their names. Additional information about the changes in that branch
is welcomed, but not obligatory.

Examples of good branch naming:
* `task/XXX-1111/readme-update`
* `bug/XXX-1111/test-aggregation`
* `XXX-1111/naming-fixes`
* `XXX-1111`

## Typical development workflow
The typical day-to-day flow includes normal changes that developers make to the code, changes that do not bring any
heightened sense of urgency.
* The branch should be crated from the `develop` branch.
* PR should be targeted and merged to the `develop` branch.
* No project version update is required (because of `SNAPSHOT`).

## Emergency hotfixes
An emergency hotfix is when a particular incident or issue has been expedited to deal with some emergent situation,
normally bug fixes.
* The branch should be crated from the `master` branch.
* PR should be targeted and merged to the `master` branch.
* Version update is required (e.g. `1.2.0` -> `1.2.1`).

# Release Process
The release process for the current set of auxiliary libraries is the process of publishing the version to the Delphi
Nexus. For this repository automatic publishing to the Delphi Nexus is configured for `develop` and `master` branches.

### Development version publishing
Each Jenkins build triggered on `develop` branch publishes a new `SNAPSHOT` version to the Nexus.

### Release version publishing
To release a new stable version of this project there is a need to follow the following steps:
1. Do merge `develop` branch to the `master` branch.
2. Update project version from `X.X.X-SNAPSHOT` -> `X.X.X` with a separate commit to the `master` branch.
3. Push `master` branch to the remote.

### Publish Locally
During the development process, from time to time there is a need to have the latest version of the delphi common 
libraries available without publishing to the Nexus. To build the latest version of libraries from sources and 
install to your local repo use the following command:
```bash
$ sbt clean publishLocal
```

The output similar to the following should be printed to stdout:
```bash
[info] :: delivering :: com.sonymusic#delphi-etl-common_2.11;0.1.0-SNAPSHOT :: 0.1.0-SNAPSHOT :: integration :: Mon Nov 18 13:55:08 EET 2019
[info]  delivering ivy file to /Users/asuprun/Documents/Development/sony/delphi-etl-common/target/scala-2.11/ivy-0.1.0-SNAPSHOT.xml
[info]  published delphi-etl-common_2.11 to .../.ivy2/local/com.sonymusic/delphi-etl-common_2.11/0.1.0-SNAPSHOT/docs/delphi-etl-common_2.11-javadoc.jar
[info]  published delphi-etl-common_2.11 to .../.ivy2/local/com.sonymusic/delphi-etl-common_2.11/0.1.0-SNAPSHOT/poms/delphi-etl-common_2.11.pom
[info]  published delphi-etl-common_2.11 to .../.ivy2/local/com.sonymusic/delphi-etl-common_2.11/0.1.0-SNAPSHOT/jars/delphi-etl-common_2.11.jar
[info]  published delphi-etl-common_2.11 to .../.ivy2/local/com.sonymusic/delphi-etl-common_2.11/0.1.0-SNAPSHOT/jars/delphi-etl-common_2.11-tests.jar
[info]  published delphi-etl-common_2.11 to .../.ivy2/local/com.sonymusic/delphi-etl-common_2.11/0.1.0-SNAPSHOT/srcs/delphi-etl-common_2.11-sources.jar
[info]  published ivy to /Users/asuprun/.ivy2/local/com.sonymusic/delphi-etl-common_2.11/0.1.0-SNAPSHOT/ivys/ivy.xml
[success] Total time: 12 s, completed Nov 18, 2019 1:55:08 PM
```

The command above will install artifacts to the local `.ivy` location. Alternatively, it's possible to publish
the latest library versions to the local `.m2` repo:
```bash
$ sbt clean publishM2
```

# Setup Into the Application

Configure Delphi Nexus resolver in `build.sbt`:
```scala
val nexus = "https://artifacts-internal.delphiplatform.io"
ThisBuild / resolvers += "Delphi Nexus" at s"$nexus/repository/maven-public/"
```

Then add required modules in `build.sbt`:
```scala
libraryDependencies ++= Seq(
  // main dependencies
  "com.sonymusic" %% "delphi-etl-common" % "x.y.z",
  "com.sonymusic" %% "delphi-etl-common-slz" % "x.y.z",
  "com.sonymusic" %% "delphi-etl-common-app-guice" % "x.y.z",
  "com.sonymusic" %% "delphi-etl-common-bigtable" "x.y.z",
  
  // test dependency
"com.sonymusic" %% "delphi-etl-common-test" % "x.y.z" % Test
)
```
