blob: d5f634dc8ff68c19574669251fa55cca2f82c90a [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
Adrià Vilanova Martínez87e35052022-06-01 14:05:29 +020015 -c, --channel indicates the channel of the release. Can be "beta",
16 "stable" or "canary". Defaults to "stable".
Adrià Vilanova Martínez8b63fb32022-05-29 23:26:50 +020017 -b, --browser indicates the target browser for the release. Can be
Adrià Vilanova Martínez86fda492022-05-31 15:05:21 +020018 "chromium", "chromium_mv3, "edge" or "edge_mv3".
19 Defaults to "chromium".
avm999639bbb3a42020-12-29 03:29:44 +010020 -f, --fast indicates that the release shouldn't generate the
21 i18n credits JSON file.
avm99963f01af0e2020-12-26 23:11:10 +010022
23END
24}
25
26# Updates manifest.json field
27function set_manifest_field() {
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +020028 sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" dist/$browser/manifest.json
avm99963f01af0e2020-12-26 23:11:10 +010029}
30
31# Get options
avm999639bbb3a42020-12-29 03:29:44 +010032opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@")
avm99963f01af0e2020-12-26 23:11:10 +010033eval set -- "$opts"
34
35channel=stable
36browser=chromium
avm999639bbb3a42020-12-29 03:29:44 +010037fast=0
avm99963f01af0e2020-12-26 23:11:10 +010038
39while true; do
40 case "$1" in
41 -h | --help)
42 usage
43 exit
44 ;;
45 -c | --channel)
46 channel="$2"
47 shift 2
48 ;;
49 -b | --browser)
50 browser="$2"
51 shift 2
52 ;;
avm999639bbb3a42020-12-29 03:29:44 +010053 -f | --fast)
54 fast=1
55 shift
56 ;;
avm99963f01af0e2020-12-26 23:11:10 +010057 *) break ;;
58 esac
59done
60
Adrià Vilanova Martínez87e35052022-06-01 14:05:29 +020061if [[ $channel != "stable" && $channel != "beta" && $channel != "canary" ]]; then
avm99963f01af0e2020-12-26 23:11:10 +010062 echo "channel parameter value is incorrect." >&2
63 usage
64 exit
65fi
66
Adrià Vilanova Martínez86fda492022-05-31 15:05:21 +020067if [[ $browser != "chromium" && $browser != "chromium_mv3" && $browser != "edge" && $browser != "edge_mv3" ]]; then
avm99963f01af0e2020-12-26 23:11:10 +010068 echo "browser parameter value is incorrect." >&2
69 usage
70 exit
71fi
72
73echo "Started building release..."
74
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +020075# Generate the credits for the translators if applicable
avm999639bbb3a42020-12-29 03:29:44 +010076if [[ $fast == 0 ]]; then
77 bash generatei18nCredits.bash
78fi
79
avm99963f01af0e2020-12-26 23:11:10 +010080# This is the version name which git gives us
81version=$(git describe --always --tags --dirty)
82
83# If the version name contains a hyphen then it isn't a release
84# version. This is also the case if it doesn't start with a "v".
85if [[ $version == *"-"* || $version != "v"* ]]; then
Adrià Vilanova Martínez87e35052022-06-01 14:05:29 +020086 if [[ $channel == "canary" && $version == "v"* && \
87 $version != *"dirty" ]]; then
88 # If we're releasing a canary build and the build is not dirty,
89 # generate a version number
90 IFS='-' read -ra versionExplode <<< "${version:1}"
91 versionCanary="${versionExplode[0]}.${versionExplode[1]}"
92 set_manifest_field "version" "$versionCanary"
93 set_manifest_field "version_name" "$versionCanary-$channel"
94 else
95 # As it isn't a release version, setting version number to 0 so it
96 # cannot be uploaded to the Chrome Web Store
97 set_manifest_field "version" "0"
98 set_manifest_field "version_name" "$version-$channel"
99 fi
avm99963f01af0e2020-12-26 23:11:10 +0100100else
101 # It is a release version, set the version fields accordingly.
102 set_manifest_field "version" "${version:1}"
103 set_manifest_field "version_name" "${version:1}-$channel"
104fi
105
Adrià Vilanova Martínez87e35052022-06-01 14:05:29 +0200106if [[ $channel == "canary" ]]; then
107 # Change manifest.json to label the release as canary
108 set_manifest_field "name" "__MSG_appCanaryName__"
109elif [[ $channel == "beta" ]]; then
avm99963f01af0e2020-12-26 23:11:10 +0100110 # Change manifest.json to label the release as beta
111 set_manifest_field "name" "__MSG_appBetaName__"
112fi
113
114# Create ZIP file for upload to the Chrome Web Store
115mkdir -p out
116rm -rf out/translateselectedtext-$version-$browser-$channel.zip
Adrià Vilanova Martíneza197d862022-05-27 17:33:20 +0200117(cd dist/$browser &&
118 zip -rq ../../out/translateselectedtext-$version-$browser-$channel.zip * \
avm99963f01af0e2020-12-26 23:11:10 +0100119 -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS")
120
avm99963f01af0e2020-12-26 23:11:10 +0100121echo "Done!"