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