blob: 91f6b20583a217b76e9518e1d482095e4805a6a9 [file] [log] [blame]
avm99963f01af0e2020-12-26 23:11:10 +01001#!/bin/bash
2#
3# Generate release files (ZIP archives of the extension source code).
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +02004#
5# Precondition: webpack has already built the extension.
avm99963f01af0e2020-12-26 23:11:10 +01006
7# Prints help text
8function usage() {
9 cat <<END
10
11 Usage: $progname [--channel CHANNEL --browser BROWSER]
12
13 optional arguments:
14 -h, --help show this help message and exit
15 -c, --channel indicates the channel of the release. Can be "beta"
16 or "stable". Defaults to "stable".
Adrià Vilanova Martínez8b63fb32022-05-29 23:26:50 +020017 -b, --browser indicates the target browser for the release. Can be
18 "chromium" or "edge". Defaults to "chromium".
avm999639bbb3a42020-12-29 03:29:44 +010019 -f, --fast indicates that the release shouldn't generate the
20 i18n credits JSON file.
avm99963f01af0e2020-12-26 23:11:10 +010021
22END
23}
24
25# Updates manifest.json field
26function set_manifest_field() {
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +020027 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" dist/$browser/manifest.json
avm99963f01af0e2020-12-26 23:11:10 +010028}
29
30# Get options
avm999639bbb3a42020-12-29 03:29:44 +010031opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@")
avm99963f01af0e2020-12-26 23:11:10 +010032eval set -- "$opts"
33
34channel=stable
35browser=chromium
avm999639bbb3a42020-12-29 03:29:44 +010036fast=0
avm99963f01af0e2020-12-26 23:11:10 +010037
38while true; do
39 case "$1" in
40 -h | --help)
41 usage
42 exit
43 ;;
44 -c | --channel)
45 channel="$2"
46 shift 2
47 ;;
48 -b | --browser)
49 browser="$2"
50 shift 2
51 ;;
avm999639bbb3a42020-12-29 03:29:44 +010052 -f | --fast)
53 fast=1
54 shift
55 ;;
avm99963f01af0e2020-12-26 23:11:10 +010056 *) break ;;
57 esac
58done
59
60if [[ $channel != "stable" && $channel != "beta" ]]; then
61 echo "channel parameter value is incorrect." >&2
62 usage
63 exit
64fi
65
Adrià Vilanova Martínez8b63fb32022-05-29 23:26:50 +020066if [[ $browser != "chromium" && $browser != "edge" ]]; then
avm99963f01af0e2020-12-26 23:11:10 +010067 echo "browser parameter value is incorrect." >&2
68 usage
69 exit
70fi
71
72echo "Started building release..."
73
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +020074# Generate the credits for the translators if applicable
avm999639bbb3a42020-12-29 03:29:44 +010075if [[ $fast == 0 ]]; then
76 bash generatei18nCredits.bash
77fi
78
avm99963f01af0e2020-12-26 23:11:10 +010079# This is the version name which git gives us
80version=$(git describe --always --tags --dirty)
81
82# If the version name contains a hyphen then it isn't a release
83# version. This is also the case if it doesn't start with a "v".
84if [[ $version == *"-"* || $version != "v"* ]]; then
85 # As it isn't a release version, setting version number to 0 so it
86 # cannot be uploaded to the Chrome Web Store
87 set_manifest_field "version" "0"
88 set_manifest_field "version_name" "$version-$channel"
89else
90 # It is a release version, set the version fields accordingly.
91 set_manifest_field "version" "${version:1}"
92 set_manifest_field "version_name" "${version:1}-$channel"
93fi
94
95if [[ $channel == "beta" ]]; then
96 # Change manifest.json to label the release as beta
97 set_manifest_field "name" "__MSG_appBetaName__"
98fi
99
100# Create ZIP file for upload to the Chrome Web Store
101mkdir -p out
102rm -rf out/translateselectedtext-$version-$browser-$channel.zip
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +0200103(cd dist/$browser &&
104 zip -rq ../../out/translateselectedtext-$version-$browser-$channel.zip * \
avm99963f01af0e2020-12-26 23:11:10 +0100105 -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS")
106
avm99963f01af0e2020-12-26 23:11:10 +0100107echo "Done!"