LoginSignup
5
5

More than 5 years have passed since last update.

CFBundleVersion をカウントアップしつつ TestFlight に送り、idobata に通知するスクリプト

Last updated at Posted at 2014-07-22

背景

僕は今のところ Version (CFBundleShortVersionString) を 1.0.0 のように設定し、Build (CFBundleVersion) を単純にビルドごとに 1, 2, 3... と連番でカウントアップするような運用にしています。

TestFlight に投げるときにわざわざ手動で Build を上げて、git でコミットして、tag 打って...とやるのは面倒なのでスクリプト化しました。

準備

  • direnv が必要です (brew install direnv で入ります)
  • shenzhen が必要です (gem install shenzhen で入ります)

設定

.envrc をプロジェクトルートに作ります。リポジトリにはコミットしない方がいいでしょう。

.envrc
export PRODUCT_NAME=YOUR_PRODUCT_NAME
export TESTFLIGHT_API_TOKEN=YOUR_API_TOKEN
export TESTFLIGHT_TEAM_TOKEN=YOUR_TEAM_TOKEN
export TESTFLIGHT_DISTRIBUTION_LISTS="testers, developers"
export IDOBATA_ENDPOINT_URL=YOUR_ENDPOINT_URL

スクリプト

build.sh
#!/bin/sh

#
# $ brew install direnv
# $ cp dotenvrc .envrc && vim .envrc
# $ gem install shenzhen && rbenv rehash
# $ ./build.sh -m "hoge"
#

_usage() {
  echo "Usage:"
  echo "${0} -m MESSAGE"
  exit 1
}

while getopts :m: OPT
do
  case $OPT in
    "m" ) FLG_M="TRUE"; MESSAGE="$OPTARG";;
    :|\?) _usage;;
  esac
done

shift `expr ${OPTIND} - 1`

[ "${FLG_M}" != "TRUE" ] && _usage

# bump build version
plistFile=${PRODUCT_NAME}/${PRODUCT_NAME}-Info.plist
bundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $plistFile)
shortVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $plistFile)
bundleVersion=$(($bundleVersion + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bundleVersion" $plistFile

# # commit && tag
git add $plistFile
git commit -m "build $shortVersion($bundleVersion)"
git tag $shortVersion-$bundleVersion

# build
ipa build

# testflight
ipafile=$(ls *.ipa)
dsymfile=$(ls *.dSYM.zip)
response=$(curl http://testflightapp.com/api/builds.json \
    -F file=@$ipafile \
    -F dsym=@$dsymfile \
    -F api_token=$TESTFLIGHT_API_TOKEN \
    -F team_token=$TESTFLIGHT_TEAM_TOKEN \
    -F notes="$MESSAGE" \
    -F notify=True \
    -F distribution_lists="$TESTFLIGHT_DISTRIBUTION_LISTS"
  )

# notify
title="$PRODUCT_NAME $shortVersion($bundleVersion) is now available."
curl --data-urlencode "source=<p>$title</p><pre>$response</pre>" -d format=html $IDOBATA_ENDPOINT_URL
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5