forked from puppetlabs/puppet-editor-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
175 lines (146 loc) · 5.85 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
require 'rspec/core/rake_task'
rubocop_available = Gem::Specification::find_all_by_name('rubocop').any?
require 'rubocop/rake_task' if rubocop_available
desc 'Run rspec tests for the Language Server with coloring.'
RSpec::Core::RakeTask.new(:test_languageserver) do |t|
t.rspec_opts = %w[--color --format documentation --default-path spec/languageserver]
t.pattern = ['spec/languageserver/unit/**/*_spec.rb', 'spec/languageserver/integration/**/*_spec.rb']
end
desc 'Run acceptance tests for the Language Server with coloring.'
RSpec::Core::RakeTask.new(:acceptance_languageserver) do |t|
t.rspec_opts = %w[--color --format documentation --default-path spec/languageserver]
t.pattern = ['spec/languageserver/acceptance/**/*_spec.rb']
end
desc 'Run rspec tests for the Language Server Sidecar with coloring.'
RSpec::Core::RakeTask.new(:test_languageserver_sidecar) do |t|
t.rspec_opts = %w[--color --format documentation --default-path spec/languageserver-sidecar]
t.pattern = 'spec/languageserver-sidecar'
end
desc 'Run rspec tests for the Debug Server with coloring.'
RSpec::Core::RakeTask.new(:test_debugserver) do |t|
t.rspec_opts = %w[--color --format documentation --default-path spec/debugserver]
t.pattern = 'spec/debugserver'
end
if rubocop_available
desc 'Run RuboCop'
RuboCop::RakeTask.new(:rubocop) do |task|
task.options << '--display-cop-names'
task.options << '--config'
task.options << '.rubocop.yml'
end
end
namespace :rubocop do
desc "Generate the Rubocop Todo file"
task :generate do
begin
sh "rubocop --auto-gen-config"
rescue => exception
# Ignore any errors
end
end
end
desc "Download and vendor required gems"
task :gem_revendor do
require 'fileutils'
gem_list = [
{
:directory => 'puppet-lint',
:github_repo => 'https://github.com/rodjek/puppet-lint.git',
:github_ref => '2.4.2',
},
{
:directory => 'hiera-eyaml',
:github_repo => 'https://github.com/voxpupuli/hiera-eyaml',
:github_ref => 'v2.1.0',
},
{
:directory => 'puppetfile-resolver',
:github_repo => 'https://github.com/glennsarti/puppetfile-resolver.git',
:github_ref => '0.3.0',
},
{
:directory => 'molinillo',
:github_repo => 'https://github.com/CocoaPods/Molinillo.git',
:github_ref => '0.6.6',
},
{
:directory => 'puppet-strings',
:github_repo => 'https://github.com/puppetlabs/puppet-strings.git',
:github_ref => 'v2.4.0',
},
{
:directory => 'yard',
:github_repo => 'https://github.com/lsegal/yard.git',
:github_ref => 'v0.9.24',
},
]
# Clean out the vendor directory first
puts "Clearing the vendor directory..."
vendor_dir = File.join(File.dirname(__FILE__),'vendor')
gem_list.each do |vendor|
gem_dir = File.join(vendor_dir,vendor[:directory])
FileUtils.rm_rf(gem_dir) if Dir.exists?(gem_dir)
end
Dir.mkdir(vendor_dir) unless Dir.exists?(vendor_dir)
gem_list.each do |vendor|
puts "Vendoring #{vendor[:directory]}..."
gem_dir = File.join(vendor_dir,vendor[:directory])
sh "git clone #{vendor[:github_repo]} #{gem_dir}"
Dir.chdir(gem_dir) do
sh 'git fetch origin'
sh "git reset --hard #{vendor[:github_ref]}"
end
# Cleanup the gem directory...
FileUtils.rm_rf(File.join(gem_dir,'.git'))
FileUtils.rm_rf(File.join(gem_dir,'spec'))
FileUtils.rm_rf(File.join(gem_dir,'features'))
FileUtils.rm_rf(File.join(gem_dir,'docs'))
end
# Generate the README
readme = <<-HEREDOC
# Vendored Gems
The puppet language server is designed to run within the Puppet Agent ruby environment which means no access to Native Extensions or Gem bundling.
This means any Gems required outside of Puppet Agent for the language server must be vendored in this directory and the load path modified in the `puppet-languageserver` file.
Note - To comply with Licensing, the Gem source should be MIT licensed or even more unrestricted.
Note - To improve the packaging size, test files etc. were stripped from the Gems prior to committing.
Gem List
--------
HEREDOC
gem_list.each { |vendor| readme += "* #{vendor[:directory]} (#{vendor[:github_repo]} ref #{vendor[:github_ref]})\n"}
File.open(File.join(vendor_dir,'README.md'), 'wb') { |file| file.write(readme + "\n") }
end
desc "Create compressed files of the language and debug servers for release"
task build: [:gem_revendor] do
require 'fileutils'
require 'archive/zip'
require 'zlib'
require 'minitar'
require 'digest'
project_dir = File.dirname(__FILE__)
output_dir = File.join(project_dir, 'output')
file_list = ['lib', 'vendor', 'puppet-languageserver', 'puppet-debugserver', 'puppet-languageserver-sidecar', 'LICENSE']
# Remove files in the list that do not exist.
file_list.reject! { |filepath| !File.exists?(filepath) }
puts "Cleaning output directory..."
FileUtils.rm_rf Dir.glob("#{output_dir}/*") if Dir.exists?(output_dir)
Dir.mkdir(output_dir) unless Dir.exists?(output_dir)
puts "Fetch editor services version..."
require_relative 'lib/puppet_editor_services/version'
version = PuppetEditorServices.version
puts "Editor services is v#{version}"
puts "Creating zip file..."
zip_archive_file = File.join(output_dir,"puppet_editor_services_#{version}.zip")
Archive::Zip.archive(zip_archive_file, file_list)
puts "Created #{zip_archive_file}"
puts "Creating tar file..."
tar_archive_file = File.join(output_dir,"puppet_editor_services_#{version}.tar.gz")
Minitar.pack(file_list, Zlib::GzipWriter.new(File.open(tar_archive_file, 'wb')))
puts "Created #{tar_archive_file}"
puts "Creating checksums..."
[zip_archive_file, tar_archive_file].each do |filepath|
sha = Digest::SHA256.hexdigest(File.open(filepath, 'rb') { |file| file.read })
File.open(filepath + '.sha256', 'wb') { |file| file.write(sha) }
end
puts "Created checksums"
end
task :default => [:test]