-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
118 lines (95 loc) · 2.98 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
TEAM_ID = 'UP9C8XM22A'
APP_NAME = 'Contrast'
SCHEME_NAME = APP_NAME
build_dir = 'build'
desc 'Build'
task :build do
sh %(mkdir -p #{build_dir})
signing = ENV['NO_SIGNING'] ? 'CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO' : ''
sh %(xcodebuild build -scheme "#{SCHEME_NAME}" -derivedDataPath "#{build_dir}" #{signing})
end
desc 'Archive'
task :archive => :build do
# Build
sh %(mkdir -p #{build_dir})
archive_path = "#{build_dir}/#{APP_NAME}.xcarchive"
sh %(xcodebuild archive -scheme "#{SCHEME_NAME}" -archivePath "#{archive_path}")
# Create export options
export_options = "#{build_dir}/export-options.plist"
File.open(export_options, 'w') do |f|
f.write <<~PLIST
<?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>teamID</key>
<string>#{TEAM_ID}</string>
<key>method</key>
<string>developer-id</string>
</dict>
</plist>
PLIST
end
# Export archive
sh %(xcodebuild -exportArchive -archivePath "#{archive_path}" -exportOptionsPlist #{export_options} -exportPath #{build_dir})
# Check code signing
app = "#{build_dir}/#{APP_NAME}.app"
result = `codesign -vvvv "#{app}" 2>&1`
unless result.include?('satisfies its Designated Requirement')
puts "Failed codesign check:\n\n"
puts result
exit
end
# Get version
version = `/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "#{app}/Contents/Info.plist"`.chomp
short_version = `/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "#{app}/Contents/Info.plist"`.chomp
# Compress
version_s = if (system 'git diff-index --quiet HEAD --')
version
else
"#{version.to_i + 1}-wip"
end
zip = "#{APP_NAME.gsub(/\s/, '')}-#{version_s}.zip"
sh %Q{ditto -c -k --sequesterRsrc --keepParent "#{app}" "#{zip}"}
# Clean up
sh 'rm -rf build'
$tag_name = "v#{short_version}-#{version}"
puts "\n\n> Created #{zip}."
end
desc 'Create a beta build'
task :beta do
# Ensure clean git state
unless system 'git diff-index --quiet HEAD --'
abort 'Failed. You have uncommitted changes.'
end
Rake::Task['build'].invoke()
# Tag
latest_tag = `git describe --tags --abbrev=0`.chomp
sh %(git tag #{$tag_name})
# Done!
puts "\n\n> Created git tag '#{$tag_name}'.\n\n"
recent_changes(latest_tag)
end
task :default => :build
desc 'Print changes since latest tag'
task :log do
recent_changes
end
desc 'Clean up builds'
task :clean do
system 'rm -rf build *.zip'
end
private
def recent_changes(latest_tag = `git describe --tags --abbrev=0`.chomp)
# Find latest tag
scope = if latest_tag
puts "Changes since #{latest_tag}:\n\n"
"#{latest_tag}..HEAD"
else
puts "No tags yet. All changes since the project started:\n\n"
''
end
# Print changes since last tag
log = `git log #{scope} --pretty=format:'%s' --abbrev-commit`.chomp
puts log.gsub(/^([\w])/, '• \1') + "\n\n"
end