-
Notifications
You must be signed in to change notification settings - Fork 13
/
Rakefile
142 lines (122 loc) · 4.3 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
$: << File.expand_path( '../lib/', __FILE__ )
require 'fileutils'
require 'find'
require 'rake/clean'
require 'rspec/core/rake_task'
require 'rubygems'
require 'simp/rake'
require 'simp/rake/beaker'
require 'simp/rake/ci'
require 'simp/cli/version'
# Create pkg:* and simp:ci_* Rake tasks
Simp::Rake::Pkg.new(File.dirname(__FILE__))
Simp::Rake::Ci.new(File.dirname(__FILE__))
@package='simp-cli'
@rakefile_dir=File.dirname(__FILE__)
CLEAN.include "#{@package}-*.gem"
CLEAN.include 'coverage'
CLEAN.include 'dist'
CLEAN.include 'pkg'
Find.find( @rakefile_dir ) do |path|
if File.directory? path
CLEAN.include path if File.basename(path) == 'tmp'
else
Find.prune
end
end
# Create beaker:* acceptance test Rake tasks
Simp::Rake::Beaker.new(File.dirname(__FILE__))
desc 'Ensure gemspec-safe permissions on all files'
task :chmod do
gemspec = File.expand_path( "#{@package}.gemspec", @rakefile_dir ).strip
spec = Gem::Specification::load( gemspec )
spec.files.each do |file|
FileUtils.chmod 'go=r', file
end
end
desc 'special notes about these rake commands'
task :help do
puts %Q{
== Environment Variables ==
SIMP_RPM_BUILD when set, alters the gem produced by pkg:gem to be RPM-safe.
'pkg:gem' sets this automatically.
== Restrictions ==
- Because the code for this gem uses a global, singleton HighLine object,
the tests for this code cannot be parallelized.
- To prevent actual changes from being made to your system, some of the
'simp config' tests skip if the tests are run as root.
}
end
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--color']
t.exclude_pattern = '**/{acceptance,fixtures,files}/**/*_spec.rb'
t.pattern = 'spec/{lib,bin}/**/*_spec.rb'
end
namespace :pkg do
@specfile_template = "rubygem-#{@package}.spec.template"
@specfile = "build/rubygem-#{@package}.spec"
# ----------------------------------------
# DO NOT UNCOMMENT THIS: the spec file requires a lot of tweaking
# ----------------------------------------
# desc "generate RPM spec file for #{@package}"
# task :spec => [:clean, :gem] do
# Dir.glob("pkg/#{@package}*.gem") do |pkg|
# sh %Q{gem2rpm -t "#{@specfile_template}" "#{pkg}" > "#{@specfile}"}
# end
# end
desc "build rubygem package for #{@package}"
task :gem => :chmod do
gem_dirs = [@rakefile_dir]
gem_dirs += Dir.glob('ext/gems/*')
gem_dirs.each do |gem_dir|
Dir.chdir gem_dir do
Dir['*.gemspec'].each do |spec_file|
# highline optional (development-related) gems require cmake, so
# exclude them in the bundle
opts = (File.basename(gem_dir) == 'highline') ? '--without=code_quality' : ''
cmd = %Q{SIMP_RPM_BUILD=1 bundle exec gem build "#{spec_file}" &> /dev/null}
if ::Bundler.respond_to?(:with_unbundled_env)
# Use Bundler 2.x API
::Bundler.with_unbundled_env do
%x{bundle install #{opts}}
sh cmd
end
else
# Use deprecated Bundler 1.x API
::Bundler.with_clean_env do
%x{bundle install #{opts}}
sh cmd
end
end
FileUtils.mkdir_p 'dist'
FileUtils.mv Dir.glob('*.gem'), File.join(@rakefile_dir, 'dist')
end
end
end
end
desc "build and install rubygem package for #{@package}"
task :install_gem => [:clean, :gem] do
Dir.chdir @rakefile_dir
Dir.glob("dist/#{@package}*.gem") do |pkg|
sh %Q{bundle exec gem install #{pkg}}
end
end
desc 'ensure simp cli Ruby version matches its RPM spec file version'
task :validate_ruby_version do
basedir = File.dirname(__FILE__)
info, changelogs = Simp::RelChecks::load_and_validate_changelog(basedir, false)
spec_file_version = Gem::Version.new(info.version)
ruby_version = Gem::Version.new(Simp::Cli::VERSION)
if spec_file_version != ruby_version
fail("ERROR: Version mismatch: " +
" spec file version = #{spec_file_version}," +
" version.rb version = #{ruby_version}")
end
end
Rake::Task[:rpm].prerequisites.unshift(:gem)
Rake::Task[:compare_latest_tag].enhance [:validate_ruby_version]
end
# Make sure gem packages are built because they will be installed in
# the acceptance test
Rake::Task['beaker:suites'].enhance ['pkg:gem']
# vim: syntax=ruby