blob: e65441fdd190d9a8ee817b361f92da00dfde44e8 [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
Adrià Vilanova Martínez9aa29312022-01-16 02:42:46 +010015 -c, --channel indicates the channel of the release. Can be "beta",
16 "stable" or "canary". Defaults to "stable".
avm999636c357302020-08-09 19:54:08 +020017 -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
Adrià Vilanova Martínez9aa29312022-01-16 02:42:46 +010055if [[ $channel != "stable" && $channel != "beta" && \
56 $channel != "canary" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020057 echo "channel parameter value is incorrect." >&2
avm9996303d54092020-01-18 21:33:16 +010058 usage
59 exit
60fi
61
Adrià Vilanova Martínez9aa29312022-01-16 02:42:46 +010062if [[ $browser != "chromium" && $browser != "gecko" && \
63 $browser != "chromium_mv3" ]]; then
avm99963b69eb3d2020-08-20 02:03:44 +020064 echo "browser parameter value is incorrect." >&2
avm999636c357302020-08-09 19:54:08 +020065 usage
66 exit
67fi
68
avm9996303d54092020-01-18 21:33:16 +010069echo "Started building release..."
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
Adrià Vilanova Martínez9aa29312022-01-16 02:42:46 +010077 if [[ $channel == "canary" && $version == "v"* && \
78 $version != *"dirty" ]]; then
79 # If we're releasing a canary build and the build is not dirty,
80 # generate a version number
81 IFS='-' read -ra versionExplode <<< "${version:1}"
82 versionCanary="${versionExplode[0]}.${versionExplode[1]}"
83 set_manifest_field "version" "$versionCanary"
84 set_manifest_field "version_name" "$versionCanary-$channel"
85 else
86 # As it isn't a release version, setting version number to 0 so it
87 # cannot be uploaded to the Chrome Web Store
88 set_manifest_field "version" "0"
89 set_manifest_field "version_name" "$version-$channel"
90 fi
avm99963666575f2020-08-08 15:40:39 +020091else
92 # It is a release version, set the version fields accordingly.
93 set_manifest_field "version" "${version:1}"
94 set_manifest_field "version_name" "${version:1}-$channel"
95fi
96
Adrià Vilanova Martínez9aa29312022-01-16 02:42:46 +010097if [[ $channel == "canary" ]]; then
98 # Change manifest.json to label the release as canary
99 set_manifest_field "name" "__MSG_appNameCanary__"
100
101 if [[ $browser == "gecko" ]]; then
102 # Change the extension ID
103 set_manifest_field "id" "twpowertools+canary@avm99963.com"
104 fi
105elif [[ $channel == "beta" ]]; then
avm9996303d54092020-01-18 21:33:16 +0100106 # Change manifest.json to label the release as beta
avm99963666575f2020-08-08 15:40:39 +0200107 set_manifest_field "name" "__MSG_appNameBeta__"
avm999636c357302020-08-09 19:54:08 +0200108
109 if [[ $browser == "gecko" ]]; then
110 # Change the extension ID
111 set_manifest_field "id" "twpowertools+beta@avm99963.com"
112 fi
avm9996375814b82020-08-09 20:33:23 +0200113else
114 if [[ $browser == "gecko" ]]; then
115 set_manifest_field "name" "__MSG_appNameGecko__"
116 fi
avm9996303d54092020-01-18 21:33:16 +0100117fi
118
119# Create ZIP file for upload to the Chrome Web Store
120mkdir -p out
avm999636c357302020-08-09 19:54:08 +0200121rm -rf out/twpowertools-$version-$browser-$channel.zip
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +0200122(cd dist/$browser &&
123 zip -rq ../../out/twpowertools-$version-$browser-$channel.zip * -x "*/.git*" \
Adrià Vilanova Martínez9aa29312022-01-16 02:42:46 +0100124 -x "*/\.DS_Store" -x "*/OWNERS")
avm9996303d54092020-01-18 21:33:16 +0100125
avm9996303d54092020-01-18 21:33:16 +0100126echo "Done!"