<commit_before>#!/bin/bash

### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "master" ]];
then
  echo ">> This script must be run under \`master\` branch"
  exit
fi

DIRNAME=`pwd`

### Releasing
current=`grep -oP "version\": \"\d+.\d+.\d+((a|b)[0-9]+)?" package.json | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
echo "Current version: $current"
currentAndroid=`grep -oP "android-versionCode=\"[0-9]+\"" config.xml | grep -oP "\d+"`
echo "Current Android version: $currentAndroid"

if [[ $2 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ && $3 =~ ^[0-9]+$ ]]; then

  echo "new build version: $2"
  echo "new build android version: $3"
  case "$1" in
    rel|pre)
       # Change the version in package.json and test file
      sed -i "s/version\": \"$current\"/version\": \"$2\"/g" package.json
        currentConfigXmlVersion=`grep -oP "version=\"\d+.\d+.\d+((a|b)[0-9]+)?\"" config.xml | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
      sed -i "s/ version=\"$currentConfigXmlVersion\"/ version=\"$2\"/g" config.xml
      sed -i "s/ android-versionCode=\"$currentAndroid\"/ android-versionCode=\"$3\"/g" config.xml

      # Bump the install.sh
      sed -i "s/echo \"v.*\" #lastest/echo \"v$2\" #lastest/g" install.sh
      ;;
    *)
      echo "No task given"
      ;;
  esac


  # force nodejs version to 5
  if [ -d "$NVM_DIR" ]; then
    . $NVM_DIR/nvm.sh
    nvm use 5
  else
    echo "nvm (Node version manager) not found (directory $NVM_DIR not found). Please install, and retry"
    exit -1
  fi

  # Update config file
  gulp config --env default

  echo "----------------------------------"
  echo "- Building Android artifact..."
  echo "----------------------------------"
  gulp
  ionic build android --release
  #ionic build firefoxos --release

  echo "----------------------------------"
  echo "- Building web artifact..."
  echo "----------------------------------"

  # Update config file
  gulp build:web --release

  #ionic build ubuntu --release
  #cd platforms/ubuntu/native/gchange; debuild
  #cd $DIRNAME

  echo "----------------------------------"
  echo "- Executing git push, with tag: v$2"
  echo "----------------------------------"

  # Commit
  git reset HEAD
  git add package.json config.xml install.sh www/js/config.js
  git commit -m "v$2"
  git tag "v$2"
  git push

  if [[ $4 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && "_$5" != "_" ]]; then
      echo "**********************************"
      echo "* Uploading artifact to Github..."
      echo "**********************************"

      ./github.sh $1 $4 "'"$5"'"

      echo "----------------------------------"
      echo "- Building desktop versions..."
      echo "----------------------------------"

      git submodule update --init
      git submodule sync
      cd platforms/desktop

      # Exclude Windows - TODO FIXME (not enough space in BL directories)
      EXPECTED_ASSETS="gchange-desktop-v$2-linux-x64.deb
gchange-desktop-v$2-linux-x64.tar.gz"

      ./release.sh $2

      # back to nodejs version 5
      cd $DIRNAME
      nvm use 5<commit_msg>fix release script (limit desktop builds to defined assets)<commit_after>#!/bin/bash

### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "master" ]];
then
  echo ">> This script must be run under \`master\` branch"
  exit
fi

DIRNAME=`pwd`

### Releasing
current=`grep -oP "version\": \"\d+.\d+.\d+((a|b)[0-9]+)?" package.json | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
echo "Current version: $current"
currentAndroid=`grep -oP "android-versionCode=\"[0-9]+\"" config.xml | grep -oP "\d+"`
echo "Current Android version: $currentAndroid"

if [[ $2 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ && $3 =~ ^[0-9]+$ ]]; then

  echo "new build version: $2"
  echo "new build android version: $3"
  case "$1" in
    rel|pre)
       # Change the version in package.json and test file
      sed -i "s/version\": \"$current\"/version\": \"$2\"/g" package.json
        currentConfigXmlVersion=`grep -oP "version=\"\d+.\d+.\d+((a|b)[0-9]+)?\"" config.xml | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
      sed -i "s/ version=\"$currentConfigXmlVersion\"/ version=\"$2\"/g" config.xml
      sed -i "s/ android-versionCode=\"$currentAndroid\"/ android-versionCode=\"$3\"/g" config.xml

      # Bump the install.sh
      sed -i "s/echo \"v.*\" #lastest/echo \"v$2\" #lastest/g" install.sh
      ;;
    *)
      echo "No task given"
      ;;
  esac


  # force nodejs version to 5
  if [ -d "$NVM_DIR" ]; then
    . $NVM_DIR/nvm.sh
    nvm use 5
  else
    echo "nvm (Node version manager) not found (directory $NVM_DIR not found). Please install, and retry"
    exit -1
  fi

  # Update config file
  gulp config --env default

  echo "----------------------------------"
  echo "- Building Android artifact..."
  echo "----------------------------------"
  gulp
  ionic build android --release
  #ionic build firefoxos --release

  echo "----------------------------------"
  echo "- Building web artifact..."
  echo "----------------------------------"

  # Update config file
  gulp build:web --release

  #ionic build ubuntu --release
  #cd platforms/ubuntu/native/gchange; debuild
  #cd $DIRNAME

  echo "----------------------------------"
  echo "- Executing git push, with tag: v$2"
  echo "----------------------------------"

  # Commit
  git reset HEAD
  git add package.json config.xml install.sh www/js/config.js
  git commit -m "v$2"
  git tag "v$2"
  git push

  if [[ $4 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && "_$5" != "_" ]]; then
      echo "**********************************"
      echo "* Uploading artifact to Github..."
      echo "**********************************"

      ./github.sh $1 $4 "'"$5"'"

      echo "----------------------------------"
      echo "- Building desktop versions..."
      echo "----------------------------------"

      git submodule update --init
      git submodule sync
      cd platforms/desktop

      # Exclude Windows - TODO FIXME (not enough space in BL directories)
      EXPECTED_ASSETS="gchange-desktop-v$2-linux-x64.deb
gchange-desktop-v$2-linux-x64.tar.gz"
      export EXPECTED_ASSETS

      ./release.sh $2

      # back to nodejs version 5
      cd $DIRNAME
      nvm use 5
{'fraction_non_alphanumeric': 0.2726837824908308, 'fraction_numerical': 0.01690320523042577, 'mean_word_length': 1.9598867390278434, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '2909884', 'n_tokens_mistral': 2158, 'n_tokens_neox': 2035, 'n_words': 575}