release.sh 4.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/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)
25
      # Change the version in files: 'package.json' and 'config.xml'
26
      sed -i "s/version\": \"$current\"/version\": \"$2\"/g" package.json
27
      currentConfigXmlVersion=`grep -oP "version=\"\d+.\d+.\d+((a|b)[0-9]+)?\"" config.xml | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
28 29
      sed -i "s/ version=\"$currentConfigXmlVersion\"/ version=\"$2\"/g" config.xml
      sed -i "s/ android-versionCode=\"$currentAndroid\"/ android-versionCode=\"$3\"/g" config.xml
30

31 32 33 34
      # Change version in file: 'www/manifest.json'
      currentManifestJsonVersion=`grep -oP "version\": \"\d+.\d+.\d+((a|b)[0-9]+)?\"" www/manifest.json | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
      sed -i "s/version\": \"$currentManifestJsonVersion\"/version\": \"$2\"/g" www/manifest.json

35 36 37 38 39 40 41 42
      # Bump the install.sh
      sed -i "s/echo \"v.*\" #lastest/echo \"v$2\" #lastest/g" install.sh
      ;;
    *)
      echo "No task given"
      ;;
  esac

Benoit Lavenier's avatar
Benoit Lavenier committed
43 44 45 46 47 48 49 50 51
  # 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

52 53 54
  # Update config file
  gulp config --env default

Benoit Lavenier's avatar
Benoit Lavenier committed
55
  echo "----------------------------------"
56
  echo "- Compiling sources..."
Benoit Lavenier's avatar
Benoit Lavenier committed
57
  echo "----------------------------------"
Benoit Lavenier's avatar
Benoit Lavenier committed
58
  gulp
59 60 61 62

  echo "----------------------------------"
  echo "- Building Android artifact..."
  echo "----------------------------------"
63
  ionic build android --release
64

65 66
  #ionic build firefoxos --release

Benoit Lavenier's avatar
Benoit Lavenier committed
67
  echo "----------------------------------"
Benoit Lavenier's avatar
Benoit Lavenier committed
68
  echo "- Building web artifact..."
Benoit Lavenier's avatar
Benoit Lavenier committed
69 70
  echo "----------------------------------"

71 72 73 74
  gulp build:web --release

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

Benoit Lavenier's avatar
Benoit Lavenier committed
77 78 79
  echo "----------------------------------"
  echo "- Executing git push, with tag: v$2"
  echo "----------------------------------"
80 81 82

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

Benoit Lavenier's avatar
Benoit Lavenier committed
88 89
  if [[ $4 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && "_$5" != "_" ]]; then
      echo "**********************************"
90
      echo "* Uploading artifacts to Github..."
Benoit Lavenier's avatar
Benoit Lavenier committed
91 92 93
      echo "**********************************"

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

Benoit Lavenier's avatar
Benoit Lavenier committed
95 96 97 98
      echo "----------------------------------"
      echo "- Building desktop versions..."
      echo "----------------------------------"

99 100 101
      # Remove old vagrant virtual machines
      rm -rf ~/.vagrant.d/*

Benoit Lavenier's avatar
Benoit Lavenier committed
102 103 104 105 106 107 108
      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"
109
      export EXPECTED_ASSETS
Benoit Lavenier's avatar
Benoit Lavenier committed
110 111 112 113 114 115 116

      ./release.sh $2

      # back to nodejs version 5
      cd $DIRNAME
      nvm use 5

117 118 119
    echo "**********************************"
    echo "* Build release succeed !"
    echo "**********************************"
120
  else
121 122 123 124 125

    echo "**********************************"
    echo "* Build release succeed !"
    echo "**********************************"

126 127 128 129 130
    echo " WARN - missing arguments: "
    echo "       user:password 'release_description'"
    echo
    echo "   Binaries files NOT sending to github repository"
    echo "   Please run:"
131 132 133 134 135
    echo "   > ./github.sh pre|rel user:password 'release_description'"
    echo
    echo "   Desktop artifact are NOT build"
    echo "   Please run:"
    echo "   > platforms/desktop/release.sh <version>"
136 137 138 139 140 141 142 143 144 145 146 147 148
    echo
  fi

else
  echo "Wrong version format"
  echo "Usage:"
  echo " > ./release.sh [pre|rel] <version> <android-version> <github_credentials>"
  echo "with:"
  echo "  version: x.y.z"
  echo "  android-version: nnn"
  echo "  github_credentials: user:password  (a valid GitHub user account)"
fi