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