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 |
Adrià Vilanova Martínez | 9aa2931 | 2022-01-16 02:42:46 +0100 | [diff] [blame] | 15 | -c, --channel indicates the channel of the release. Can be "beta", |
| 16 | "stable" or "canary". Defaults to "stable". |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 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 | |
Adrià Vilanova Martínez | 9aa2931 | 2022-01-16 02:42:46 +0100 | [diff] [blame] | 55 | if [[ $channel != "stable" && $channel != "beta" && \ |
| 56 | $channel != "canary" ]]; then |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 57 | echo "channel parameter value is incorrect." >&2 |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 58 | usage |
| 59 | exit |
| 60 | fi |
| 61 | |
Adrià Vilanova Martínez | 9aa2931 | 2022-01-16 02:42:46 +0100 | [diff] [blame] | 62 | if [[ $browser != "chromium" && $browser != "gecko" && \ |
| 63 | $browser != "chromium_mv3" ]]; then |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 64 | echo "browser parameter value is incorrect." >&2 |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 65 | usage |
| 66 | exit |
| 67 | fi |
| 68 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 69 | echo "Started building release..." |
| 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 |
Adrià Vilanova Martínez | 9aa2931 | 2022-01-16 02:42:46 +0100 | [diff] [blame] | 77 | if [[ $channel == "canary" && $version == "v"* && \ |
| 78 | $version != *"dirty" ]]; then |
| 79 | # If we're releasing a canary build and the build is not dirty, |
| 80 | # generate a version number |
| 81 | IFS='-' read -ra versionExplode <<< "${version:1}" |
| 82 | versionCanary="${versionExplode[0]}.${versionExplode[1]}" |
| 83 | set_manifest_field "version" "$versionCanary" |
| 84 | set_manifest_field "version_name" "$versionCanary-$channel" |
| 85 | else |
| 86 | # As it isn't a release version, setting version number to 0 so it |
| 87 | # cannot be uploaded to the Chrome Web Store |
| 88 | set_manifest_field "version" "0" |
| 89 | set_manifest_field "version_name" "$version-$channel" |
| 90 | fi |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 91 | else |
| 92 | # It is a release version, set the version fields accordingly. |
| 93 | set_manifest_field "version" "${version:1}" |
| 94 | set_manifest_field "version_name" "${version:1}-$channel" |
| 95 | fi |
| 96 | |
Adrià Vilanova Martínez | 9aa2931 | 2022-01-16 02:42:46 +0100 | [diff] [blame] | 97 | if [[ $channel == "canary" ]]; then |
| 98 | # Change manifest.json to label the release as canary |
| 99 | set_manifest_field "name" "__MSG_appNameCanary__" |
| 100 | |
| 101 | if [[ $browser == "gecko" ]]; then |
| 102 | # Change the extension ID |
| 103 | set_manifest_field "id" "twpowertools+canary@avm99963.com" |
| 104 | fi |
| 105 | elif [[ $channel == "beta" ]]; then |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 106 | # Change manifest.json to label the release as beta |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 107 | set_manifest_field "name" "__MSG_appNameBeta__" |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 108 | |
| 109 | if [[ $browser == "gecko" ]]; then |
| 110 | # Change the extension ID |
| 111 | set_manifest_field "id" "twpowertools+beta@avm99963.com" |
| 112 | fi |
avm99963 | 75814b8 | 2020-08-09 20:33:23 +0200 | [diff] [blame] | 113 | else |
| 114 | if [[ $browser == "gecko" ]]; then |
| 115 | set_manifest_field "name" "__MSG_appNameGecko__" |
| 116 | fi |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 117 | fi |
| 118 | |
| 119 | # Create ZIP file for upload to the Chrome Web Store |
| 120 | mkdir -p out |
avm99963 | 6c35730 | 2020-08-09 19:54:08 +0200 | [diff] [blame] | 121 | rm -rf out/twpowertools-$version-$browser-$channel.zip |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 122 | (cd dist/$browser && |
| 123 | zip -rq ../../out/twpowertools-$version-$browser-$channel.zip * -x "*/.git*" \ |
Adrià Vilanova Martínez | 9aa2931 | 2022-01-16 02:42:46 +0100 | [diff] [blame] | 124 | -x "*/\.DS_Store" -x "*/OWNERS") |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 125 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 126 | echo "Done!" |