“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

preface

In iOS development, there’s a lot of time spent packing… Especially the iOS packages can only on the MAC packaging, in this regard is and is very annoying, there is no point in a lot of work, is time-consuming, so as a programmer, how can you waste time on these useless work, then introduce today is the automated packaging shell script, pure local running script

The script

Parameter configuration

The script execution needs a lot of parameters, some of these parameters are dynamic configuration, some of the runtime environment variables, so you need to declare a lot of variables, I write these variables according to my script, if there is a better way, thank you for guidance

CONFIGURATION="Debug" PUSH_MESSAGE=" no change "# BRANCH_NAME="2.2.0" While getopts ":e:b:m:" opt do case $opt in # e) ENVIRONMENT=$OPTARG; B) CONFIGURATION=$OPTARG; PUSH_MESSAGE=$OPTARG; ?). Echo "unknown parameter" exit 1; esac doneCopy the code

These are the variables that can be configured at startup

# pin robot TOKEN ROBOT_TOKEN="" # dandelion key PGYER_UESR_KEY=" XXXXX "PGYER_API_KEY=" XXXX" #xcode compile mode XCODE_CONFIGURATION=${CONFIGURATION}${ENVIRONMENT} # Project name APP_NAME=" XXX "# scheme scheme =${APP_NAME}_${ENVIRONMENT} # APP_PATH="${HOME}/${APP_NAME}"Copy the code

This is the fixed configuration write dead data

${APP_PATH}/${APP_NAME}. Xcworkspace ="${APP_PATH}/${APP_NAME} '/MARKETING_VERSION/{s/MARKETING_VERSION = //; s/; / /; s/^[[:space:]]*//; p; q; }' ${APP_PATH}/${APP_NAME}.xcodeproj/project.pbxproj`Copy the code

So that’s some of the information for getting the project

ARCHIVE_PATH="${PACKAGE_PATH}/ TMP /${APP_NAME}. Xcarchive DATE="$(DATE "+%Y%m%d%H% m% S")" IPA_PATH="${PACKAGE_PATH}/${ENVIRONMENT}_${CONFIGURATION}_V${VERSION_NUMBER}_${DATE}"Copy the code

That’s some of the packaged configuration information

compile

The compiler still uses xcodeBuild, which should be familiar to everyone, and can be found on the Internet. I won’t go into details here

echo "\n\n+++++++++++++++++clean+++++++++++++++++"
xcodebuild -workspace ${WORKSPACE} -scheme ${SCHEME} -configuration ${XCODE_CONFIGURATION} clean

echo "\n\n+++++++++++++++++build+++++++++++++++++"
xcodebuild -workspace ${WORKSPACE} -scheme ${SCHEME} -sdk iphoneos -configuration ${XCODE_CONFIGURATION} -archivePath ${ARCHIVE_PATH} archive
Copy the code

Packaging export

Packaging still needs to pay attention to the time, certificate configuration and so on, or need to study

echo "\n\n+++++++++++++++++export+++++++++++++++++"
xcodebuild -exportArchive -archivePath ${ARCHIVE_PATH} -exportPath ${IPA_PATH} -exportOptionsPlist ${ARCHIVE_OPTIONS_PATH}
Copy the code

Upload dandelions

Upload the ipA package to dandelion to make it easy for testers to download, provided of course you add the UDID of the test machine to the description file.

# upload file, Obtain return data JSON_TMP = ` curl - F "file = @ ${IPA_PATH} / ${APP_NAME}. The ipa" -f "uKey = ${PGYER_UESR_KEY}" -f "_api_key = ${PGYER_API_KEY}" Replace # https://upload.pgyer.com/apiv1/app/upload ` json \ \ json = ${JSON_TMP / / \ \ /} # get qr code connection QR_CODE_URL_TMP = ` echo ${json} | Jq '.data.appQRCodeURL' 'QR_CODE_URL=${QR_CODE_URL_TMP//\"/} echo "\n ${JSON} \ n "echo" image links: 033 [34 m ${QR_CODE_URL} \ \ [0 033 m"Copy the code

Nailing push

After completing all tasks, push the results of the execution of the task to the nail, you can directly @ tester, this is the rest of the typing communication, very convenient

Of course, nail robot, you can go to the official website of nail to check the corresponding documents

Echo "\ n \ n \ 033 [34 m + + + + + + + + + + + + + + + + + nailing push message + + + + + + + + + + + + + + + + + \ [0 033 m" # push CONTENT the CONTENT = "{\ 'msgtype:' markdown, \ 'markdown: {\' title ':' iOS release ', \ 'text' : '\ # # # # # release: ${VERSION_NUMBER} \ n \ # # # # # packaging mode: ${CONFIGURATION} \ n \ # # # # # release environments: ${ENVIRONMENT} [] () \ n \ # # # # # release time: $(date "+ % Y - m - H: % d % % % m: % S") \ n \ # # # # # content: \ n > ${PUSH_MESSAGE} \ n \ n \! [qrcode]($QR_CODE_URL) \n\n\ [@xxxxx]() \n\ '},\ 'at':{\ 'atMobiles':['xxxxx'], 'isAtAll':false\ }\ }" curl -H 'Content-Type:application/json' -d "${CONTENT}" "Https://oapi.dingtalk.com/robot/send?access_token=${ROBOT_TOKEN}" # remove packaging rm - rf $ARCHIVE_PATH cache fileCopy the code

conclusion

I wrote it in haste. If there is something you don’t understand, you can tell me in the comment section. I will reply to you