blob: 852e4f0a4ab3d7cb15d7f51595a7e6847253fb57 [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
avm999634c584882020-08-23 16:08:50 +02009 Usage: $progname [--channel CHANNEL --browser BROWSER]
avm9996303d54092020-01-18 21:33:16 +010010
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
avm99963bbc88c62020-12-25 03:44:41 +010016 "chromium", "gecko" or "chromium_mv3".
17 Defaults to "chromium".
avm9996303d54092020-01-18 21:33:16 +010018
19END
20}
21
avm99963666575f2020-08-08 15:40:39 +020022# Updates manifest.json field
avm99963b69eb3d2020-08-20 02:03:44 +020023function set_manifest_field() {
avm99963666575f2020-08-08 15:40:39 +020024 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
25}
26
avm9996303d54092020-01-18 21:33:16 +010027# Get options
avm999636c357302020-08-09 19:54:08 +020028opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@")
avm9996303d54092020-01-18 21:33:16 +010029eval set -- "$opts"
30
31channel=stable
avm999636c357302020-08-09 19:54:08 +020032browser=chromium
avm9996303d54092020-01-18 21:33:16 +010033
34while true; do
35 case "$1" in
avm99963b69eb3d2020-08-20 02:03:44 +020036 -h | --help)
37 usage
38 exit
39 ;;
40 -c | --channel)
41 channel="$2"
42 shift 2
43 ;;
44 -b | --browser)
45 browser="$2"
46 shift 2
47 ;;
48 *) break ;;
avm9996303d54092020-01-18 21:33:16 +010049 esac
50done
51
52if [[ $channel != "stable" && $channel != "beta" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020053 echo "channel parameter value is incorrect." >&2
avm9996303d54092020-01-18 21:33:16 +010054 usage
55 exit
56fi
57
avm99963bbc88c62020-12-25 03:44:41 +010058if [[ $browser != "chromium" && $browser != "gecko" &&
59 $browser != "chromium_mv3" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020060 echo "browser parameter value is incorrect." >&2
avm999636c357302020-08-09 19:54:08 +020061 usage
62 exit
63fi
64
avm9996303d54092020-01-18 21:33:16 +010065echo "Started building release..."
66
avm999636c357302020-08-09 19:54:08 +020067# First of all, generate the appropriate manifest.json file for the
68# target browser
avm99963e13bace2020-12-25 01:35:25 +010069dependencies=(${browser})
avm999636c357302020-08-09 19:54:08 +020070
avm99963e13bace2020-12-25 01:35:25 +010071go run generateManifest.go "${dependencies[@]}"
avm999636c357302020-08-09 19:54:08 +020072
avm99963666575f2020-08-08 15:40:39 +020073# This is the version name which git gives us
74version=$(git describe --always --tags --dirty)
75
76# If the version name contains a hyphen then it isn't a release
77# version. This is also the case if it doesn't start with a "v".
78if [[ $version == *"-"* || $version != "v"* ]]; then
79 # As it isn't a release version, setting version number to 0 so it
80 # cannot be uploaded to the Chrome Web Store
81 set_manifest_field "version" "0"
82 set_manifest_field "version_name" "$version-$channel"
83else
84 # It is a release version, set the version fields accordingly.
85 set_manifest_field "version" "${version:1}"
86 set_manifest_field "version_name" "${version:1}-$channel"
87fi
88
avm9996303d54092020-01-18 21:33:16 +010089if [[ $channel == "beta" ]]; then
90 # Change manifest.json to label the release as beta
avm99963666575f2020-08-08 15:40:39 +020091 set_manifest_field "name" "__MSG_appNameBeta__"
avm999636c357302020-08-09 19:54:08 +020092
93 if [[ $browser == "gecko" ]]; then
94 # Change the extension ID
95 set_manifest_field "id" "twpowertools+beta@avm99963.com"
96 fi
avm9996375814b82020-08-09 20:33:23 +020097else
98 if [[ $browser == "gecko" ]]; then
99 set_manifest_field "name" "__MSG_appNameGecko__"
100 fi
avm9996303d54092020-01-18 21:33:16 +0100101fi
102
103# Create ZIP file for upload to the Chrome Web Store
104mkdir -p out
avm999636c357302020-08-09 19:54:08 +0200105rm -rf out/twpowertools-$version-$browser-$channel.zip
avm99963b69eb3d2020-08-20 02:03:44 +0200106(cd src &&
avm9996350c553d2020-12-23 18:46:43 +0100107 zip -rq ../out/twpowertools-$version-$browser-$channel.zip * -x "*/.git*" \
108 -x "*/\.DS_Store" -x "*/OWNERS")
avm9996303d54092020-01-18 21:33:16 +0100109
avm999636c357302020-08-09 19:54:08 +0200110# Clean generated manifest.json file
111rm -f src/manifest.json
avm9996303d54092020-01-18 21:33:16 +0100112
113echo "Done!"