blob: b29162c17c929f6964e2209e362bf50aa9f7e86d [file] [log] [blame]
avm99963f01af0e2020-12-26 23:11:10 +01001#!/bin/bash
2#
3# Generate release files (ZIP archives of the extension source code).
4
5# Prints help text
6function usage() {
7 cat <<END
8
9 Usage: $progname [--channel CHANNEL --browser BROWSER]
10
11 optional arguments:
12 -h, --help show this help message and exit
13 -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. As of
16 now it can only be "chromium", which is also the
17 default value.
avm999639bbb3a42020-12-29 03:29:44 +010018 -f, --fast indicates that the release shouldn't generate the
19 i18n credits JSON file.
avm99963f01af0e2020-12-26 23:11:10 +010020
21END
22}
23
24# Updates manifest.json field
25function set_manifest_field() {
26 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
27}
28
29# Get options
avm999639bbb3a42020-12-29 03:29:44 +010030opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@")
avm99963f01af0e2020-12-26 23:11:10 +010031eval set -- "$opts"
32
33channel=stable
34browser=chromium
avm999639bbb3a42020-12-29 03:29:44 +010035fast=0
avm99963f01af0e2020-12-26 23:11:10 +010036
37while true; do
38 case "$1" in
39 -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 ;;
avm999639bbb3a42020-12-29 03:29:44 +010051 -f | --fast)
52 fast=1
53 shift
54 ;;
avm99963f01af0e2020-12-26 23:11:10 +010055 *) break ;;
56 esac
57done
58
59if [[ $channel != "stable" && $channel != "beta" ]]; then
60 echo "channel parameter value is incorrect." >&2
61 usage
62 exit
63fi
64
65if [[ $browser != "chromium" ]]; then
66 echo "browser parameter value is incorrect." >&2
67 usage
68 exit
69fi
70
71echo "Started building release..."
72
73# First of all, generate the appropriate manifest.json file for the
74# target browser
75dependencies=(${browser})
76
77bash generateManifest.bash "${dependencies[@]}"
78
avm999639bbb3a42020-12-29 03:29:44 +010079# Also, generate the credits for the translators
80if [[ $fast == 0 ]]; then
81 bash generatei18nCredits.bash
82fi
83
avm99963f01af0e2020-12-26 23:11:10 +010084# This is the version name which git gives us
85version=$(git describe --always --tags --dirty)
86
87# If the version name contains a hyphen then it isn't a release
88# version. This is also the case if it doesn't start with a "v".
89if [[ $version == *"-"* || $version != "v"* ]]; then
90 # As it isn't a release version, setting version number to 0 so it
91 # cannot be uploaded to the Chrome Web Store
92 set_manifest_field "version" "0"
93 set_manifest_field "version_name" "$version-$channel"
94else
95 # It is a release version, set the version fields accordingly.
96 set_manifest_field "version" "${version:1}"
97 set_manifest_field "version_name" "${version:1}-$channel"
98fi
99
100if [[ $channel == "beta" ]]; then
101 # Change manifest.json to label the release as beta
102 set_manifest_field "name" "__MSG_appBetaName__"
103fi
104
105# Create ZIP file for upload to the Chrome Web Store
106mkdir -p out
107rm -rf out/translateselectedtext-$version-$browser-$channel.zip
108(cd src &&
109 zip -rq ../out/translateselectedtext-$version-$browser-$channel.zip * \
110 -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS")
111
112# Clean generated manifest.json file
113rm -f src/manifest.json
114
115echo "Done!"