forked from braintree/braintree-ios-drop-in
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
202 lines (164 loc) · 6.02 KB
/
Rakefile
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
require 'tempfile'
require 'fileutils'
require 'shellwords'
require 'bundler'
Bundler.require
HighLine.color_scheme = HighLine::SampleColorScheme.new
task :default => %w[sanity_checks spec]
desc "Run default set of tasks"
task :spec => %w[spec:all]
desc "Run internal release process"
task :release => %w[release:assumptions sanity_checks release:check_working_directory release:bump_version release:lint_podspec release:tag]
desc "Publish code and pod to public github.com"
task :publish => %w[publish:push publish:push_pod]
SEMVER = /\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?/
PODSPEC = "BraintreeDropIn.podspec"
DEMO_PLIST = "DropInDemo/Supporting Files/Braintree-Demo-Info.plist"
DROPIN_FRAMEWORKS_PLIST = "BraintreeDropIn/Info.plist"
UIKIT_FRAMEWORKS_PLIST = "BraintreeUIKit/Info.plist"
PUBLIC_REMOTE_NAME = "origin"
class << self
def run cmd
say(HighLine.color("$ #{cmd}", :debug))
File.popen(cmd) { |file|
if block_given?
result = ''
result << file.gets until file.eof?
yield result
else
puts file.gets until file.eof?
end
}
$? == 0
end
def run! cmd
run(cmd) or fail("Command failed with non-zero exit status #{$?}:\n$ #{cmd}")
end
def current_version
File.read(PODSPEC)[SEMVER]
end
def current_version_with_sha
%x{git describe}.strip
end
def current_branch
%x{git rev-parse --abbrev-ref HEAD}.strip
end
def xcodebuild(scheme, command, configuration, ios_version, options={})
default_options = {
:build_settings => {}
}
ios_version_specifier = ",OS=#{ios_version}" if !ios_version.nil?
options = default_options.merge(options)
build_settings = options[:build_settings].map{|k,v| "#{k}='#{v}'"}.join(" ")
return "set -o pipefail && xcodebuild -workspace 'BraintreeDropIn.xcworkspace' -sdk 'iphonesimulator' -configuration '#{configuration}' -scheme '#{scheme}' -destination 'name=iPhone 11,platform=iOS Simulator#{ios_version_specifier}' #{build_settings} #{command} | xcpretty -c -r junit"
end
end
namespace :spec do
def run_test_scheme! scheme, ios_version = nil
run! xcodebuild(scheme, 'test', 'Release', ios_version)
end
desc 'Run unit tests'
task :unit, [:ios_version] do |t, args|
if args[:ios_version]
run_test_scheme! 'UnitTests', args[:ios_version]
else
run_test_scheme! 'UnitTests'
end
end
desc 'Run UI tests'
task :ui do
run_test_scheme! 'UITests'
end
desc 'Run all spec schemes'
task :all => %w[spec:unit spec:ui]
end
namespace :demo do
desc 'Verify that the demo app builds successfully'
task :build do
run! xcodebuild('DropInDemo', 'build', 'Release', nil)
end
end
desc 'Run Carthage update'
namespace :carthage do
def generate_cartfile
run! 'mkdir -p BuildTest'
File.write("BuildTest/Cartfile", "git \"file://#{Dir.pwd}\" \"#{current_branch}\"")
end
task :generate do
generate_cartfile
end
task :clean do
run! 'rm -rf BuildTest/Carthage && rm -rf Carthage && rm BuildTest/Cartfile && rm BuildTest/Cartfile.resolved && rm -rf ~/Library/Developers/Xcode/DerivedData'
end
task :test do
run! "rm -rf Carthage"
run! "rm -rf BuildTest"
generate_cartfile
run! "cd BuildTest && carthage update"
run! "mv BuildTest/Carthage #{Dir.pwd}"
run! "xcodebuild -project 'DropInDemo/CarthageTest/CarthageTest.xcodeproj' -scheme 'CarthageTest' clean build"
end
end
desc 'Run all sanity checks'
task :sanity_checks => %w[sanity_checks:pending_specs sanity_checks:build_demo sanity_checks:carthage_test]
namespace :sanity_checks do
desc 'Check for pending tests'
task :pending_specs do
#TODO Update for UI Tests
end
desc 'Verify that all demo apps Build successfully'
task :build_demo => 'demo:build'
desc 'Verify that Carthage builds successfully'
task :carthage_test => %w[carthage:test carthage:clean]
end
namespace :release do
desc "Print out pre-release checklist"
task :assumptions do
say "Release Assumptions"
say "* [ ] You have pulled the latest public code from github.com."
say "* [ ] You are on the branch and commit you want to release."
say "* [ ] You have already merged hotfixes and pulled changes."
say "* [ ] You have already reviewed the diff between the current release and the last tag, noting breaking changes in the semver and CHANGELOG."
say "* [ ] Tests (rake spec) are passing, manual verifications complete."
say "* [ ] Email is composed and ready to send to braintree-sdk-announce@googlegroups.com"
abort(1) unless ask "Ready to release? Press any key to continue. "
end
desc "Check that working directory is clean"
task :check_working_directory do
run! "echo 'Checking for uncommitted changes' && git diff --exit-code"
end
desc "Bump version in Podspec"
task :bump_version do
say "Current version in Podspec: #{current_version}"
n = 10
say "Previous #{n} versions in Git:"
run "git tag -l | tail -n #{n}"
version = ask("What version are you releasing?") { |q| q.validate = /\A#{SEMVER}\Z/ }
podspec = File.read(PODSPEC)
podspec.gsub!(/(s\.version\s*=\s*)"#{SEMVER}"/, "\\1\"#{version}\"")
File.open(PODSPEC, "w") { |f| f.puts podspec }
[DEMO_PLIST, DROPIN_FRAMEWORKS_PLIST, UIKIT_FRAMEWORKS_PLIST].each do |plist|
run! "plutil -replace CFBundleVersion -string #{current_version} -- '#{plist}'"
run! "plutil -replace CFBundleShortVersionString -string #{current_version} -- '#{plist}'"
end
run "git commit -m 'Bump pod version to #{version}' -- #{PODSPEC} Podfile.lock '#{DEMO_PLIST}' '#{DROPIN_FRAMEWORKS_PLIST}' '#{UIKIT_FRAMEWORKS_PLIST}'"
end
desc "Lint podspec."
task :lint_podspec do
run! "pod lib lint --allow-warnings"
end
desc "Tag."
task :tag do
run! "git tag #{current_version} -a -m 'Release #{current_version}'"
end
end
namespace :publish do
desc "Push code and tag to github.com"
task :push do
run! "git push #{PUBLIC_REMOTE_NAME} HEAD #{current_version}"
end
desc "Pod push."
task :push_pod do
run! "pod trunk push --allow-warnings BraintreeDropIn.podspec"
end
end