<commit_before>#!/bin/bash

# Single source of truth for building Rawls.
# @ <NAME>
#
# Provide command line options to do one or several things:
#   jar : build rawls jar
#   publish : run rawls/core/src/bin/publishSnapshot.sh to publish to Artifactory
#   -d | --docker : provide arg either "build" or "push", to build and push docker image
# Jenkins build job should run with all options, for example,
#   ./docker/build.sh jar publish -d push

set -ex
PROJECT=rawls

function make_jar()
{
    echo "building jar..."
    bash ./docker/run-mysql.sh start
    bash ./docker/run-opendj.sh start

    # Get the last commit hash of the model directory and set it as an environment variable
    GIT_MODEL_HASH=$(git log -n 1 --pretty=format:%h model)

    # make jar.  cache sbt dependencies. capture output and stop db before returning.
    JAR_CMD=`docker run --rm --link mysql:mysql --link opendj:opendj -e GIT_MODEL_HASH=$GIT_MODEL_HASH -v $PWD:/working -v jar-cache:/root/.ivy -v jar-cache:/root/.ivy2 broadinstitute/scala-baseimage /working/docker/install.sh /working`
    EXIT_CODE=$?

    # stop mysql and opendj
    bash ./docker/run-mysql.sh stop
    bash ./docker/run-opendj.sh stop

    # if tests were a fail, fail script
    if [ $EXIT_CODE != 0 ]; then
        exit $EXIT_CODE
    fi
}

function artifactory_push()
{
    echo "Publishing to artifactory..."
    docker run --rm -v $PWD:/$PROJECT -v jar-cache:/root/.ivy -v jar-cache:/root/.ivy2 -w="/$PROJECT" -e ARTIFACTORY_USERNAME=$ARTIFACTORY_USERNAME -e ARTIFACTORY_PASSWORD=$ARTIFACTORY_PASSWORD broadinstitute/scala-baseimage:scala-2.11.8 /$PROJECT/core/src/bin/publishSnapshot.sh
}

function docker_cmd()
{
    if [ $DOCKER_CMD = "build" ] || [ $DOCKER_CMD = "push" ]; then
        echo "building $PROJECT docker image..."
        if [ "$ENV" != "dev" ] && [ "$ENV" != "alpha" ] && [ "$ENV" != "staging" ] && [ "$ENV" != "perf" ]; then
            DOCKER_TAG=${BRANCH}
        else
            GIT_SHA=$(git rev-parse origin/${BRANCH})
            DOCKER_TAG=${GIT_SHA:0:12}
        fi
        echo "building $PROJECT-tests docker image..."
        docker build -t $REPO:${DOCKER_TAG} .
        cd automation
        docker build -f Dockerfile-tests -t $TESTS_REPO:${DOCKER_TAG} .<commit_msg>save git sha during build script<commit_after>#!/bin/bash

# Single source of truth for building Rawls.
# @ <NAME>
#
# Provide command line options to do one or several things:
#   jar : build rawls jar
#   publish : run rawls/core/src/bin/publishSnapshot.sh to publish to Artifactory
#   -d | --docker : provide arg either "build" or "push", to build and push docker image
# Jenkins build job should run with all options, for example,
#   ./docker/build.sh jar publish -d push

set -ex
PROJECT=rawls

function make_jar()
{
    echo "building jar..."
    bash ./docker/run-mysql.sh start
    bash ./docker/run-opendj.sh start

    # Get the last commit hash of the model directory and set it as an environment variable
    GIT_MODEL_HASH=$(git log -n 1 --pretty=format:%h model)

    # make jar.  cache sbt dependencies. capture output and stop db before returning.
    JAR_CMD=`docker run --rm --link mysql:mysql --link opendj:opendj -e GIT_MODEL_HASH=$GIT_MODEL_HASH -v $PWD:/working -v jar-cache:/root/.ivy -v jar-cache:/root/.ivy2 broadinstitute/scala-baseimage /working/docker/install.sh /working`
    EXIT_CODE=$?

    # stop mysql and opendj
    bash ./docker/run-mysql.sh stop
    bash ./docker/run-opendj.sh stop

    # if tests were a fail, fail script
    if [ $EXIT_CODE != 0 ]; then
        exit $EXIT_CODE
    fi
}

function artifactory_push()
{
    echo "Publishing to artifactory..."
    docker run --rm -v $PWD:/$PROJECT -v jar-cache:/root/.ivy -v jar-cache:/root/.ivy2 -w="/$PROJECT" -e ARTIFACTORY_USERNAME=$ARTIFACTORY_USERNAME -e ARTIFACTORY_PASSWORD=$ARTIFACTORY_PASSWORD broadinstitute/scala-baseimage:scala-2.11.8 /$PROJECT/core/src/bin/publishSnapshot.sh
}

function docker_cmd()
{
    if [ $DOCKER_CMD = "build" ] || [ $DOCKER_CMD = "push" ]; then
        echo "building $PROJECT docker image..."
        if [ "$ENV" != "dev" ] && [ "$ENV" != "alpha" ] && [ "$ENV" != "staging" ] && [ "$ENV" != "perf" ]; then
            DOCKER_TAG=${BRANCH}
        else
            GIT_SHA=$(git rev-parse origin/${BRANCH})
            echo GIT_SHA=$GIT_SHA > env.properties
            DOCKER_TAG=${GIT_SHA:0:12}
        fi
        echo "building $PROJECT-tests docker image..."
        docker build -t $REPO:${DOCKER_TAG} .
        cd automation
        docker build -f Dockerfile-tests -t $TESTS_REPO:${DOCKER_TAG} .
{'fraction_non_alphanumeric': 0.1328397212543554, 'fraction_numerical': 0.004790940766550522, 'mean_word_length': 2.8759493670886074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2525327', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1543, 'n_words': 446}