blob: e261c374a787712c7dbcf02fc25dc44d1af06fef [file] [log] [blame]
avm9996303d54092020-01-18 21:33:16 +01001#!/bin/bash
avm99963b69eb3d2020-08-20 02:03:44 +02002#
3# Generate release files (ZIP archives of the extension source code).
avm9996303d54092020-01-18 21:33:16 +01004
5# Prints help text
avm99963b69eb3d2020-08-20 02:03:44 +02006function usage() {
7 cat <<END
avm99963666575f2020-08-08 15:40:39 +02008
avm9996303d54092020-01-18 21:33:16 +01009 Usage: $progname [--channel CHANNEL]
10
11 optional arguments:
12 -h, --help show this help message and exit
avm999636c357302020-08-09 19:54:08 +020013 -c, --channel indicates the channel of the release. Can be "beta"
14 or "stable". Defaults to "stable".
15 -b, --browser indicates the target browser for the release. Can be
16 "chromium" or "gecko". Defaults to "chromium".
avm9996303d54092020-01-18 21:33:16 +010017
18END
19}
20
avm99963666575f2020-08-08 15:40:39 +020021# Updates manifest.json field
avm99963b69eb3d2020-08-20 02:03:44 +020022function set_manifest_field() {
avm99963666575f2020-08-08 15:40:39 +020023 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
24}
25
avm9996303d54092020-01-18 21:33:16 +010026# Get options
avm999636c357302020-08-09 19:54:08 +020027opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@")
avm9996303d54092020-01-18 21:33:16 +010028eval set -- "$opts"
29
30channel=stable
avm999636c357302020-08-09 19:54:08 +020031browser=chromium
avm9996303d54092020-01-18 21:33:16 +010032
33while true; do
34 case "$1" in
avm99963b69eb3d2020-08-20 02:03:44 +020035 -h | --help)
36 usage
37 exit
38 ;;
39 -c | --channel)
40 channel="$2"
41 shift 2
42 ;;
43 -b | --browser)
44 browser="$2"
45 shift 2
46 ;;
47 *) break ;;
avm9996303d54092020-01-18 21:33:16 +010048 esac
49done
50
51if [[ $channel != "stable" && $channel != "beta" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020052 echo "channel parameter value is incorrect." >&2
avm9996303d54092020-01-18 21:33:16 +010053 usage
54 exit
55fi
56
avm999636c357302020-08-09 19:54:08 +020057if [[ $browser != "chromium" && $browser != "gecko" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020058 echo "browser parameter value is incorrect." >&2
avm999636c357302020-08-09 19:54:08 +020059 usage
60 exit
61fi
62
avm9996303d54092020-01-18 21:33:16 +010063echo "Started building release..."
64
avm999636c357302020-08-09 19:54:08 +020065# First of all, generate the appropriate manifest.json file for the
66# target browser
avm99963b69eb3d2020-08-20 02:03:44 +020067dependencies=(${browser^^})
avm999636c357302020-08-09 19:54:08 +020068
69bash generateManifest.bash "${dependencies[@]}"
70
avm99963666575f2020-08-08 15:40:39 +020071# This is the version name which git gives us
72version=$(git describe --always --tags --dirty)
73
74# If the version name contains a hyphen then it isn't a release
75# version. This is also the case if it doesn't start with a "v".
76if [[ $version == *"-"* || $version != "v"* ]]; then
77 # As it isn't a release version, setting version number to 0 so it
78 # cannot be uploaded to the Chrome Web Store
79 set_manifest_field "version" "0"
80 set_manifest_field "version_name" "$version-$channel"
81else
82 # It is a release version, set the version fields accordingly.
83 set_manifest_field "version" "${version:1}"
84 set_manifest_field "version_name" "${version:1}-$channel"
85fi
86
avm9996303d54092020-01-18 21:33:16 +010087if [[ $channel == "beta" ]]; then
88 # Change manifest.json to label the release as beta
avm99963666575f2020-08-08 15:40:39 +020089 set_manifest_field "name" "__MSG_appNameBeta__"
avm999636c357302020-08-09 19:54:08 +020090
91 if [[ $browser == "gecko" ]]; then
92 # Change the extension ID
93 set_manifest_field "id" "twpowertools+beta@avm99963.com"
94 fi
avm9996375814b82020-08-09 20:33:23 +020095else
96 if [[ $browser == "gecko" ]]; then
97 set_manifest_field "name" "__MSG_appNameGecko__"
98 fi
avm9996303d54092020-01-18 21:33:16 +010099fi
100
101# Create ZIP file for upload to the Chrome Web Store
102mkdir -p out
avm999636c357302020-08-09 19:54:08 +0200103rm -rf out/twpowertools-$version-$browser-$channel.zip
avm99963b69eb3d2020-08-20 02:03:44 +0200104(cd src &&
105 zip -rq ../out/twpowertools-$version-$browser-$channel.zip * -x *.git*)
avm9996303d54092020-01-18 21:33:16 +0100106
avm999636c357302020-08-09 19:54:08 +0200107# Clean generated manifest.json file
108rm -f src/manifest.json
avm9996303d54092020-01-18 21:33:16 +0100109
110echo "Done!"