release.sh 5.08 KB
Newer Older
Benoit Lavenier's avatar
Benoit Lavenier committed
1
#!/bin/bash
2

Benoit Lavenier's avatar
Benoit Lavenier committed
3 4 5 6 7
### 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"
8
  exit -1
Benoit Lavenier's avatar
Benoit Lavenier committed
9 10
fi

11
DIRNAME=`pwd`
Benoit Lavenier's avatar
Benoit Lavenier committed
12

13
### Get current version (package.json)
Benoit Lavenier's avatar
Benoit Lavenier committed
14
current=`grep -oP "version\": \"\d+.\d+.\d+((a|b)[0-9]+)?" package.json | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
15 16 17 18
if [[ "_$current" == "_" ]]; then
  echo "Unable to get current version. Please check version format is: x.y.z (x and y should be an integer)."
  exit -1;
fi
Benoit Lavenier's avatar
Benoit Lavenier committed
19
echo "Current version: $current"
20 21

### Get current version for Android
Benoit Lavenier's avatar
Benoit Lavenier committed
22
currentAndroid=`grep -oP "android-versionCode=\"[0-9]+\"" config.xml | grep -oP "\d+"`
23 24 25 26
if [[ "_$currentAndroid" == "_" ]]; then
  echo "Unable to get current Android version. Please check version format is an integer."
  exit -1;
fi
Benoit Lavenier's avatar
Benoit Lavenier committed
27 28
echo "Current Android version: $currentAndroid"

29
### Releasing
Benoit Lavenier's avatar
Benoit Lavenier committed
30
if [[ $2 =~ ^[0-9]+.[0-9]+.[0-9]+((a|b)[0-9]+)?$ && $3 =~ ^[0-9]+$ ]]; then
Benoit Lavenier's avatar
Benoit Lavenier committed
31

32 33
  echo "new build version: $2"
  echo "new build android version: $3"
Benoit Lavenier's avatar
Benoit Lavenier committed
34 35
  case "$1" in
    rel|pre)
36 37
      # Change the version in files: 'package.json' and 'config.xml'
      sed -i "s/version\": \"$current\"/version\": \"$2\"/g" package.json
38
      currentConfigXmlVersion=`grep -oP "version=\"\d+.\d+.\d+((a|b)[0-9]+)?\"" config.xml | grep -oP "\d+.\d+.\d+((a|b)[0-9]+)?"`
39 40 41 42 43 44
      sed -i "s/ version=\"$currentConfigXmlVersion\"/ version=\"$2\"/g" config.xml
      sed -i "s/ android-versionCode=\"$currentAndroid\"/ android-versionCode=\"$3\"/g" config.xml

      # 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
Benoit Lavenier's avatar
Benoit Lavenier committed
45 46

      # Bump the install.sh
Benoit Lavenier's avatar
Benoit Lavenier committed
47
      sed -i "s/echo \"v.*\" #lastest/echo \"v$2\" #lastest/g" install.sh
Benoit Lavenier's avatar
Benoit Lavenier committed
48 49 50
      ;;
    *)
      echo "No task given"
51
      exit -1
Benoit Lavenier's avatar
Benoit Lavenier committed
52 53 54
      ;;
  esac

55
  # Load env.sh if exists
56
  if [[ -f "${DIRNAME}/env.sh" ]]; then
57
    source ${DIRNAME}/env.sh $*
58 59
  fi

60 61 62 63 64 65 66 67 68 69 70 71 72 73
  # Check the Java version
  JAVA_VERSION=`java -version 2>&1 | grep "java version" | awk '{print $3}' | tr -d \"`
  if [[ $? -ne 0 ]]; then
    echo "No Java JRE 1.8 found in machine. This is required for Android artifacts."
    exit -1
  fi
  JAVA_MINOR_VERSION=`echo ${JAVA_VERSION} | awk '{split($0, array, ".")} END{print array[2]}'`
  if [[ ${JAVA_MINOR_VERSION} -ne 8 ]]; then
    echo "Require a Java JRE in version 1.8, but found ${JAVA_VERSION}. You can override your default JAVA_HOME in 'env.sh'."
    exit -1
  fi
  echo "Java: $JAVA_VERSION"


74
  # force nodejs version to 5
75
  if [[ -d "$NVM_DIR" ]]; then
76 77
    . $NVM_DIR/nvm.sh
    nvm use 5
78
    if [[ $? -ne 0 ]]; then
79 80
      exit -1
    fi
81 82 83 84 85
  else
    echo "nvm (Node version manager) not found (directory $NVM_DIR not found). Please install, and retry"
    exit -1
  fi

86
  # Update config file
87
  gulp config --env default_fr
88

89
  echo "----------------------------------"
90
  echo "- Compiling sources..."
91
  echo "----------------------------------"
92
  gulp
93 94 95 96

  echo "----------------------------------"
  echo "- Building Android artifact..."
  echo "----------------------------------"
97
  ionic build android --release
98
  if [[ $? -ne 0 ]]; then
99 100
    exit -1
  fi
101

102 103 104 105
  echo "----------------------------------"
  echo "- Building web artifact..."
  echo "----------------------------------"

106 107
  # Update config file
  gulp config --env default
108
  gulp build:web --release
109
  if [[ $? -ne 0 ]]; then
110 111
    exit -1
  fi
112

113 114 115 116
  echo "----------------------------------"
  echo "- Executing git push, with tag: v$2"
  echo "----------------------------------"

Benoit Lavenier's avatar
Benoit Lavenier committed
117
  # Commit
118
  cd $DIRNAME
119
  git reset HEAD
120
  git add package.json config.xml install.sh www/js/config.js www/manifest.json
Benoit Lavenier's avatar
Benoit Lavenier committed
121 122
  git commit -m "v$2"
  git tag "v$2"
123
  git push
124
  if [[ $? -ne 0 ]]; then
125 126
    exit -1
  fi
127

128 129 130
  # Pause (wait propagation to from git.duniter.org to github)
  echo " Waiting 30s, for propagation to github..."
  sleep 30s
Benoit Lavenier's avatar
Benoit Lavenier committed
131

132 133 134 135 136 137 138 139
  description="$4"
  if [[ "_$description" == "_" ]]; then
     description="Release v$1"
  fi

  echo "**********************************"
  echo "* Uploading artifacts to Github..."
  echo "**********************************"
140

141
  ./github.sh $1 ''"$description"''
142
  if [[ $? -ne 0 ]]; then
143 144
      exit -1
  fi
145

146
  echo "----------------------------------"
147
  echo "- Building desktop artifacts..."
148
  echo "----------------------------------"
149

Benoit Lavenier's avatar
Benoit Lavenier committed
150

151 152
  #FIXME: ceci empêche d'etre sur le master/origin de cesium-desktop
  #git submodule update --init
153 154
  git submodule sync
  cd platforms/desktop
155

156
  # Build desktop assets
157
  ./release.sh $2
158
  if [[ $? -ne 0 ]]; then
159 160
      exit -1
  fi
161

162 163 164
  # back to nodejs version 5
  cd $DIRNAME
  nvm use 5
165

166 167 168
  echo "**********************************"
  echo "* Build release succeed !"
  echo "**********************************"
169

Benoit Lavenier's avatar
Benoit Lavenier committed
170 171 172
else
  echo "Wrong version format"
  echo "Usage:"
173
  echo " > ./release.sh [pre|rel] <version> <android-version> <release_description>"
Benoit Lavenier's avatar
Benoit Lavenier committed
174
  echo "with:"
175 176
  echo "  version: x.y.z"
  echo "  android-version: nnn"
177
  echo "  release_description: a short description of the release"
Benoit Lavenier's avatar
Benoit Lavenier committed
178 179
fi