-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
338 lines (284 loc) · 8.16 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
require 'bundler'
require 'osx/cocoa'
require 'tempfile'
require 'uri'
Bundler.require
class Crypto
class << self
def signature(path)
`openssl dgst -sha1 -binary < "#{path}" | openssl dgst -dss1 -sign "#{private_key}" | openssl enc -base64`.strip
end
private
def private_key
"#{ENV['HOME']}/.signing_keys/dsa_priv.pem"
end
end
end
class FinderPreferences
include Appscript
KEYS = %w(
desktop_shows_hard_disks
desktop_shows_external_hard_disks
desktop_shows_removable_media
desktop_shows_connected_servers
)
class << self
def hide_desktop_items(&block)
new.hide_desktop_items(&block)
end
end
def initialize
finder = app('Finder').Finder_preferences
@preferences = KEYS.collect { |key| finder.send(key) }.
inject({}) { |hash, key| hash[key] = key.get; hash }
end
def hide_desktop_items(&block)
@preferences.each { |preference, initial_value| preference.set(false) }
block.call
ensure
@preferences.each { |preference, initial_value| preference.set(initial_value) }
end
end
class Git
class << self
def commits
`git log --pretty=format:%s #{tags.last}..`.strip.split("\n")
end
def describe
`git describe --tags`.strip
end
def has_tag?(tag)
tags.include?(tag)
end
private
def tags
`git tag`.strip.split("\n")
end
end
end
class Project
class << self
def artifact
"build/Release/#{name}.app"
end
def demo(*options, &block)
pid = fork { exec "#{artifact}/Contents/MacOS/#{name}", *options }
sleep 2
fork { exec 'open', artifact }
sleep 2
block.call
ensure
Process.kill('TERM', pid)
end
def disk_image_path
"#{name}-#{marketing_version}.dmg"
end
# TODO determine download url from somewhere?
def disk_image_url
"https://matthewtodd.org/downloads/#{disk_image_path}"
end
def marketing_version
`agvtool mvers -terse1`.strip
end
def minimum_system_version
settings = `grep MACOSX_DEPLOYMENT_TARGET #{name}.xcodeproj/project.pbxproj`
versions = settings.scan(/[.0-9]+/).sort.uniq
abort("Multiple versions specified:\n#{settings}") if versions.size > 1
versions.first
end
# TODO read name from XCode config?
def name
'HeadsUp'
end
# TODO determine this unix_name automatically?
def unix_name
'heads_up'
end
def version
`agvtool vers -terse`.strip
end
end
end
class Screen
class << self
def resize(width, height, &block)
new.resize(width, height, &block)
end
end
def initialize(screen = OSX::CGMainDisplayID())
@screen = screen
@mode = OSX::CGDisplayCopyDisplayMode(@screen)
end
def resize(width, height, &block)
configure(best_mode(width, height))
block.call
ensure
configure(@mode)
end
private
def best_mode(width, height)
# TODO Try to figure out color depth from CGDisplayModeCopyPixelEncoding?
OSX::CGDisplayCopyAllDisplayModes(@screen, nil).detect do |mode|
OSX::CGDisplayModeGetWidth(mode) == width &&
OSX::CGDisplayModeGetHeight(mode) == height &&
OSX::CGDisplayModeIsUsableForDesktopGUI(mode)
end
end
def configure(mode)
result, config = OSX::CGBeginDisplayConfiguration()
if result == OSX::KCGErrorSuccess
OSX::CGConfigureDisplayWithDisplayMode(config, @screen, mode, nil)
OSX::CGCompleteDisplayConfiguration(config, OSX::KCGConfigureForSession)
else
raise "I have no clue what just happened: #{result}"
end
end
end
class SystemEvents
include Appscript
class << self
def hide_others(name, &block)
new(name).hide_others(&block)
end
end
def initialize(name)
@target = app(name)
@others = app('System Events').processes[its.name.ne(name).and(its.visible.eq(true))].get
end
def hide_others(&block)
@target.activate
@others.each { |p| p.visible.set(false) }
block.call
ensure
@others.each { |p| p.visible.set(true) }
end
end
class Website
class << self
def configuration_path
'docs/_config.yml'
end
def configure(options)
File.open(configuration_path, 'w') do |file|
file.write(configuration.merge(options).to_yaml)
end
end
def release_announcement_path
"docs/_posts/#{Date.today.strftime('%Y-%m-%d')}-version-#{Project.marketing_version}.textile"
end
def screenshot_path
'docs/images/screenshot.jpg'
end
def small_screenshot_path
'docs/images/screenshot-small.jpg'
end
private
def configuration
YAML.load_file(configuration_path) || {}
end
end
end
file Project.artifact do
sh 'xcodebuild'
end
file Project.disk_image_path => Project.artifact do |task|
Dir.mktmpdir do |path|
FileUtils.rm_r task.name, :force => true
FileUtils.cp_r task.prerequisites, path
FileUtils.ln_s '/Applications', "#{path}/Applications"
sh "hdiutil create -volname #{Project.name} -srcfolder #{path} #{task.name}"
end
end
file Website.configuration_path => Project.artifact do
Website.configure(
'latest_disk_image_url' => Project.disk_image_url,
'latest_disk_image_name' => Project.disk_image_path
)
end
file Website.release_announcement_path => Project.disk_image_path do |task|
File.open(task.name, 'w') do |file|
file.puts '---'
file.puts "title: #{Project.name} #{Project.marketing_version}"
file.puts "layout: default"
file.puts "dmg: #{Project.disk_image_url}"
file.puts "dmg_name: #{Project.disk_image_path}"
file.puts "version: #{Project.version}"
file.puts "short_version: #{Project.marketing_version}"
file.puts "length: #{File.stat(Project.disk_image_path).size}"
file.puts "signature: #{Crypto.signature(Project.disk_image_path)}"
file.puts "minimum_system_version: #{Project.minimum_system_version}"
file.puts 'category: releases'
file.puts 'tag: app'
file.puts '---'
file.puts 'h3. Changelog'
file.puts
Git.commits.each { |commit| file.puts "* #{commit}" }
end
end
file Website.screenshot_path => Project.artifact do |task|
SystemEvents.hide_others('Finder') do
Screen.resize(1024, 768) do
FinderPreferences.hide_desktop_items do
Project.demo('-bottom_left', 'date', '-bottom_right', 'netstat -p tcp') do
sh "screencapture -m -tjpg #{task.name}"
end
end
end
end
end
file Website.small_screenshot_path => Website.screenshot_path do |task|
sh "convert -resize 300x #{task.prerequisites} #{task.name}"
end
desc 'Remove generated artifacts.'
task :clean do
sh 'xcodebuild clean'
FileUtils.rm Dir['*.dmg']
end
desc "Build #{Project.disk_image_path}"
task :default => Project.disk_image_path
unless Git.has_tag?(Project.marketing_version)
desc "Prepare to release #{Project.name} #{Project.marketing_version}"
task :prepare_release => [
:clean,
Project.disk_image_path,
Website.configuration_path,
Website.release_announcement_path,
Website.screenshot_path,
Website.small_screenshot_path,
:website
] do
puts "Now, tweak the release notes, upload the disk image, commit the website, commit the project, tag #{Project.marketing_version} and push."
end
desc "Upload the disk image."
task :upload => Project.disk_image_path do
uri_path = URI.parse(Project.disk_image_url).path
remote_path = File.join('web/public', uri_path)
Net::SFTP.start('college') do |sftp|
sftp.upload! Project.disk_image_path, remote_path
end
end
end
desc 'Show current version numbers.'
task :versions do
puts
puts " git describe: #{Git.describe}"
puts "marketing version: #{Project.marketing_version}"
puts " version: #{Project.version}"
puts
puts "To set marketing version, use `agvtool new-marketing-version VERSION`."
puts "To set version, use `agvtool new-version VERSION` or `agvtool bump`."
end
desc 'See how the GitHub Pages will look.'
task :website do
pid = fork do
Dir.mktmpdir do |path|
exec 'jekyll', 'docs', path, '--auto', '--server', '3000', '--url', 'http://localhost:3000'
end
end
begin
sleep 2
sh 'open', '-Wn', "http://localhost:3000/"
ensure
Process.kill('KILL', pid)
end
end