forked from getappmap/appmap-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
167 lines (143 loc) · 4.56 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
$: << File.join(__dir__, 'lib')
require 'appmap/version'
GEM_VERSION = AppMap::VERSION
require 'rake/testtask'
require 'rdoc/task'
require 'open3'
require 'rake/extensiontask'
desc 'build the native extension'
Rake::ExtensionTask.new("appmap") do |ext|
ext.lib_dir = "lib/appmap"
end
namespace 'gem' do
require 'bundler/gem_tasks'
module Bundler
class GemHelper
# A handy tip - find the location of any Rake task using `rake -W`.
# rake -W build
# ~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/gem_helper.rb:39:in `install'
def build_gem
raise "Don't use 'rake gem:build' - use 'yarn install --prod && gem build <gemspec>', because that's what ./release.sh does"
end
end
end
end
RUBY_VERSIONS=%w[2.6 2.7 3.0].select do |version|
travis_ruby_version = ENV['TRAVIS_RUBY_VERSION']
next true unless travis_ruby_version
if travis_ruby_version.index(version) == 0
warn "Testing Ruby version #{version}, since it matches TRAVIS_RUBY_VERSION=#{travis_ruby_version}"
next true
end
false
end
FIXTURE_APPS=%w[rack_users_app rails6_users_app rails5_users_app]
def run_cmd(*cmd)
$stderr.puts "Running: #{cmd}"
out, s = Open3.capture2e(*cmd)
unless s.success?
$stderr.puts <<-END
Command failed:
<<< Output:
#{out}
>>> End of output
END
raise 'Docker build failed'
end
end
def build_base_image(ruby_version)
run_cmd "docker build" \
" --build-arg RUBY_VERSION=#{ruby_version}" \
" --build-arg GEM_VERSION=#{GEM_VERSION}" \
" -t appmap:#{GEM_VERSION} -f Dockerfile.appmap ."
end
def build_app_image(app, ruby_version)
Dir.chdir "spec/fixtures/#{app}" do
env = {"RUBY_VERSION" => ruby_version, "GEM_VERSION" => GEM_VERSION}
run_cmd(env,
"docker-compose build" \
" --build-arg RUBY_VERSION=#{ruby_version}" \
" --build-arg GEM_VERSION=#{GEM_VERSION}" )
end
end
namespace :build do
namespace :base do
RUBY_VERSIONS.each do |ruby_version|
desc ruby_version
task ruby_version do
run_system = ->(cmd) { system(cmd) or raise "Command failed: #{cmd}" }
run_system.call 'mkdir -p pkg'
run_system.call 'yarn install --prod'
run_system.call "gem build appmap.gemspec --output pkg/appmap-#{GEM_VERSION}.gem"
build_base_image(ruby_version)
end.tap do |t|
desc "Build all images"
task all: t
end
end
end
namespace :fixtures do
RUBY_VERSIONS.each do |ruby_version|
namespace ruby_version do
desc "build:fixtures:#{ruby_version}"
FIXTURE_APPS.each do |app|
desc app
task app => ["base:#{ruby_version}"] do
build_app_image(app, ruby_version)
end.tap do |t|
desc "Build all fixture images for #{ruby_version}"
task all: t
end
end
end
desc "Build all fixture images"
task all: ["#{ruby_version}:all"]
end
end
task all: ["fixtures:all"]
end
def run_specs(ruby_version, task_args)
require 'rspec/core/rake_task'
require 'climate_control'
# Define an rspec rake task for the specified Ruby version. It's hidden (i.e. doesn't have a
# description), because it's not intended to be invoked directly
RSpec::Core::RakeTask.new("rspec_#{ruby_version}", [:specs]) do |task, args|
task.exclude_pattern = 'spec/fixtures/**/*_spec.rb'
if args.count > 0
# There doesn't appear to be a value for +pattern+ that will
# cause it to be ignored. Setting it to '' or +nil+ causes an
# empty argument to get passed to rspec, which confuses it.
task.pattern = 'never match this'
task.rspec_opts = args.to_a.join(' ')
end
end
# Set up the environment, then execute the rspec task we
# created above.
ClimateControl.modify(RUBY_VERSION: ruby_version) do
Rake::Task["rspec_#{ruby_version}"].execute(task_args)
end
end
namespace :spec do
RUBY_VERSIONS.each do |ruby_version|
desc ruby_version
task ruby_version, [:specs] => ["compile", "build:fixtures:#{ruby_version}:all"] do |_, task_args|
run_specs(ruby_version, task_args)
end.tap do |t|
desc "Run all specs"
task :all, [:specs] => t
end
end
end
Rake::RDocTask.new do |rd|
rd.main = 'README.rdoc'
rd.rdoc_files.include(%w[README.rdoc lib/**/*.rb exe/**/*])
rd.title = 'AppMap'
end
Rake::TestTask.new(minitest: 'compile') do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/*_test.rb']
end
task spec: %i[spec:all]
task test: %i[spec:all minitest]
task default: :test