OLD | NEW |
| (Empty) |
1 #!/bin/sh | |
2 | |
3 set -e # abort on error | |
4 set -x # expand and print executed commands | |
5 | |
6 SDK_DEVICE=$1 | |
7 SDK_VERSION=$2 | |
8 SDK="${SDK_DEVICE}${SDK_VERSION}" | |
9 | |
10 IOS_SIMULATOR_VERSION=${3:-SDK_VERSION} | |
11 | |
12 # This is redirecting all output to file. Which means that stdout gets nothing. | |
13 # And in particular environment of CircleCI, it's a Good Thing for couple of rea
sons: | |
14 # - CCI web UI is extremely slow when trying to display a lengthy build log | |
15 # - even if the log is displayed, it's limited to first 400k chars | |
16 # - the system allows downloading the log, but only first 4M of it | |
17 # - even if the error happens in first 400k, the system rarely detects it correc
tly, pointing | |
18 # at irrelevant warnings or noncritical errors instead. It may not be completely
a CCI fault | |
19 # as xcodebuild output is quite cryptic (so cryptic that it warrants xcrun exist
ence). | |
20 LOGFILE="${CIRCLE_ARTIFACTS}/build_${SDK}.log" | |
21 exec > $LOGFILE 2>&1 | |
22 | |
23 # xcodebuild default build path must be overridden because it stores | |
24 # the compilation products at a cryptic temporary path but we need | |
25 # to copy it away for archivation and deployment | |
26 BUILD_DIR=$PWD/$SDK | |
27 | |
28 CI_BUILD_NUMBER=${CIRCLE_BUILD_NUM} | |
29 CI_VERSION_NUMBER=${APP_VERSION} | |
30 | |
31 # Resulting build artifact name (ending with .app, .ipa, .dSYM and whatever) | |
32 ARTIFACT_NAME="${XCODE_SCHEME}-${SDK}-${CI_BUILD_NUMBER}" | |
33 | |
34 # Keep an eye on used ruby version, in case future Xcode/Circle updates | |
35 # introduce incompatible expectations again | |
36 ruby -v | |
37 | |
38 # Note to the following construction and usage of ARTIFACT_DIR: | |
39 # It is effectively the same folder as CONFIGURATION_BUILD_DIR made from | |
40 # ${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}. But CONFIGURATION_BUILD_DIR is ign
ored in | |
41 # "Copy Pod Resources" step since Pods 1.0 - the path is constructed directly fr
om $BUILD_DIR. | |
42 # Custom CONFIGURATION_BUILD_DIR results in builds landing in custom location bu
t then being | |
43 # attempted to copy from a different location based on $BUILD_DIR. | |
44 # So BUILD_DIR, the root var of all config must be modified, and the resulting | |
45 # CONFIGURATION_BUILD_DIR then constructed manually. | |
46 # https://github.com/CocoaPods/CocoaPods/issues/5358 | |
47 | |
48 case $SDK in | |
49 iphonesimulator*) | |
50 CONFIGURATION=Debug | |
51 # BUILD TEST | |
52 xcodebuild \ | |
53 -sdk $SDK \ | |
54 -workspace "$XCODE_WORKSPACE" \ | |
55 -scheme "$XCODE_SCHEME" \ | |
56 -configuration "$CONFIGURATION" \ | |
57 -destination "platform=iOS Simulator,name=iPhone SE,OS=${IOS_SIMULATOR_VERSI
ON}" \ | |
58 BUILD_DIR=$BUILD_DIR \ | |
59 CI_BUILD_NUMBER=$CI_BUILD_NUMBER \ | |
60 CI_VERSION_NUMBER=$CI_VERSION_NUMBER \ | |
61 test # build-test has the main build in its xcodeproj dependencies | |
62 # ZIP AND COPY APP so that it's downloadable from artifacts | |
63 ARTIFACT_DIR=$BUILD_DIR/${CONFIGURATION}-iphonesimulator | |
64 ditto -ck --keepParent --norsrc "${ARTIFACT_DIR}/${XCODE_SCHEME}.app" "$CIRCL
E_ARTIFACTS/${ARTIFACT_NAME}.zip" | |
65 ;; | |
66 iphoneos*) | |
67 # BUILD PRODUCT | |
68 CONFIGURATION=Devbuild | |
69 # Specific name for archive | |
70 ARTIFACT_DIR=$BUILD_DIR/${CONFIGURATION}-iphoneos | |
71 ARCHIVE_NAME="${ARTIFACT_DIR}/${ARTIFACT_NAME}.xcarchive" | |
72 # The folder where exported IPA is stored | |
73 IPA_LOCATION="${ARTIFACT_DIR}/${ARTIFACT_NAME}" | |
74 xcodebuild \ | |
75 -sdk $SDK \ | |
76 -workspace "$XCODE_WORKSPACE" \ | |
77 -scheme "$XCODE_SCHEME" \ | |
78 -configuration "$CONFIGURATION" \ | |
79 -archivePath "$ARCHIVE_NAME" \ | |
80 BUILD_DIR=$BUILD_DIR \ | |
81 CI_BUILD_NUMBER=$CI_BUILD_NUMBER \ | |
82 CI_VERSION_NUMBER=$CI_VERSION_NUMBER \ | |
83 archive # no test | |
84 if [ "$CIRCLE_BRANCH" == "master" ]; then | |
85 echo "Branch '${CIRCLE_BRANCH}', packing xcarchive to artifacts" | |
86 # zip the archive and save it to artifacts | |
87 # @TODO upload to Eyeo signing service | |
88 ditto -ck --keepParent --norsrc "$ARCHIVE_NAME" "${ARCHIVE_NAME}.zip" | |
89 cp ${ARCHIVE_NAME}.zip $CIRCLE_ARTIFACTS | |
90 else | |
91 echo "Branch '${CIRCLE_BRANCH}', exporting xcarchive to IPA" | |
92 # Export the built xcarchive as IPA | |
93 # | |
94 # One would be tempted to add -exportSigningIdentity parameter here, but | |
95 # xcodebuild actively fights it with error: | |
96 # "The flag -exportSigningIdentity cannot be specified along with -exportO
ptionsPlist" | |
97 # where -exportOptionsPlist is mandated by warning: | |
98 # "exportArchive without -exportOptionsPlist is deprecated" | |
99 # SO we must trust xcodebuild export to map all signing assets correctly | |
100 # In CI environment, it has only one cert and a minimal necessary provisio
ning available | |
101 # but on real world devbox with half a dozen of each it could be a problem | |
102 xcodebuild \ | |
103 -exportArchive \ | |
104 -exportOptionsPlist "$HOME/$CIRCLE_PROJECT_REPONAME/deploy/ExportOptions.p
list" \ | |
105 -archivePath "$ARCHIVE_NAME" \ | |
106 -exportPath "$IPA_LOCATION" # Path is a folder, NOT THE IPA FILENAME ITSEL
F! | |
107 # Copy to Circle artifacts. The source name is fixed by xcodebuild | |
108 cp "${IPA_LOCATION}/${XCODE_SCHEME}.ipa" "${CIRCLE_ARTIFACTS}/${ARTIFACT_N
AME}.ipa" | |
109 # For some reason, dSYMs are not in xcarchive but left in the build dir | |
110 mv ${ARTIFACT_DIR}/*.dSYM ${ARCHIVE_NAME}/dSYMs | |
111 # ZIP DSYMs directly to Circle artifacts | |
112 # ditto creates Finder-compress-compatible package, where Apple service ma
y have a problem accepting plain pkzip | |
113 ditto -ck --keepParent --rsrc --sequesterRsrc "${ARCHIVE_NAME}/dSYMs" "$CI
RCLE_ARTIFACTS/${ARTIFACT_NAME}.dSYM.zip" | |
114 # UPLOAD AND CLEAN | |
115 $HOME/$CIRCLE_PROJECT_REPONAME/deploy/hockey.sh \ | |
116 "${CIRCLE_ARTIFACTS}/${ARTIFACT_NAME}.ipa" \ | |
117 "${CIRCLE_ARTIFACTS}/${ARTIFACT_NAME}.dSYM.zip" | |
118 fi | |
119 ;; | |
120 esac | |
OLD | NEW |