-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxcode-build-testflight.sh
executable file
·164 lines (145 loc) · 3.89 KB
/
xcode-build-testflight.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/sh
########################################################
# #
# Generic App build and Testflight Submission #
# Author: Bruno Koga, October 2013 #
# #
########################################################
USAGE_MESSAGE="
Usage:
-c Use CocoaPods flag
-p PROJECT_NAME
-s SCHEME_NAME
-v VERSION
-i ICON_PATH
-n APP_NAME
-t TESTFLIGHT_TEAM_TOKEN
-a TESTFLIGHT_API_TOKEN
-d TESTFLIGHT_DISTRIBUTION_LIST
-r CERTIFICATE_NAME
-f CONFIGURATION
-h Help Message"
USE_COCOA_PODS=NO
PROJECT_NAME=""
SCHEME_NAME=""
ICON_PATH=""
APP_NAME=""
TESTFLIGHT_TEAM_TOKEN=""
TESTFLIGHT_API_TOKEN=""
TESTFLIGHT_DISTRIBUTION_LIST=""
CERTIFICATE_NAME=""
CONFIGURATION=""
function test_args {
if [[ $OPTARG = -* ]]; then
echo "Invalid argument for -$opt: $OPTARG"
exit 1
fi
}
while getopts ":chp:s:f:i:n:t:a:d:r:" opt; do
case $opt in
c)
USE_COCOA_PODS=YES
;;
p)
test_args
PROJECT_NAME=$OPTARG
;;
s)
test_args
SCHEME_NAME=$OPTARG
;;
i)
test_args
ICON_PATH=$OPTARG
;;
n)
test_args
APP_NAME=$OPTARG
;;
t)
test_args
TESTFLIGHT_TEAM_TOKEN=$OPTARG
;;
a)
test_args
TESTFLIGHT_API_TOKEN=$OPTARG
;;
d)
test_args
TESTFLIGHT_DISTRIBUTION_LIST=$OPTARG
;;
r)
test_args
CERTIFICATE_NAME=$OPTARG
;;
f)
test_args
CONFIGURATION=$OPTARG
;;
h)
echo "$USAGE_MESSAGE"
exit
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
:)
echo "Option -$OPTARG requires an argument"
;;
esac
done
WORKSPACE_FILE=""
PROJECT_FILE=""
if [[ $USE_COCOA_PODS = YES ]]; then
pod install
WORKSPACE_FILE="${PROJECT_NAME}.xcworkspace"
else
PROJECT_FILE="${PROJECT_NAME}.xcodeproj"
fi
# Workspace and build configuration
TARGET_SDK="iphoneos" # Target SDK: iphoneos
BUILD_DIR="build" # Directory where the build is generated
BUILD_ARCHIVED_DIR="BuildArchived" # Directory with the history of builds
#Release Notes
TESTFLIGHT_RELEASE_NOTES_FILE="ios_testflight-releasenotes"
# fix for the newest sdk
# Only export the environment variable if the location exists,
# otherwise it breaks the signing process!
if [ -f "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate" ]
then
echo Export environment variable for codesign_allocate location
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
fi
PWD=`pwd`
PROJECT_BUILDDIR="${PWD}/build/${CONFIGURATION}-${TARGET_SDK}"
CURRENT_DIR="${PWD}/${TARGET_NAME}"
#changing the build version
INFO_PLIST_PATH="${CURRENT_DIR}/${PROJECT_NAME}/${PROJECT_NAME}-Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${SVN_REVISION}" "$INFO_PLIST_PATH"
# compile project
echo Building Project
xcodebuild \
-workspace "${WORKSPACE_FILE}" \
-scheme "${SCHEME_NAME}" \
-configuration "${CONFIGURATION}" \
OBJROOT="${PWD}/build" \
SYMROOT="${PWD}/build" \
clean build
# .ipa file generation
echo Generating .ipa file
echo "${PROJECT_BUILDDIR}"
# change to the project build dir to archive
/usr/bin/xcrun -sdk "${TARGET_SDK}" PackageApplication -v "${PROJECT_BUILDDIR}/${APP_NAME}.app" -o "${PROJECT_BUILDDIR}/${APP_NAME}.ipa" --sign "${CERTIFICATE_NAME}"
#zipping the .dSYM to send to Testflight
echo Generating zip file
/usr/bin/zip -r "${PROJECT_BUILDDIR}/${APP_NAME}.app.dSYM.zip" "${PROJECT_BUILDDIR}/${APP_NAME}.app.dSYM"
# sends the .ipa file to TestFlight
echo Sending to TestFlight
curl http://testflightapp.com/api/builds.json -F file="@${PROJECT_BUILDDIR}/${APP_NAME}.ipa" \
-F dsym="@${PROJECT_BUILDDIR}/${APP_NAME}.app.dSYM.zip" \
-F api_token="${TESTFLIGHT_API_TOKEN}" \
-F team_token="${TESTFLIGHT_TEAM_TOKEN}" \
-F notes="This build was uploaded via the upload API" \
-F notify=False \
-F distribution_lists="${TESTFLIGHT_DISTRIBUTION_LIST}"
echo Submission ended