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). |
| 4 | |
| 5 | # Prints help text |
| 6 | function 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. |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 18 | -f, --fast indicates that the release shouldn't generate the |
| 19 | i18n credits JSON file. |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 20 | |
| 21 | END |
| 22 | } |
| 23 | |
| 24 | # Updates manifest.json field |
| 25 | function set_manifest_field() { |
| 26 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json |
| 27 | } |
| 28 | |
| 29 | # Get options |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 30 | opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@") |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 31 | eval set -- "$opts" |
| 32 | |
| 33 | channel=stable |
| 34 | browser=chromium |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 35 | fast=0 |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 36 | |
| 37 | while 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 | ;; |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 51 | -f | --fast) |
| 52 | fast=1 |
| 53 | shift |
| 54 | ;; |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 55 | *) break ;; |
| 56 | esac |
| 57 | done |
| 58 | |
| 59 | if [[ $channel != "stable" && $channel != "beta" ]]; then |
| 60 | echo "channel parameter value is incorrect." >&2 |
| 61 | usage |
| 62 | exit |
| 63 | fi |
| 64 | |
| 65 | if [[ $browser != "chromium" ]]; then |
| 66 | echo "browser parameter value is incorrect." >&2 |
| 67 | usage |
| 68 | exit |
| 69 | fi |
| 70 | |
| 71 | echo "Started building release..." |
| 72 | |
| 73 | # First of all, generate the appropriate manifest.json file for the |
| 74 | # target browser |
| 75 | dependencies=(${browser}) |
| 76 | |
| 77 | bash generateManifest.bash "${dependencies[@]}" |
| 78 | |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 79 | # Also, generate the credits for the translators |
| 80 | if [[ $fast == 0 ]]; then |
| 81 | bash generatei18nCredits.bash |
| 82 | fi |
| 83 | |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 84 | # This is the version name which git gives us |
| 85 | version=$(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". |
| 89 | if [[ $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" |
| 94 | else |
| 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" |
| 98 | fi |
| 99 | |
| 100 | if [[ $channel == "beta" ]]; then |
| 101 | # Change manifest.json to label the release as beta |
| 102 | set_manifest_field "name" "__MSG_appBetaName__" |
| 103 | fi |
| 104 | |
| 105 | # Create ZIP file for upload to the Chrome Web Store |
| 106 | mkdir -p out |
| 107 | rm -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 |
| 113 | rm -f src/manifest.json |
| 114 | |
| 115 | echo "Done!" |