Introduction:

During development, it is often necessary to package to QA for testing. This kind of repeatable work, I realized through the way of script. Have QA execute scripts on a configured computer to implement packaged tests. A fun!

Project background

Mac

The project and script are all executed on the Mac system;

bash

The scripting language uses bash, so you need your computer to support the execution of bash scripts. Mac OS support by default!

React-Native

The project is developed using the React-Native framework, so some code in the script is specific to RN.

Prepare before packing

Certificate of configuration

Project compiled successfully

Dandelion generation application

Packaging process

Generate the exportOptions plist file

The exportOptions configuration file is the configuration item that uses xcode to guide the package.

Description of configuration items:

  1. provisioningProfilesThe App Bundle ID is the key, and the mobileprovision file name is the value.
  2. methodDetermine the types of packages to export, including: app-Store, ad-hoc, Package, Enterprise, Development, developer-ID, and Mac-Application;
  3. teamIDDeveloper ID, which can be viewed in keychain or on the developer website;

Update the code

git pull
yarn install
yarn link
Copy the code

Clear the cache

# use Cocoapods
xcodebuild clean -workspace <workspace_path>  -scheme <app_scheme> -configuration <Debug Or Release>

# Don't use Cocoapods
xcodebuild clean -project <project_path>  -scheme <app_scheme> -configuration <Debug Or Release>
Copy the code

Code description:

  1. <workspace_path>The absolute path to the project.xcWorkspace;
  2. <project_path>The absolute path of the project. Xcodeproj;
  3. <app_scheme>Scheme for project App (non-extension App);
  4. <Debug Or Release>Compile environment, Debug Or Release;

The scheme of App must be the same as scheme name of Manager Schemes in the project.


Begin to compile

# use Cocoapods
xcodebuild archive -workspace <workspace_path> -scheme <app_scheme> -archivePath <xcarchive_path>

# Don't use Cocoapods
xcodebuild archive -project <project_path> -scheme <app_scheme> -archivePath <xcarchive_path>
Copy the code

Code description:

  1. <workspace_path>Same as above;
  2. <project_path>Same as above;
  3. <app_scheme>Same as above;
  4. <xcarchive_path>Export the achive file path.

The export of ipa package

xcodebuild -exportArchive -archivePath <xcarchive_path> -exportPath <export_ipa_path> -exportOptionsPlist <exportOptionsPlist_path>
Copy the code

Code description:

  1. <xcarchive_path>Achive File path;
  2. <export_ipa_path>Ipa file export path;
  3. <exportOptionsPlist_path>Guide package configuration plIST file;

Upload it to a dandelion

curl -F "file=@{$filePath}" \
-F "uKey={$uKey}" \
-F "_api_key={$apiKey}" \
https://www.pgyer.com/apiv1/app/upload
Copy the code

Code description:

  1. {$filePath}Is the path of the application installation package.
  2. {$uKey}Is the developer’s user Key, in the application management -API view;
  3. {$apiKey}Is the developer’s API Key, in the application management -API view;

If the upload succeeds, the interface returns the application details in JSON format. If the upload fails, an error message is displayed.

The complete code

#! /bin/sh

# echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ began to execute the script ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" 

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the script configuration information -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
 #Project directory BASE_PROJECT=''  #The name of the project PROJECT_NAME=""  #Compile mode, with Debug Release by default CONFIGURATION_TARGET=Release  #Compile the path BUILDPATH=~/Desktop  #Export the PLIST required by ipA ADHOCExportOptionsPlist=~/exportOptions.plist  # archivePath ARCHIVEPATH=${BUILDPATH}/${PROJECT_NAME}/${PROJECT_NAME}.xcarchive  #Ipa storage path IPAPATH=${BUILDPATH}/ipa_$(date +%F-%T)  #Dandelion key uKey=""  #Dandelion apiKey apiKey=""  #Dandelion download address DOWNLOAD_PATH=""  # # -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- to determine whether a file/directory exists -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  if [ ! -d ${BASE_PROJECT} ]; then Echo "\033[31m ${BASE_PROJECT}" exit 1 elif [ ! -d ${BASE_PROJECT}/ios ]; then Echo "\033[31m ${BASE_PROJECT}/ios" exit 1 elif [ ! -f ${ADHOCExportOptionsPlist} ]; then Echo "\033[31m${ADHOCExportOptionsPlist} "\033[0m" exit 1 fi  #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- whether certificate is set up correctly -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --    Echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ update code ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" cd ${BASE_PROJECT} # git checkout dev # git pull origin dev # npm install # react-native link  Echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ clear the cache ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" cd ./ios watchman watch-del-all # npm start -- --reset-cache xcodebuild clean -project ${PROJECT_NAME}.xcodeproj -scheme ${PROJECT_NAME} -configuration ${CONFIGURATION_TARGET}  Echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ began to compile ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" xcodebuild archive -project ${PROJECT_NAME}.xcodeproj -scheme ${PROJECT_NAME} -archivePath ${ARCHIVEPATH} -configuration ${CONFIGURATION_TARGET} #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- whether editor success -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  if [ ! -d "$ARCHIVEPATH" ] then Echo "\033[31m failed to compile! \033[0m" exit 1 fi  Echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ the export of ipa ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" xcodebuild -exportArchive -archivePath ${ARCHIVEPATH} -exportPath ${IPAPATH} -exportOptionsPlist ${ADHOCExportOptionsPlist}  #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- whether export success -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  if [ ! -d "$IPAPATH" ] then Echo "\033[31m failed to export IPA! \033[0m" exit 1 fi  Echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ upload dandelion ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" curl -F "file=@$IPAPATH/${PROJECT_NAME}.ipa" \ -F "uKey=$uKey" \ -F "_api_key=$apiKey" \ http://www.pgyer.com/apiv1/app/upload  #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - open a browser to download address -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  open -a "/Applications/Safari.app" ${DOWNLOAD_PATH}  Echo "\ [42, 033, 37 m ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ packaging success ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \ [0 033 m" exit 1 Copy the code

Problems encountered during the packaging process

Script execution error: Permission denied

# Solution:
Chmod 777 File pathCopy the code

References:

  1. Xcode command line script packaging;
  2. Dandelion: Quickly upload an app with a single command;
  3. Building from the Command Line with Xcode FAQ

This article is formatted using MDNICE