<commit_before>#!/bin/bash
#
# build.sh compiles dnote binary for target platforms
# it is resonsible for creating distributable files that can
# be released by a human or a script
# use: ./scripts/build.sh 0.4.8

set -eu

version="$1"
basedir="$GOPATH/src/github.com/dnote/cli"
TMP="$basedir/build"

command_exists () {
  command -v "$1" >/dev/null 2>&1;
}

if ! command_exists shasum; then
  echo "please install shasum"
  exit 1
fi
if [ $# -eq 0 ]; then
  echo "no version specified."
  exit 1
fi
if [[ $1 == v* ]]; then
  echo "do not prefix version with v"
  exit 1
fi

build() {
  # init build dir
  rm -rf "$TMP"
  mkdir "$TMP"

  # fetch tool
  go get -u github.com/karalabe/xgo

  pushd "$basedir"

  # TODO: do i need to pass fts5 tag?

  # build linux
  xgo --targets="linux/amd64"\
    -ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
  mkdir "$TMP/linux"
  mv cli-linux-amd64 "$TMP/linux/dnote"

  # build darwin
  xgo --targets="darwin/amd64"\
    -ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
  mkdir "$TMP/darwin"
  mv cli-darwin-10.6-amd64 "$TMP/darwin/dnote"

  # build windows
  xgo --targets="windows/amd64"\
    -ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
  mkdir "$TMP/windows"
  mv cli-windows-4.0-amd64.exe "$TMP/windows/dnote.exe"

  popd
}

get_buildname() {
  os=$1

  echo "dnote_${version}_${os}_amd64"
}

calc_checksum() {
  os=$1

  pushd "$TMP/$os"

  buildname=$(get_buildname "$os")
  mv dnote "$buildname"
  shasum -a 256 "$buildname" >> "$TMP/dnote_${version}_checksums.txt"
  mv "$buildname" dnote

  popd
}

build_tarball() {
  os=$1
  buildname=$(get_buildname "$os")
<commit_msg>Fix build (#152)<commit_after>#!/bin/bash
#
# build.sh compiles dnote binary for target platforms
# it is resonsible for creating distributable files that can
# be released by a human or a script
# use: ./scripts/build.sh 0.4.8

set -eu

version="$1"
basedir="$GOPATH/src/github.com/dnote/cli"
TMP="$basedir/build"

command_exists () {
  command -v "$1" >/dev/null 2>&1;
}

if ! command_exists shasum; then
  echo "please install shasum"
  exit 1
fi
if [ $# -eq 0 ]; then
  echo "no version specified."
  exit 1
fi
if [[ $1 == v* ]]; then
  echo "do not prefix version with v"
  exit 1
fi

build() {
  # init build dir
  rm -rf "$TMP"
  mkdir "$TMP"

  # fetch tool
  go get -u github.com/karalabe/xgo

  pushd "$basedir"

  # build linux
  xgo --targets="linux/amd64"\
    --tags "linux fts5"\
    -ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
  mkdir "$TMP/linux"
  mv cli-linux-amd64 "$TMP/linux/dnote"

  # build darwin
  xgo --targets="darwin/amd64"\
    --tags "darwin fts5"\
    -ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
  mkdir "$TMP/darwin"
  mv cli-darwin-10.6-amd64 "$TMP/darwin/dnote"

  # build windows
  xgo --targets="windows/amd64"\
    --tags "fts5"\
    -ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
  mkdir "$TMP/windows"
  mv cli-windows-4.0-amd64.exe "$TMP/windows/dnote.exe"

  popd
}

get_buildname() {
  os=$1

  echo "dnote_${version}_${os}_amd64"
}

calc_checksum() {
  os=$1

  pushd "$TMP/$os"

  buildname=$(get_buildname "$os")
  mv dnote "$buildname"
  shasum -a 256 "$buildname" >> "$TMP/dnote_${version}_checksums.txt"
  mv "$buildname" dnote

  popd
}

build_tarball() {
  os=$1
  buildname=$(get_buildname "$os")

{'fraction_non_alphanumeric': 0.16207687894434883, 'fraction_numerical': 0.02323580034423408, 'mean_word_length': 3.2420924574209247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 6, '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': '5784497', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1367, 'n_words': 340}