Change the release system to a tag-based system

Before, releases were created by commiting a change to the manifest.json
file which updated the "version" field.

This commit changes this procedure by generating the version strings
directly in the release.bash script with the "git describe" command,
based on annotated Git tags.

Change-Id: I4de4e1040b7e9d22b4d3c8df9c0870989d966c49
diff --git a/release.bash b/release.bash
index f1e89fd..4e6a436 100644
--- a/release.bash
+++ b/release.bash
@@ -1,9 +1,9 @@
 #!/bin/bash
 
 # Prints help text
-function usage() {
+function usage {
   cat << END
-  
+
   Usage: $progname [--channel CHANNEL]
 
   optional arguments:
@@ -13,6 +13,11 @@
 END
 }
 
+# Updates manifest.json field
+function set_manifest_field {
+  sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
+}
+
 # Get options
 opts=$(getopt -l "help,channel:" -o "hc:" -n "$progname" -- "$@")
 eval set -- "$opts"
@@ -35,10 +40,25 @@
 
 echo "Started building release..."
 
+# This is the version name which git gives us
+version=$(git describe --always --tags --dirty)
+
+# If the version name contains a hyphen then it isn't a release
+# version. This is also the case if it doesn't start with a "v".
+if [[ $version == *"-"* || $version != "v"* ]]; then
+  # As it isn't a release version, setting version number to 0 so it
+  # cannot be uploaded to the Chrome Web Store
+  set_manifest_field "version" "0"
+  set_manifest_field "version_name" "$version-$channel"
+else
+  # It is a release version, set the version fields accordingly.
+  set_manifest_field "version" "${version:1}"
+  set_manifest_field "version_name" "${version:1}-$channel"
+fi
+
 if [[ $channel == "beta" ]]; then
   # Change manifest.json to label the release as beta
-  sed -i 's/"name": "[^"]*"/"name": "__MSG_appNameBeta__"/' src/manifest.json
-  sed -i -r 's/"version": "([^"]*)",/"version": "\1",\n  "version_name": "\1-beta",/' src/manifest.json
+  set_manifest_field "name" "__MSG_appNameBeta__"
 fi
 
 # Create ZIP file for upload to the Chrome Web Store
@@ -46,10 +66,11 @@
 rm -rf out/infinitegforums-$channel.zip
 zip -rq out/infinitegforums-$channel.zip src -x *.git*
 
+# Revert manifest.json changes
+set_manifest_field "version" "0"
+set_manifest_field "version_name" "dirty"
 if [[ $channel == "beta" ]]; then
-  # Revert manifest.json changes
-  sed -i 's/"name": "[^"]*"/"name": "__MSG_appName__"/' src/manifest.json
-  sed -i '/"version_name"/d' src/manifest.json
+  set_manifest_field "name" "__MSG_appName__"
 fi
 
 echo "Done!"