avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Prints help text |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 4 | function usage { |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 5 | cat << END |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 6 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 7 | Usage: $progname [--channel CHANNEL] |
| 8 | |
| 9 | optional arguments: |
| 10 | -h, --help show this help message and exit |
| 11 | -c, --channel indicates the channel of the release. Can be "beta" or "stable". |
| 12 | |
| 13 | END |
| 14 | } |
| 15 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 16 | # Updates manifest.json field |
| 17 | function set_manifest_field { |
| 18 | sed -i -E "s/\"$1\": \"[^\"]*\"/\"$1\": \"$2\"/" src/manifest.json |
| 19 | } |
| 20 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 21 | # Get options |
| 22 | opts=$(getopt -l "help,channel:" -o "hc:" -n "$progname" -- "$@") |
| 23 | eval set -- "$opts" |
| 24 | |
| 25 | channel=stable |
| 26 | |
| 27 | while true; do |
| 28 | case "$1" in |
| 29 | -h | --help ) usage; exit; ;; |
| 30 | -c | --channel ) channel="$2"; shift 2 ;; |
| 31 | * ) break ;; |
| 32 | esac |
| 33 | done |
| 34 | |
| 35 | if [[ $channel != "stable" && $channel != "beta" ]]; then |
| 36 | echo "channel parameter value is incorrect." |
| 37 | usage |
| 38 | exit |
| 39 | fi |
| 40 | |
| 41 | echo "Started building release..." |
| 42 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 43 | # This is the version name which git gives us |
| 44 | version=$(git describe --always --tags --dirty) |
| 45 | |
| 46 | # If the version name contains a hyphen then it isn't a release |
| 47 | # version. This is also the case if it doesn't start with a "v". |
| 48 | if [[ $version == *"-"* || $version != "v"* ]]; then |
| 49 | # As it isn't a release version, setting version number to 0 so it |
| 50 | # cannot be uploaded to the Chrome Web Store |
| 51 | set_manifest_field "version" "0" |
| 52 | set_manifest_field "version_name" "$version-$channel" |
| 53 | else |
| 54 | # It is a release version, set the version fields accordingly. |
| 55 | set_manifest_field "version" "${version:1}" |
| 56 | set_manifest_field "version_name" "${version:1}-$channel" |
| 57 | fi |
| 58 | |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 59 | if [[ $channel == "beta" ]]; then |
| 60 | # Change manifest.json to label the release as beta |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 61 | set_manifest_field "name" "__MSG_appNameBeta__" |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 62 | fi |
| 63 | |
| 64 | # Create ZIP file for upload to the Chrome Web Store |
| 65 | mkdir -p out |
avm99963 | bf0849a | 2020-08-08 16:16:04 +0200 | [diff] [blame^] | 66 | rm -rf out/twpowertools-$version-$channel.zip |
| 67 | zip -rq out/twpowertools-$version-$channel.zip src -x *.git* |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 68 | |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 69 | # Revert manifest.json changes |
| 70 | set_manifest_field "version" "0" |
| 71 | set_manifest_field "version_name" "dirty" |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 72 | if [[ $channel == "beta" ]]; then |
avm99963 | 666575f | 2020-08-08 15:40:39 +0200 | [diff] [blame] | 73 | set_manifest_field "name" "__MSG_appName__" |
avm99963 | 03d5409 | 2020-01-18 21:33:16 +0100 | [diff] [blame] | 74 | fi |
| 75 | |
| 76 | echo "Done!" |