Lmsgsendnilself

Uninhibited Soul, Free Craziness

iOS自动化打包脚本

| Comments

  最近自己在做新项目,利用空余时间研究写了下自动化打包脚本,打包需要两个文件的配置,一个是打包脚本文件,另一个则是打相应包所需配置plist文件。

以打ad-hoc包为例,ad-hoc.plist配置如下

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>compileBitcode</key>
  <false/>
  <key>method</key>
  <string>ad-hoc</string>
  <key>teamID</key>
  <string>your apple developer teamID</string>
</dict>
</plist>


autobuild.py脚本内容如下:

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
#coding:utf-8
import subprocess
import os
from datetime import datetime
import urllib, httplib
import json

def exeCommand(cmd, needResult=False):
    try:
        if needResult:
            process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
            process.wait()
            return process.stdout.read().strip()
        else:
            process = subprocess.Popen(cmd, shell=True)
            process.wait()
    except Exception, e:
        print(e)

def cleanLastBuild():
    print("clean last compile")

    exeCommands("rm -rf build")

def beginNewBuild():
    print("start this compile")

    exeCommands('xcodebuild archive -workspace yourprojectWorkspace.xcworkspace -scheme yourProjectScheme -configuration  DailyBuild -derivedDataPath build -archivePath ./build/Products/yourproject.xcarchive')

def exportIpa():
    print("finish compile,making ipa")

    exeCommands('xcodebuild -exportArchive -archivePath ./build/Products/yourproject.xcarchive -exportOptionsPlist ./adhoc.plist -exportPath ./build/Products')

    print("finish making ipa: ./build/Products/yourproject.ipa" )


#Pgyer key
uKey          = "xxxxxxxxxxxxxxxxxxx"
aKey          = "xxxxxxxxxxxxxxxxxxx"

def uploadIpa():

    cmdstr = u'curl  -F "file=@./build/Products/yourproject.ipa"  -F "uKey=%s" -F "_api_key=%s"  http://www.pgyer.com/apiv1/app/upload' % (uKey, aKey)
    exeCommands(cmdstr)

#autobuild extrance
if __name__ == '__main__':

    os.chdir(os.path.abspath(os.path.dirname(__file__)))


    cleanLastBuild()
    beginNewBuild()

    exportIpa()
    uploadIpa()

当我们需要打包时,进入命令行终端 输入
rvm system
然后执行
python autobuild.py
就会完成自动打包了。

UPDATE: 详细代码参考Github: AutoBuild

Comments