<commit_before>#!/usr/bin/env bash
set -eE
set -o pipefail

# Figure out where the script lives
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC=$DIR/..

# These are our input variables
TARGET_REF=$1
ENVIRONMENT=$2

USAGE_STR="Usage: bash release.sh <target-ref> <environment>"
if [ -z "$TARGET_REF" -o -z "$ENVIRONMENT" ]; then
    echo "Usage: bash release.sh <target-ref> <environment>"
    exit 1
fi

GIT_REPOSITORY="<EMAIL>:arigatomachine/cli.git"
KEY_FILE="$SRC/keys/$ENVIRONMENT.json"
RELEASE_STAMP=`date -u +"%Y-%m-%dT%H-%M-%SZ"`
BUILD_DIRECTORY=$HOME/build
RELEASE_DIRECTORY="$BUILD_DIRECTORY/$RELEASE_STAMP"

if [ ! -f "$KEY_FILE" ]; then
    echo "Cannot find offline public key file: $KEY_FILE"
    exit 1
fi

if [ ! -d "$BUILD_DIRECTORY" ]; then
    echo "Build directory $BUILD_DIRECTORY does not exist; creating."
    mkdir -p $BUILD_DIRECTORY
fi

# Fetch the latest greatest and then figure out the pointer of the tag
echo "Attempting to resolve $TARGET_REF to SHA"
git fetch
TARGET_SHA=`git rev-list -n 1 refs/heads/$TARGET_REF`
echo "Resoled $TARGET_REF to $TARGET_SHA"

echo "Changing CWD to $BUILD_DIRECTORY"
cd $BUILD_DIRECTORY

echo "Cloning repository into $BUILD_DIRECTORY/$RELEASE_STAMP"
git clone --reference $SRC $GIT_REPOSITORY $RELEASE_STAMP

echo "Switching into $RELEASE_DIRECTORY"
cd "$RELEASE_DIRECTORY"
git checkout $TARGET_SHA

echo ""
echo "Building Docker Container"
echo ""
docker build -t arigato/cli:$TARGET_SHA .

echo ""
echo "Building Daemon"
echo ""
docker run --name relase-builder --rm \
    -v $RELEASE_DIRECTORY:/go/src/github.com/arigatomachine/cli \
    -v $RELEASE_DIRECTORY/builds:/builds \
    arigato/cli:$TARGET_SHA \
    release

echo ""
echo "Copying Key File"
echo ""
cp $KEY_FILE cli/public_key.json

echo ""
echo "Creating Distributable ($RELEASE_STAMP.tar.gz) in $RELEASE_DIRECTORY"
echo ""
tar czf "$RELEASE_STAMP.tar.gz" cli/

read -p "Do you wish to publish to npm? [yn] " publish
case $publish in
    [Yy]* )
        npm publish $RELEASE_STAMP.tar.gz
        ;;
    * )
        echo "Not publishing"
        ;;
esac

echo ""
echo "Done; package $RELEASE_DIRECTORY/$RELEASE_STAMP.tar.gz"
echo ""
<commit_msg>CA Bundled up during Release<commit_after>#!/usr/bin/env bash
set -eE
set -o pipefail

# Figure out where the script lives
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRC=$DIR/..

# These are our input variables
TARGET_REF=$1
ENVIRONMENT=$2

USAGE_STR="Usage: bash release.sh <target-ref> <environment>"
if [ -z "$TARGET_REF" -o -z "$ENVIRONMENT" ]; then
    echo "Usage: bash release.sh <target-ref> <environment>"
    exit 1
fi

GIT_REPOSITORY="<EMAIL>:arigatomachine/cli.git"
KEY_FILE="$SRC/keys/$ENVIRONMENT.json"
CA_BUNDLE="$SRC/daemon/ca_bundle.pem"
RELEASE_STAMP=`date -u +"%Y-%m-%dT%H-%M-%SZ"`
BUILD_DIRECTORY=$HOME/build
RELEASE_DIRECTORY="$BUILD_DIRECTORY/$RELEASE_STAMP"

if [ ! -f "$KEY_FILE" ]; then
    echo "Cannot find offline public key file: $KEY_FILE"
    exit 1
fi

if [ ! -d "$BUILD_DIRECTORY" ]; then
    echo "Build directory $BUILD_DIRECTORY does not exist; creating."
    mkdir -p $BUILD_DIRECTORY
fi

# Fetch the latest greatest and then figure out the pointer of the tag
echo "Attempting to resolve $TARGET_REF to SHA"
git fetch
TARGET_SHA=`git rev-list -n 1 refs/heads/$TARGET_REF`
echo "Resoled $TARGET_REF to $TARGET_SHA"

echo "Changing CWD to $BUILD_DIRECTORY"
cd $BUILD_DIRECTORY

echo "Cloning repository into $BUILD_DIRECTORY/$RELEASE_STAMP"
git clone --reference $SRC $GIT_REPOSITORY $RELEASE_STAMP

echo "Switching into $RELEASE_DIRECTORY"
cd "$RELEASE_DIRECTORY"
git checkout $TARGET_SHA

echo ""
echo "Building Docker Container"
echo ""
docker build -t arigato/cli:$TARGET_SHA .

echo ""
echo "Building Daemon"
echo ""
docker run --name relase-builder --rm \
    -v $RELEASE_DIRECTORY:/go/src/github.com/arigatomachine/cli \
    -v $RELEASE_DIRECTORY/builds:/builds \
    arigato/cli:$TARGET_SHA \
    release

echo ""
echo "Copying Key File"
echo ""
cp $KEY_FILE cli/public_key.json
cp $CA_BUNDLE cli/ca_bundle.pem

echo ""
echo "Creating Distributable ($RELEASE_STAMP.tar.gz) in $RELEASE_DIRECTORY"
echo ""
tar czf "$RELEASE_STAMP.tar.gz" cli/

read -p "Do you wish to publish to npm? [yn] " publish
case $publish in
    [Yy]* )
        npm publish $RELEASE_STAMP.tar.gz
        ;;
    * )
        echo "Not publishing"
        ;;
esac

echo ""
echo "Done; package $RELEASE_DIRECTORY/$RELEASE_STAMP.tar.gz"
echo ""

{'fraction_non_alphanumeric': 0.12895978431813077, 'fraction_numerical': 0.0026960233655358348, 'mean_word_length': 4.152777777777778, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6094214', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1565, 'n_words': 448}