CI configuring notes


Configure a new subproject

In order to configure a new project the following steps must be taken:

  1. Create a directory at the root of the repository;
  2. Place a build.sbt file at the root of the created directory;

For now, support for build systems other than sbt is not expected

For now, we assume that each subproject has an sbt configuration. The build script will run each subproject that has some changes.


Structure of the project

The project could have any convenient structure, except it should have a build.sbt file at the root. Also, we assume that project follows SBT guidelines.


SBT basics

SBT is the build tool for Scala, that allows you to manage your dependencies and building process.

To allow your project to use SBT you should create a so-called build definition that is defined in build.sbt. In this file, you can specify dependencies for your project and describe the build process itself.

The very minimalistic version of build definition is:

build.sbt
name := "Your project name"

version := "0.1"

scalaVersion := "2.12.3"

libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.0-RC1"

Here we define a new project with a Cats library dependency.

The next step you would like to do is to start sbt command and run some tasks, like:

  • compile - compiles the whole project
  • test - run test suites

To learn more about sbt please visit http://www.scala-sbt.org/1.x/docs/Getting-Started.html

To learn more about testing in sbt please visit http://www.scala-sbt.org/1.0/docs/Testing.html

CI process

A quick description of the CI process is:

  1. Travis watch for github PR/merge hooks;
  2. When notification received, Travis starts a build process that is described in .travis.yaml file;
  3. The build runs a build script, that will try to figure out which directories have changed;
  4. Then script tries to treat these directories as projects and run the "sbt compile test" command;
  5. Based on output script can determine build as successful or failed;
The draft implementation of the build script
#!/bin/bash

COUNT=0

#list subdirectories
for d in */ ; do
    #check for sbt subproject
    if [ -f "$d/build.sbt" ]
    then
        #check for changes
        if git diff --name-only HEAD^ | grep "$d" > /dev/null 
        then
            DIFF[COUNT]="$d"
            COUNT=$((COUNT+1))
        fi
    fi
done

#run test for all subprojects with changes
for i in ${DIFF[@]}; do
    echo "Run sbt"
    cd "$i"
    sbt test
    cd ../
done