This repository has been archived by the owner on Jul 4, 2018. It is now read-only.
forked from flaviogranero/assisted_workflow
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
119 lines (97 loc) · 3.17 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
require "bundler/gem_tasks"
require 'rake/testtask'
require 'assisted_workflow/version'
Rake::TestTask.new do |t|
t.libs << "spec"
t.pattern = "spec/**/*_spec.rb"
end
task :console do
require 'irb'
require 'irb/completion'
require 'assisted_workflow'
require 'assisted_workflow/cli'
ARGV.clear
IRB.start
end
PROJECT_NAME = "aw"
TRAVELING_RUBY_VERSION = "20150517-2.2.2"
TRAVELING_RUBY_HOST = "http://d6r77u77i8pq3.cloudfront.net/releases"
RUBY_BASENAME = "traveling-ruby-#{TRAVELING_RUBY_VERSION}"
namespace :package do
desc "Generate assisted_workflow #{AssistedWorkflow::VERSION} packages for OSX, Linux x86 and Linux x86_64"
task all: ["linux:x86", "linux:x86_64", "osx"]
namespace :linux do
desc "Generate assisted_workflow #{AssistedWorkflow::VERSION} package for Linux x86"
task x86: "packaging/#{RUBY_BASENAME}-linux-x86.tar.gz" do
clean_up("linux-x86")
create_package("linux-x86")
end
desc "Generate assisted_workflow #{AssistedWorkflow::VERSION} package for Linux x86_64"
task x86_64: "packaging/#{RUBY_BASENAME}-linux-x86_64.tar.gz" do
clean_up("linux-x86_64")
create_package("linux-x86_64")
end
end
desc "Generate assisted_workflow #{AssistedWorkflow::VERSION} package for OSX"
task osx: "packaging/#{RUBY_BASENAME}-osx.tar.gz" do
clean_up("osx")
create_package("osx")
end
desc "Remove the files generated by packaging"
task :cleanup do
clean_up("osx")
clean_up("linux-x86")
clean_up("linux-x86_64")
end
end
file "packaging/#{RUBY_BASENAME}-osx.tar.gz" do
sh "cd packaging && curl -L -O --fail #{TRAVELING_RUBY_HOST}/#{ruby_for("osx")}"
end
file "packaging/#{RUBY_BASENAME}-linux-x86.tar.gz" do
sh "cd packaging && curl -L -O --fail #{TRAVELING_RUBY_HOST}/#{ruby_for("linux-x86")}"
end
file "packaging/#{RUBY_BASENAME}-linux-x86_64.tar.gz" do
sh "cd packaging && curl -L -O --fail #{TRAVELING_RUBY_HOST}/#{ruby_for("linux-x86_64")}"
end
def create_package(target)
if RUBY_VERSION !~ /^2\.2\./
abort "You can't package with a Ruby version other than 2.2."
end
package_dir = "#{PROJECT_NAME}-#{AssistedWorkflow::VERSION}-#{target}"
copy_shims(package_dir)
install_dependencies(package_dir)
extract_ruby(package_dir, target)
archive_package(package_dir)
end
def clean_up(target)
package_name = "#{PROJECT_NAME}-#{AssistedWorkflow::VERSION}-#{target}"
rm_rf package_name
rm_f "#{package_name}.tar.gz"
end
def ruby_for(target)
"#{RUBY_BASENAME}-#{target}.tar.gz"
end
def install_dependencies(package_dir)
app_path = "#{package_dir}/lib/app"
mkdir_p app_path
cp "packaging/Gemfile", app_path
mkdir "#{app_path}/.bundle"
cp "packaging/bundler-config", "#{app_path}/.bundle/config"
Bundler.with_clean_env do
sh "cd #{app_path}/ && bundle install"
end
rm_f "#{app_path}/vendor/*/*/cache/*"
end
def copy_shims(package_dir)
shim_dir = "#{package_dir}/bin"
mkdir_p shim_dir
cp "packaging/aw.sh", "#{shim_dir}/aw"
end
def extract_ruby(package_dir, target)
ruby_dir = "#{package_dir}/lib/ruby"
mkdir_p ruby_dir
sh "tar -xzf packaging/#{ruby_for(target)} -C #{ruby_dir}"
end
def archive_package(package_dir)
sh "tar -czf #{package_dir}.tar.gz #{package_dir}"
end