blob: 6b8851e512167ece2e44565513184ea528c8f5b9 [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
avm999636c357302020-08-09 19:54:08 +020011 -c, --channel indicates the channel of the release. Can be "beta"
12 or "stable". Defaults to "stable".
13 -b, --browser indicates the target browser for the release. Can be
14 "chromium" or "gecko". Defaults to "chromium".
avm9996303d54092020-01-18 21:33:16 +010015
16END
17}
18
avm99963666575f2020-08-08 15:40:39 +020019# Updates manifest.json field
20function set_manifest_field {
21 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
22}
23
avm9996303d54092020-01-18 21:33:16 +010024# Get options
avm999636c357302020-08-09 19:54:08 +020025opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@")
avm9996303d54092020-01-18 21:33:16 +010026eval set -- "$opts"
27
28channel=stable
avm999636c357302020-08-09 19:54:08 +020029browser=chromium
avm9996303d54092020-01-18 21:33:16 +010030
31while true; do
32 case "$1" in
33 -h | --help ) usage; exit; ;;
34 -c | --channel ) channel="$2"; shift 2 ;;
avm999636c357302020-08-09 19:54:08 +020035 -b | --browser ) browser="$2"; shift 2 ;;
avm9996303d54092020-01-18 21:33:16 +010036 * ) break ;;
37 esac
38done
39
40if [[ $channel != "stable" && $channel != "beta" ]]; then
41 echo "channel parameter value is incorrect."
42 usage
43 exit
44fi
45
avm999636c357302020-08-09 19:54:08 +020046if [[ $browser != "chromium" && $browser != "gecko" ]]; then
47 echo "browser parameter value is incorrect."
48 usage
49 exit
50fi
51
avm9996303d54092020-01-18 21:33:16 +010052echo "Started building release..."
53
avm999636c357302020-08-09 19:54:08 +020054# First of all, generate the appropriate manifest.json file for the
55# target browser
56dependencies=( ${browser^^} )
57
58bash generateManifest.bash "${dependencies[@]}"
59
avm99963666575f2020-08-08 15:40:39 +020060# This is the version name which git gives us
61version=$(git describe --always --tags --dirty)
62
63# If the version name contains a hyphen then it isn't a release
64# version. This is also the case if it doesn't start with a "v".
65if [[ $version == *"-"* || $version != "v"* ]]; then
66 # As it isn't a release version, setting version number to 0 so it
67 # cannot be uploaded to the Chrome Web Store
68 set_manifest_field "version" "0"
69 set_manifest_field "version_name" "$version-$channel"
70else
71 # It is a release version, set the version fields accordingly.
72 set_manifest_field "version" "${version:1}"
73 set_manifest_field "version_name" "${version:1}-$channel"
74fi
75
avm9996303d54092020-01-18 21:33:16 +010076if [[ $channel == "beta" ]]; then
77 # Change manifest.json to label the release as beta
avm99963666575f2020-08-08 15:40:39 +020078 set_manifest_field "name" "__MSG_appNameBeta__"
avm999636c357302020-08-09 19:54:08 +020079
80 if [[ $browser == "gecko" ]]; then
81 # Change the extension ID
82 set_manifest_field "id" "twpowertools+beta@avm99963.com"
83 fi
avm9996303d54092020-01-18 21:33:16 +010084fi
85
86# Create ZIP file for upload to the Chrome Web Store
87mkdir -p out
avm999636c357302020-08-09 19:54:08 +020088rm -rf out/twpowertools-$version-$browser-$channel.zip
avm99963127837b2020-08-09 20:21:03 +020089(cd src && zip -rq ../out/twpowertools-$version-$browser-$channel.zip * -x *.git*)
avm9996303d54092020-01-18 21:33:16 +010090
avm999636c357302020-08-09 19:54:08 +020091# Clean generated manifest.json file
92rm -f src/manifest.json
avm9996303d54092020-01-18 21:33:16 +010093
94echo "Done!"