avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 1 | #!/bin/bash |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 2 | # |
| 3 | # Generate release files (ZIP archives of the extension source code). |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 4 | |
| 5 | # Prints help text |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 6 | function usage() { |
| 7 | cat <<END |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 8 | |
avm99963 | 4c58488 | 2020-08-23 16:08:50 +0200 | [diff] [blame] | 9 | Usage: $progname [--channel CHANNEL --browser BROWSER] |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 10 | |
| 11 | optional arguments: |
| 12 | -h, --help show this help message and exit |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 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. Can be |
| 16 | "chromium" or "gecko". Defaults to "chromium". |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 17 | |
| 18 | END |
| 19 | } |
| 20 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 21 | # Updates manifest.json field |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 22 | function set_manifest_field() { |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 23 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json |
| 24 | } |
| 25 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 26 | # Get options |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 27 | opts=$(getopt -l "help,channel:,browser:" -o "hc:b:" -n "$progname" -- "$@") |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 28 | eval set -- "$opts" |
| 29 | |
| 30 | channel=stable |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 31 | browser=chromium |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 32 | |
| 33 | while true; do |
| 34 | case "$1" in |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 35 | -h | --help) |
| 36 | usage |
| 37 | exit |
| 38 | ;; |
| 39 | -c | --channel) |
| 40 | channel="$2" |
| 41 | shift 2 |
| 42 | ;; |
| 43 | -b | --browser) |
| 44 | browser="$2" |
| 45 | shift 2 |
| 46 | ;; |
| 47 | *) break ;; |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 48 | esac |
| 49 | done |
| 50 | |
| 51 | if [[ $channel != "stable" && $channel != "beta" ]]; then |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 52 | echo "channel parameter value is incorrect." >&2 |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 53 | usage |
| 54 | exit |
| 55 | fi |
| 56 | |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 57 | if [[ $browser != "chromium" && $browser != "gecko" ]]; then |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 58 | echo "browser parameter value is incorrect." >&2 |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 59 | usage |
| 60 | exit |
| 61 | fi |
| 62 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 63 | echo "Started building release..." |
| 64 | |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 65 | # First of all, generate the appropriate manifest.json file for the |
| 66 | # target browser |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 67 | dependencies=(${browser^^}) |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 68 | |
| 69 | bash generateManifest.bash "${dependencies[@]}" |
| 70 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 71 | # This is the version name which git gives us |
| 72 | version=$(git describe --always --tags --dirty) |
| 73 | |
| 74 | # If the version name contains a hyphen then it isn't a release |
| 75 | # version. This is also the case if it doesn't start with a "v". |
| 76 | if [[ $version == *"-"* || $version != "v"* ]]; then |
| 77 | # As it isn't a release version, setting version number to 0 so it |
| 78 | # cannot be uploaded to the Chrome Web Store |
| 79 | set_manifest_field "version" "0" |
| 80 | set_manifest_field "version_name" "$version-$channel" |
| 81 | else |
| 82 | # It is a release version, set the version fields accordingly. |
| 83 | set_manifest_field "version" "${version:1}" |
| 84 | set_manifest_field "version_name" "${version:1}-$channel" |
| 85 | fi |
| 86 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 87 | if [[ $channel == "beta" ]]; then |
| 88 | # Change manifest.json to label the release as beta |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 89 | set_manifest_field "name" "__MSG_appNameBeta__" |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 90 | |
| 91 | if [[ $browser == "gecko" ]]; then |
| 92 | # Change the extension ID |
| 93 | set_manifest_field "id" "twpowertools+beta@avm99963.com" |
| 94 | fi |
avm99963 | 75814b8 | 2020-08-09 20:33:23 +0200 | [diff] [blame] | 95 | else |
| 96 | if [[ $browser == "gecko" ]]; then |
| 97 | set_manifest_field "name" "__MSG_appNameGecko__" |
| 98 | fi |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 99 | fi |
| 100 | |
| 101 | # Create ZIP file for upload to the Chrome Web Store |
| 102 | mkdir -p out |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 103 | rm -rf out/twpowertools-$version-$browser-$channel.zip |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 104 | (cd src && |
avm99963 | 50c553d | 2020-12-23 18:46:43 +0100 | [diff] [blame^] | 105 | zip -rq ../out/twpowertools-$version-$browser-$channel.zip * -x "*/.git*" \ |
| 106 | -x "*/\.DS_Store" -x "*/OWNERS") |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 107 | |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 108 | # Clean generated manifest.json file |
| 109 | rm -f src/manifest.json |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 110 | |
| 111 | echo "Done!" |