1. shell

Folder buildScript

I’ve created a buildScript folder in the project (demo) root directory to store it in

  • 1. Script file abuild.sh
  • 2. The configuration file AppStoreExportOptions. Plist

Folder autoBuild

This file is automatically generated after the script is executed for storage

  • xcarchive
  • Ipa etc.

1.1 xcodebuild:

Function Parameter description Command: man xcodebuild Displays targets. Scheme command: xcodebuild-list

Basic configuration :(since I put the script in the project root directory, I only need to change scheme here)

BuildConfiguration=Release Package Release or Debug
SCHEMENAME=demo      The project scheme name is demo
SOURCEPATH=$PWD    # Project path

DATE=`date +%Y%m%d_%H%m`
Package the target path
IPAPATH=$SOURCEPATH/autoBuild/$DATE
IPANAME=$SCHEMENAME_$DATE.ipa
Copy the code

Clean:

# clean
xcodebuild clean \
-workspace $SOURCEPATH/$SCHEMENAME.xcworkspace \
-scheme ${SCHEMENAME} \
-configuration ${BuildConfiguration}
if[[$?!= 0]];then
    exit
fi
Copy the code

Archive:

This is xcode9.3 and xcrun is no longer used.

# archive
xcodebuild archive \
-workspace $SOURCEPATH/$SCHEMENAME.xcworkspace \
-scheme ${SCHEMENAME} \
-configuration $BuildConfiguration \
-archivePath $IPAPATH/${SCHEMENAME}.xcarchive

if [ -e $IPAPATH ]; then
    echo "build OK"
else
    echo "build fail"
    exit 1
fi
Copy the code

– exportArchive:

Export the IPA package
xcodebuild -exportArchive \
-archivePath $IPAPATH/${SCHEMENAME}.xcarchive \
-exportPath ${IPAPATH}/${SCHEMENAME} \
-exportOptionsPlist ${SOURCEPATH}/buildScript/AppStoreExportOptions.plist

if [ -e ${IPAPATH}/${SCHEMENAME} ]; then
    osascript -e 'Display notification "Packing successful!" with title "${IPAPATH}/${SCHEMENAME}"'
    echo "Archive OK"
    open ${IPAPATH}/${SCHEMENAME}
else
    echo "Archive fail"
fi
Copy the code

Once packaged successfully, execute osAScript push notifications to your MAC desktop, and then open the IPA path with Finder

1.2 validate + upload:

usealtoolPublish to iTunes Connect

altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
[email protected]
applepassword=xxx

#validate
"$altoolPath" --validate-app \
-f "${IPAPATH}/${SCHEMENAME}/${IPANAME}"\
-u "$appleid"\
-p "$applepassword"\
-t ios \
osascript -e 'display notification "Release To AppStore" with title "Validate Complete!" '

#upload
"$altoolPath" --upload-app \
-f "${IPAPATH}/${SCHEMENAME}/${IPANAME}" \
-u "$appleid" -p "$applepassword" \
-t ios \
--output-format xml
osascript -e 'display notification "Release To AppStore" with title "Upload Complete!" '
Copy the code

If you need to upload IPA to other platforms, such as FIR, dandelion, just add the upload script here

2. Automator

Workflow on iOS, Automator on Mac. Automator + shell doesn’t even need to use a terminal to type a command

CSDN reference link

  • Open the Automator
  • Creating a Service
  • Modify theService receivedService program

  • Join process 1
    1. On the left side of the Automator app screen, click”variable, type in the search boxpath“, drag it to the middle area.
    2. Below”The path“, select project (Demo),complete.
  • Join Process 2
    1. On the left side of the Automator app screen, click”operation, type in the search boxapple“, select”Run appleScript“Drag to the middle area.
    2. will(* Your script goes here *)Replace:
    tell application "Terminal"
      activate
      do script "cd " & input & " && . buildScript/ABuild.sh"
    end tell
    Copy the code
  1. command + sSave the Workflow
  2. Finally, open Xcode to see if the service exists

Conclusion:

In the process of learning shell, I prepared to write something for practice, so I came into contact with packaging tools such as XcodeBuild, Altool upload and FIR, and then I came into contact with Automator of Mac and Workflow in iOS. So a lot of unskilled knowledge points should be personally to achieve again, so there will be a lot of opportunities to understand by analogy.

Github link for this article Workflow,shell

Automator official link AlTool official link