blob: 7c1aebe89d896ac4ce085942d84b58059bb5ed9e [file] [log] [blame]
avm9996303d54092020-01-18 21:33:16 +01001#!/bin/bash
2
3# Prints help text
avm99963666575f2020-08-08 15:40:39 +02004function usage {
avm9996303d54092020-01-18 21:33:16 +01005 cat << END
avm99963666575f2020-08-08 15:40:39 +02006
avm9996303d54092020-01-18 21:33:16 +01007 Usage: $progname [--channel CHANNEL]
8
9 optional arguments:
10 -h, --help show this help message and exit
11 -c, --channel indicates the channel of the release. Can be "beta" or "stable".
12
13END
14}
15
avm99963666575f2020-08-08 15:40:39 +020016# Updates manifest.json field
17function set_manifest_field {
18 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
19}
20
avm9996303d54092020-01-18 21:33:16 +010021# Get options
22opts=$(getopt -l "help,channel:" -o "hc:" -n "$progname" -- "$@")
23eval set -- "$opts"
24
25channel=stable
26
27while true; do
28 case "$1" in
29 -h | --help ) usage; exit; ;;
30 -c | --channel ) channel="$2"; shift 2 ;;
31 * ) break ;;
32 esac
33done
34
35if [[ $channel != "stable" && $channel != "beta" ]]; then
36 echo "channel parameter value is incorrect."
37 usage
38 exit
39fi
40
41echo "Started building release..."
42
avm99963666575f2020-08-08 15:40:39 +020043# This is the version name which git gives us
44version=$(git describe --always --tags --dirty)
45
46# If the version name contains a hyphen then it isn't a release
47# version. This is also the case if it doesn't start with a "v".
48if [[ $version == *"-"* || $version != "v"* ]]; then
49 # As it isn't a release version, setting version number to 0 so it
50 # cannot be uploaded to the Chrome Web Store
51 set_manifest_field "version" "0"
52 set_manifest_field "version_name" "$version-$channel"
53else
54 # It is a release version, set the version fields accordingly.
55 set_manifest_field "version" "${version:1}"
56 set_manifest_field "version_name" "${version:1}-$channel"
57fi
58
avm9996303d54092020-01-18 21:33:16 +010059if [[ $channel == "beta" ]]; then
60 # Change manifest.json to label the release as beta
avm99963666575f2020-08-08 15:40:39 +020061 set_manifest_field "name" "__MSG_appNameBeta__"
avm9996303d54092020-01-18 21:33:16 +010062fi
63
64# Create ZIP file for upload to the Chrome Web Store
65mkdir -p out
avm99963bf0849a2020-08-08 16:16:04 +020066rm -rf out/twpowertools-$version-$channel.zip
67zip -rq out/twpowertools-$version-$channel.zip src -x *.git*
avm9996303d54092020-01-18 21:33:16 +010068
avm99963666575f2020-08-08 15:40:39 +020069# Revert manifest.json changes
70set_manifest_field "version" "0"
71set_manifest_field "version_name" "dirty"
avm9996303d54092020-01-18 21:33:16 +010072if [[ $channel == "beta" ]]; then
avm99963666575f2020-08-08 15:40:39 +020073 set_manifest_field "name" "__MSG_appName__"
avm9996303d54092020-01-18 21:33:16 +010074fi
75
76echo "Done!"