This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
build.rb
executable file
·134 lines (94 loc) · 5.37 KB
/
build.rb
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/ruby
#
# -couch <type> couchdb1.6, couchdb2.0, cloudantSAAS, cloudantlocal - default is couchdb1.6
# -platform <platfrom> OSX | iOS default is OSX
# -platform-version iOS version to test agasint (only supported for iOS)
# -hardware the simultated hardware to test against eg iPhone 4S (only supported for iOS)
# -D* gets passed into build.
# -ra true | false default is false flags if true it runs the replication acceptance tests
# in addition to the normal unit tests
#
require 'fileutils'
params = {}
arg_is_value = false
prev_arg = nil
ARGV.each do |arg|
#process arguments into a hash
unless arg_is_value
params[arg[1,arg.length] ] = nil
$prev_arg = arg[1,arg.length]
arg_is_value = true
else
params[$prev_arg] = arg
arg_is_value = false
end
end
#apply defaults
params["platform"] = "OSX" unless params["platform"]
params["couch"] = "couchdb1.6" unless params["couch"]
params["platform-version"] = "latest" unless params["platform-version"]
params["hardware"] = "iPhone 4S" unless params["hardware"]
params["ra"] = "false" unless params["ra"]
#kill any docker container that may be running on the machine.
#we don't want to effected by another failing build
system("docker rm --force couchdb")
#launch docker
puts "Starting docker container #{$couch}"
#cloudant local current runs in a Vagrant box, rather than docker, this box is *always* running on cloudantsync001
#so we skip the docker set up commands and change the options to enable connection to cloudant local
if params["couch"] == "cloudantlocal"
#Set evn variables to cloudant local settings
ENV["TEST_COUCH_USERNAME"] = "admin"
ENV["TEST_COUCH_PASSWORD"] = "pass"
ENV["TEST_COUCH_HOST"] = "127.0.0.1"
ENV["TEST_COUCH_PORT"] = "8081"
ENV["TEST_COUCH_HTTP"] = "http"
else
docker_port = 5984
#special case for couchdb2.0 it runs on port 15984 in the docker container rather than 5984
docker_port = 15984 if params["couch"] == "couchdb2.0"
unless system("docker run -p 5984:#{docker_port} -d -h db1.dockertest --name 'couchdb' #{params["couch"]}")
#we need to stop, we failed to run the docker container, just in case we will delete
system("docker rm --force couchdb")
exit 1
end
end
puts "Performing build"
system("rake podupdate")
#handle the differences in the platform
replication_options = Array.new
ENV.each do |key,value|
next unless key.start_with?("TEST_COUCH")
replication_options.push(key+"="+value)
end
if params["platform"] == "OSX"
system("xcodebuild -workspace CDTDatastore.xcworkspace -scheme 'Tests OSX' -destination 'platform=OS X' #{replication_options.join(" ")} test | xcpretty -r junit ; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/osx_unit.xml")
system("xcodebuild -workspace EncryptionTests/EncryptionTests.xcworkspace -scheme 'Encryption Tests OSX' -destination 'platform=OS X' #{replication_options.join(" ")} test | xcpretty -r junit ; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/osx_encryption.xml")
if(params["ra"] == "true")
system("xcodebuild -workspace ./ReplicationAcceptance/ReplicationAcceptance.xcworkspace -scheme 'RA_Tests_OSX' -destination 'platform=OS X' #{replication_options.join(" ")} test | xcpretty -r junit; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/osx_ra.xml")
system("xcodebuild -workspace ./ReplicationAcceptance/ReplicationAcceptance.xcworkspace -scheme 'RA_EncryptionTests_OSX' -destination 'platform=OS X' #{replication_options.join(" ")} test | xcpretty -r junit; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/osx_encryption_ra.xml")
end
elsif params["platform"] == "iOS"
system("xcodebuild -workspace CDTDatastore.xcworkspace -scheme 'Tests iOS' -destination 'platform=iOS Simulator,OS=#{params["platform-version"]},name=#{params["hardware"]}' #{replication_options.join(" ")} test | xcpretty -r junit ; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/ios_unit.xml")
system("xcodebuild -workspace EncryptionTests/EncryptionTests.xcworkspace -scheme 'Encryption Tests' -destination 'platform=iOS Simulator,OS=#{params["platform-version"]},name=#{params["hardware"]}' #{replication_options.join(" ")} test | xcpretty -r junit ; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/ios_encryption.xml")
if(params["ra"] == "true")
system("xcodebuild -workspace ./ReplicationAcceptance/ReplicationAcceptance.xcworkspace -scheme 'RA_Tests' -destination 'platform=iOS Simulator,OS=#{params["platform-version"]},name=#{params["hardware"]}' #{replication_options.join(" ")} test | xcpretty -r junit; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/ios_ra.xml")
system("xcodebuild -workspace ./ReplicationAcceptance/ReplicationAcceptance.xcworkspace -scheme 'RA_EncryptionTests' -destination 'platform=iOS Simulator,OS=#{params["platform-version"]},name=#{params["hardware"]}' #{replication_options.join(" ")} test | xcpretty -r junit; exit ${PIPESTATUS[0]}")
FileUtils.mv("build/reports/junit.xml","build/reports/ios_encryption_ra.xml")
end
end
#get the build exit code, will exit with this after tearing down the docker container
exitcode = $?
unless params["couch"] == "cloudantlocal"
puts "Tearing down docker container"
system("docker stop couchdb")
system("docker rm couchdb")
end
exit exitcode.to_i