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). |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 4 | # |
| 5 | # Precondition: webpack has already built the extension. |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 6 | |
| 7 | # Prints help text |
| 8 | function usage() { |
| 9 | cat <<END |
| 10 | |
| 11 | Usage: $progname [--channel CHANNEL --browser BROWSER] |
| 12 | |
| 13 | optional arguments: |
| 14 | -h, --help show this help message and exit |
Adrià Vilanova Martínez | 87e3505 | 2022-06-01 14:05:29 +0200 | [diff] [blame] | 15 | -c, --channel indicates the channel of the release. Can be "beta", |
| 16 | "stable" or "canary". Defaults to "stable". |
Adrià Vilanova Martínez | 8b63fb3 | 2022-05-29 23:26:50 +0200 | [diff] [blame] | 17 | -b, --browser indicates the target browser for the release. Can be |
Adrià Vilanova Martínez | 86fda49 | 2022-05-31 15:05:21 +0200 | [diff] [blame] | 18 | "chromium", "chromium_mv3, "edge" or "edge_mv3". |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 19 | -f, --fast indicates that the release shouldn't generate the |
| 20 | i18n credits JSON file. |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 21 | |
| 22 | END |
| 23 | } |
| 24 | |
| 25 | # Updates manifest.json field |
| 26 | function set_manifest_field() { |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 27 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" dist/$browser/manifest.json |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | # Get options |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 31 | opts=$(getopt -l "help,channel:,browser:,fast" -o "hc:b:f" -n "$progname" -- "$@") |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 32 | eval set -- "$opts" |
| 33 | |
| 34 | channel=stable |
Adrià Vilanova Martínez | b55b284 | 2024-05-28 19:28:49 +0200 | [diff] [blame] | 35 | browser= |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 36 | fast=0 |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 37 | |
| 38 | while true; do |
| 39 | case "$1" in |
| 40 | -h | --help) |
| 41 | usage |
| 42 | exit |
| 43 | ;; |
| 44 | -c | --channel) |
| 45 | channel="$2" |
| 46 | shift 2 |
| 47 | ;; |
| 48 | -b | --browser) |
| 49 | browser="$2" |
| 50 | shift 2 |
| 51 | ;; |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 52 | -f | --fast) |
| 53 | fast=1 |
| 54 | shift |
| 55 | ;; |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 56 | *) break ;; |
| 57 | esac |
| 58 | done |
| 59 | |
Adrià Vilanova Martínez | 87e3505 | 2022-06-01 14:05:29 +0200 | [diff] [blame] | 60 | if [[ $channel != "stable" && $channel != "beta" && $channel != "canary" ]]; then |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 61 | echo "channel parameter value is incorrect." >&2 |
| 62 | usage |
| 63 | exit |
| 64 | fi |
| 65 | |
Adrià Vilanova Martínez | 86fda49 | 2022-05-31 15:05:21 +0200 | [diff] [blame] | 66 | if [[ $browser != "chromium" && $browser != "chromium_mv3" && $browser != "edge" && $browser != "edge_mv3" ]]; then |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 67 | echo "browser parameter value is incorrect." >&2 |
| 68 | usage |
| 69 | exit |
| 70 | fi |
| 71 | |
| 72 | echo "Started building release..." |
| 73 | |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 74 | # Generate the credits for the translators if applicable |
avm99963 | 9bbb3a4 | 2020-12-29 03:29:44 +0100 | [diff] [blame] | 75 | if [[ $fast == 0 ]]; then |
| 76 | bash generatei18nCredits.bash |
| 77 | fi |
| 78 | |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 79 | # This is the version name which git gives us |
| 80 | version=$(git describe --always --tags --dirty) |
| 81 | |
| 82 | # If the version name contains a hyphen then it isn't a release |
| 83 | # version. This is also the case if it doesn't start with a "v". |
| 84 | if [[ $version == *"-"* || $version != "v"* ]]; then |
Adrià Vilanova Martínez | 87e3505 | 2022-06-01 14:05:29 +0200 | [diff] [blame] | 85 | if [[ $channel == "canary" && $version == "v"* && \ |
| 86 | $version != *"dirty" ]]; then |
| 87 | # If we're releasing a canary build and the build is not dirty, |
| 88 | # generate a version number |
| 89 | IFS='-' read -ra versionExplode <<< "${version:1}" |
| 90 | versionCanary="${versionExplode[0]}.${versionExplode[1]}" |
| 91 | set_manifest_field "version" "$versionCanary" |
| 92 | set_manifest_field "version_name" "$versionCanary-$channel" |
| 93 | else |
| 94 | # As it isn't a release version, setting version number to 0 so it |
| 95 | # cannot be uploaded to the Chrome Web Store |
| 96 | set_manifest_field "version" "0" |
| 97 | set_manifest_field "version_name" "$version-$channel" |
| 98 | fi |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 99 | else |
| 100 | # It is a release version, set the version fields accordingly. |
| 101 | set_manifest_field "version" "${version:1}" |
| 102 | set_manifest_field "version_name" "${version:1}-$channel" |
| 103 | fi |
| 104 | |
Adrià Vilanova Martínez | 87e3505 | 2022-06-01 14:05:29 +0200 | [diff] [blame] | 105 | if [[ $channel == "canary" ]]; then |
| 106 | # Change manifest.json to label the release as canary |
| 107 | set_manifest_field "name" "__MSG_appCanaryName__" |
| 108 | elif [[ $channel == "beta" ]]; then |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 109 | # Change manifest.json to label the release as beta |
| 110 | set_manifest_field "name" "__MSG_appBetaName__" |
| 111 | fi |
| 112 | |
| 113 | # Create ZIP file for upload to the Chrome Web Store |
| 114 | mkdir -p out |
| 115 | rm -rf out/translateselectedtext-$version-$browser-$channel.zip |
Adrià Vilanova Martínez | a197d86 | 2022-05-27 17:33:20 +0200 | [diff] [blame] | 116 | (cd dist/$browser && |
| 117 | zip -rq ../../out/translateselectedtext-$version-$browser-$channel.zip * \ |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 118 | -x "*/.git*" -x "*/\.DS_Store" -x "*/OWNERS") |
| 119 | |
avm99963 | f01af0e | 2020-12-26 23:11:10 +0100 | [diff] [blame] | 120 | echo "Done!" |