avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Generate release files (ZIP archives of the extension source code). |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 4 | # |
| 5 | # Precondition: webpack has already built the extension. |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 6 | |
| 7 | # Prints help text |
| 8 | function 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ínez | 8b63fb3 | 2022-05-29 23:26:50 +0200 | [diff] [blame] | 17 | -b, --browser indicates the target browser for the release. Can be |
Adrià Vilanova Martínez | 86fda49 | 2022-05-31 15:05:21 +0200 | [diff] [blame] | 18 | "chromium", "chromium_mv3, "edge" or "edge_mv3". |
| 19 | Defaults to "chromium". |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 20 | -f, --fast indicates that the release shouldn't generate the |
| 21 | i18n credits JSON file. |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 22 | |
| 23 | END |
| 24 | } |
| 25 | |
| 26 | # Updates manifest.json field |
| 27 | function set_manifest_field() { |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 28 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" dist/$browser/manifest.json |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | # Get options |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 32 | opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@") |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 33 | eval set -- "$opts" |
| 34 | |
| 35 | channel=stable |
| 36 | browser=chromium |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 37 | fast=0 |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 38 | |
| 39 | while 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 | ;; |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 53 | -f | --fast) |
| 54 | fast=1 |
| 55 | shift |
| 56 | ;; |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 57 | *) break ;; |
| 58 | esac |
| 59 | done |
| 60 | |
| 61 | if [[ $channel != "stable" && $channel != "beta" ]]; then |
| 62 | echo "channel parameter value is incorrect." >&2 |
| 63 | usage |
| 64 | exit |
| 65 | fi |
| 66 | |
Adrià Vilanova Martínez | 86fda49 | 2022-05-31 15:05:21 +0200 | [diff] [blame] | 67 | if [[ $browser != "chromium" && $browser != "chromium_mv3" && $browser != "edge" && $browser != "edge_mv3" ]]; then |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 68 | echo "browser parameter value is incorrect." >&2 |
| 69 | usage |
| 70 | exit |
| 71 | fi |
| 72 | |
| 73 | echo "Started building release..." |
| 74 | |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 75 | # Generate the credits for the translators if applicable |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 76 | if [[ $fast == 0 ]]; then |
| 77 | bash generatei18nCredits.bash |
| 78 | fi |
| 79 | |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 80 | # This is the version name which git gives us |
| 81 | version=$(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". |
| 85 | if [[ $version == *"-"* || $version != "v"* ]]; then |
| 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 | else |
| 91 | # It is a release version, set the version fields accordingly. |
| 92 | set_manifest_field "version" "${version:1}" |
| 93 | set_manifest_field "version_name" "${version:1}-$channel" |
| 94 | fi |
| 95 | |
| 96 | if [[ $channel == "beta" ]]; then |
| 97 | # Change manifest.json to label the release as beta |
| 98 | set_manifest_field "name" "__MSG_appBetaName__" |
| 99 | fi |
| 100 | |
| 101 | # Create ZIP file for upload to the Chrome Web Store |
| 102 | mkdir -p out |
| 103 | rm -rf out/translateselectedtext-$version-$browser-$channel.zip |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 104 | (cd dist/$browser && |
| 105 | zip -rq ../../out/translateselectedtext-$version-$browser-$channel.zip * \ |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 106 | -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS") |
| 107 | |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 108 | echo "Done!" |