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. |
| 18 | |
| 19 | END |
| 20 | } |
| 21 | |
| 22 | # Updates manifest.json field |
| 23 | function set_manifest_field() { |
| 24 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json |
| 25 | } |
| 26 | |
| 27 | # Get options |
| 28 | opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@") |
| 29 | eval set -- "$opts" |
| 30 | |
| 31 | channel=stable |
| 32 | browser=chromium |
| 33 | |
| 34 | while 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 |
| 50 | done |
| 51 | |
| 52 | if [[ $channel != "stable" && $channel != "beta" ]]; then |
| 53 | echo "channel parameter value is incorrect." >&2 |
| 54 | usage |
| 55 | exit |
| 56 | fi |
| 57 | |
| 58 | if [[ $browser != "chromium" ]]; then |
| 59 | echo "browser parameter value is incorrect." >&2 |
| 60 | usage |
| 61 | exit |
| 62 | fi |
| 63 | |
| 64 | echo "Started building release..." |
| 65 | |
| 66 | # First of all, generate the appropriate manifest.json file for the |
| 67 | # target browser |
| 68 | dependencies=(${browser}) |
| 69 | |
| 70 | bash generateManifest.bash "${dependencies[@]}" |
| 71 | |
| 72 | # This is the version name which git gives us |
| 73 | version=$(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". |
| 77 | if [[ $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" |
| 82 | else |
| 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" |
| 86 | fi |
| 87 | |
| 88 | if [[ $channel == "beta" ]]; then |
| 89 | # Change manifest.json to label the release as beta |
| 90 | set_manifest_field "name" "__MSG_appBetaName__" |
| 91 | fi |
| 92 | |
| 93 | # Create ZIP file for upload to the Chrome Web Store |
| 94 | mkdir -p out |
| 95 | rm -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 |
| 101 | rm -f src/manifest.json |
| 102 | |
| 103 | echo "Done!" |