blob: 94ab75a180058d2e16e8e547ee82b5f90bd88c2b [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.
18
19END
20}
21
22# Updates manifest.json field
23function set_manifest_field() {
24 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json
25}
26
27# Get options
28opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@")
29eval set -- "$opts"
30
31channel=stable
32browser=chromium
33
34while true; do
35 case "$1" in
36 -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 ;;
49 esac
50done
51
52if [[ $channel != "stable" && $channel != "beta" ]]; then
53 echo "channel parameter value is incorrect." >&2
54 usage
55 exit
56fi
57
58if [[ $browser != "chromium" ]]; then
59 echo "browser parameter value is incorrect." >&2
60 usage
61 exit
62fi
63
64echo "Started building release..."
65
66# First of all, generate the appropriate manifest.json file for the
67# target browser
68dependencies=(${browser})
69
70bash generateManifest.bash "${dependencies[@]}"
71
72# This is the version name which git gives us
73version=$(git describe --always --tags --dirty)
74
75# If the version name contains a hyphen then it isn't a release
76# version. This is also the case if it doesn't start with a "v".
77if [[ $version == *"-"* || $version != "v"* ]]; then
78 # As it isn't a release version, setting version number to 0 so it
79 # cannot be uploaded to the Chrome Web Store
80 set_manifest_field "version" "0"
81 set_manifest_field "version_name" "$version-$channel"
82else
83 # It is a release version, set the version fields accordingly.
84 set_manifest_field "version" "${version:1}"
85 set_manifest_field "version_name" "${version:1}-$channel"
86fi
87
88if [[ $channel == "beta" ]]; then
89 # Change manifest.json to label the release as beta
90 set_manifest_field "name" "__MSG_appBetaName__"
91fi
92
93# Create ZIP file for upload to the Chrome Web Store
94mkdir -p out
95rm -rf out/translateselectedtext-$version-$browser-$channel.zip
96(cd src &&
97 zip -rq ../out/translateselectedtext-$version-$browser-$channel.zip * \
98 -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS")
99
100# Clean generated manifest.json file
101rm -f src/manifest.json
102
103echo "Done!"