blob: 338d9e1046358a163b71faf496b49438e503b2ab [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).
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02004#
5# Precondition: webpack has already built the extension.
avm9996303d54092020-01-18 21:33:16 +01006
7# Prints help text
avm99963b69eb3d2020-08-20 02:03:44 +02008function usage() {
9 cat <<END
avm99963666575f2020-08-08 15:40:39 +020010
avm999634c584882020-08-23 16:08:50 +020011 Usage: $progname [--channel CHANNEL --browser BROWSER]
avm9996303d54092020-01-18 21:33:16 +010012
13 optional arguments:
14 -h, --help show this help message and exit
avm999636c357302020-08-09 19:54:08 +020015 -c, --channel indicates the channel of the release. Can be "beta"
16 or "stable". Defaults to "stable".
17 -b, --browser indicates the target browser for the release. Can be
avm99963bbc88c62020-12-25 03:44:41 +010018 "chromium", "gecko" or "chromium_mv3".
19 Defaults to "chromium".
avm9996303d54092020-01-18 21:33:16 +010020
21END
22}
23
avm99963666575f2020-08-08 15:40:39 +020024# Updates manifest.json field
avm99963b69eb3d2020-08-20 02:03:44 +020025function set_manifest_field() {
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020026 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" dist/$browser/manifest.json
avm99963666575f2020-08-08 15:40:39 +020027}
28
avm9996303d54092020-01-18 21:33:16 +010029# Get options
avm999636c357302020-08-09 19:54:08 +020030opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@")
avm9996303d54092020-01-18 21:33:16 +010031eval set -- "$opts"
32
33channel=stable
avm999636c357302020-08-09 19:54:08 +020034browser=chromium
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020035folder=null
avm9996303d54092020-01-18 21:33:16 +010036
37while true; do
38 case "$1" in
avm99963b69eb3d2020-08-20 02:03:44 +020039 -h | --help)
40 usage
41 exit
42 ;;
43 -c | --channel)
44 channel="$2"
45 shift 2
46 ;;
47 -b | --browser)
48 browser="$2"
49 shift 2
50 ;;
51 *) break ;;
avm9996303d54092020-01-18 21:33:16 +010052 esac
53done
54
55if [[ $channel != "stable" && $channel != "beta" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020056 echo "channel parameter value is incorrect." >&2
avm9996303d54092020-01-18 21:33:16 +010057 usage
58 exit
59fi
60
avm99963bbc88c62020-12-25 03:44:41 +010061if [[ $browser != "chromium" && $browser != "gecko" &&
62 $browser != "chromium_mv3" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020063 echo "browser parameter value is incorrect." >&2
avm999636c357302020-08-09 19:54:08 +020064 usage
65 exit
66fi
67
avm9996303d54092020-01-18 21:33:16 +010068echo "Started building release..."
69
avm99963666575f2020-08-08 15:40:39 +020070# This is the version name which git gives us
71version=$(git describe --always --tags --dirty)
72
73# If the version name contains a hyphen then it isn't a release
74# version. This is also the case if it doesn't start with a "v".
75if [[ $version == *"-"* || $version != "v"* ]]; then
76 # As it isn't a release version, setting version number to 0 so it
77 # cannot be uploaded to the Chrome Web Store
78 set_manifest_field "version" "0"
79 set_manifest_field "version_name" "$version-$channel"
80else
81 # It is a release version, set the version fields accordingly.
82 set_manifest_field "version" "${version:1}"
83 set_manifest_field "version_name" "${version:1}-$channel"
84fi
85
avm9996303d54092020-01-18 21:33:16 +010086if [[ $channel == "beta" ]]; then
87 # Change manifest.json to label the release as beta
avm99963666575f2020-08-08 15:40:39 +020088 set_manifest_field "name" "__MSG_appNameBeta__"
avm999636c357302020-08-09 19:54:08 +020089
90 if [[ $browser == "gecko" ]]; then
91 # Change the extension ID
92 set_manifest_field "id" "twpowertools+beta@avm99963.com"
93 fi
avm9996375814b82020-08-09 20:33:23 +020094else
95 if [[ $browser == "gecko" ]]; then
96 set_manifest_field "name" "__MSG_appNameGecko__"
97 fi
avm9996303d54092020-01-18 21:33:16 +010098fi
99
100# Create ZIP file for upload to the Chrome Web Store
101mkdir -p out
avm999636c357302020-08-09 19:54:08 +0200102rm -rf out/twpowertools-$version-$browser-$channel.zip
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200103(cd dist/$browser &&
104 zip -rq ../../out/twpowertools-$version-$browser-$channel.zip * -x "*/.git*" \
avm9996350c553d2020-12-23 18:46:43 +0100105 -x "*/\.DS_Store" -x "*/OWNERS")
avm9996303d54092020-01-18 21:33:16 +0100106
avm9996303d54092020-01-18 21:33:16 +0100107echo "Done!"