2014-11-02 15:27:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
cd "${BASH_SOURCE%/*}"
|
2014-11-18 13:12:40 +00:00
|
|
|
source ./bashlib
|
2018-06-05 18:06:55 +00:00
|
|
|
trap 'c=$BASH_COMMAND s=$?; (( s )) && echo >&2 "ERROR: $s: $c"; exit $s' EXIT
|
2018-06-05 16:49:03 +00:00
|
|
|
set -e
|
2014-11-02 15:27:02 +00:00
|
|
|
cd ..
|
|
|
|
export PATH+=:/usr/libexec
|
|
|
|
|
|
|
|
addPlistWithKey() {
|
|
|
|
local key=$1 type=$2 value=$3 plist=${4:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
|
|
|
|
|
|
|
|
PlistBuddy -c "Delete :'$key'" "$plist" 2>/dev/null || true
|
|
|
|
PlistBuddy -c "Add :'$key' '$type' '$value'" "$plist"
|
|
|
|
}
|
|
|
|
setPlistWithKey() {
|
|
|
|
local key=$1 value=$2 plist=${3:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
|
|
|
|
|
|
|
|
PlistBuddy -c "Set :'$key' '$value'" "$plist"
|
|
|
|
}
|
|
|
|
getPlistWithKey() {
|
|
|
|
local key=$1 plist=${2:-"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"}
|
|
|
|
|
|
|
|
PlistBuddy -c "Print :'$key'" "$plist"
|
|
|
|
}
|
|
|
|
setSettingWithTitle() {
|
|
|
|
local i title=$1 value=$2 plist=${3:-"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/Settings.bundle/Root.plist"}
|
|
|
|
|
|
|
|
for (( i=0; 1; ++i )); do
|
|
|
|
PlistBuddy -c "Print :PreferenceSpecifiers:$i" "$plist" &>/dev/null || break
|
|
|
|
inf "Checking preference specifier $i"
|
|
|
|
|
|
|
|
[[ $(PlistBuddy -c "Print :PreferenceSpecifiers:$i:Title" "$plist" 2>/dev/null) = $title ]] || continue
|
|
|
|
|
|
|
|
inf "Correct title, setting value."
|
|
|
|
PlistBuddy -c "Set :PreferenceSpecifiers:$i:DefaultValue $value" "$plist"
|
|
|
|
break
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2017-04-14 04:43:34 +00:00
|
|
|
case $PLATFORM_NAME in
|
|
|
|
macosx) platform=mac ;;
|
2017-04-14 17:08:23 +00:00
|
|
|
iphone*) platform=ios ;;
|
2017-04-14 04:43:34 +00:00
|
|
|
*) ftl 'ERROR: Unknown platform: %s.' "$PLATFORM_NAME"; exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
2017-05-04 18:30:50 +00:00
|
|
|
description=$(git describe --always --dirty --long --match "*-$platform*")
|
2017-04-14 04:43:34 +00:00
|
|
|
version=${description%-g*} build=${version##*-} version=${version%-$build}
|
2017-05-04 18:30:50 +00:00
|
|
|
version=${version//-$platform/} version=${version//-/.} commit=${description##*-g}
|
2014-11-02 15:27:02 +00:00
|
|
|
|
|
|
|
addPlistWithKey GITDescription string "$description"
|
2017-04-01 04:43:44 +00:00
|
|
|
setPlistWithKey CFBundleVersion "$(hr "${version%%.*}" 14).${version#*.}"
|
2016-07-06 05:24:58 +00:00
|
|
|
setPlistWithKey CFBundleShortVersionString "$version"
|
2014-11-02 15:27:02 +00:00
|
|
|
|
|
|
|
setSettingWithTitle "Build" "$commit"
|
|
|
|
setSettingWithTitle "Version" "$version"
|
|
|
|
setSettingWithTitle "Copyright" "$(getPlistWithKey NSHumanReadableCopyright)"
|
|
|
|
|
|
|
|
if [[ $DEPLOYMENT_LOCATION = YES ]]; then
|
|
|
|
# This build is a release. Do some release checks.
|
2017-04-30 03:03:50 +00:00
|
|
|
fabricPlist="$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/Fabric.plist"
|
2014-11-02 15:27:02 +00:00
|
|
|
passed=1
|
|
|
|
[[ $description != *-dirty ]] || \
|
|
|
|
{ passed=0; err 'ERROR: Cannot release a dirty version, first commit any changes.'; }
|
2017-04-14 04:43:34 +00:00
|
|
|
[[ $build == 0 ]] || \
|
|
|
|
{ passed=0; err 'ERROR: Commit is not tagged for release, first tag accordingly.'; }
|
2017-04-30 03:03:50 +00:00
|
|
|
[[ -r "$fabricPlist" && $(PlistBuddy -c "Print :'API Key'" "$fabricPlist" 2>/dev/null) ]] || \
|
|
|
|
{ passed=0; err 'ERROR: Cannot release: Fabric API key is missing.'; }
|
2014-11-02 15:27:02 +00:00
|
|
|
(( passed )) || \
|
|
|
|
{ ftl "Failed to pass release checks. Fix the above errors and re-try. Aborting."; exit 1; }
|
|
|
|
fi
|