puppetlabs_spec_helper 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rspec +1 -0
- data/.rubocop.yml +92 -458
- data/.rubocop_todo.yml +118 -0
- data/.travis.yml +14 -6
- data/CHANGELOG.md +21 -4
- data/Gemfile +9 -7
- data/HISTORY.md +498 -0
- data/README.md +9 -43
- data/Rakefile +36 -6
- data/lib/puppetlabs_spec_helper/module_spec_helper.rb +31 -0
- data/lib/puppetlabs_spec_helper/puppet_spec_helper.rb +9 -10
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb +3 -3
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb +8 -9
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb +9 -12
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb +17 -17
- data/lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb +1 -1
- data/lib/puppetlabs_spec_helper/rake_tasks.rb +91 -82
- data/lib/puppetlabs_spec_helper/tasks/beaker.rb +7 -7
- data/lib/puppetlabs_spec_helper/tasks/fixtures.rb +115 -110
- data/lib/puppetlabs_spec_helper/version.rb +1 -1
- data/puppet_spec_helper.rb +1 -1
- data/puppetlabs_spec_helper.gemspec +21 -20
- data/puppetlabs_spec_helper.rb +1 -1
- metadata +5 -3
@@ -13,7 +13,7 @@ require 'rspec/expectations'
|
|
13
13
|
# See also below in RSpec.configure
|
14
14
|
if RSpec.configuration.instance_variable_get(:@mock_framework).nil?
|
15
15
|
# This is needed because we're using mocha with rspec instead of Test::Unit or MiniTest
|
16
|
-
ENV['MOCHA_OPTIONS']='skip_integration'
|
16
|
+
ENV['MOCHA_OPTIONS'] = 'skip_integration'
|
17
17
|
|
18
18
|
# Current versions of RSpec already load this for us, but who knows what's used out there?
|
19
19
|
require 'mocha/api'
|
@@ -58,7 +58,7 @@ module Puppet
|
|
58
58
|
# Puppet's Settings singleton object, and other fun implementation details
|
59
59
|
# that code external to puppet should really never know about.
|
60
60
|
def self.initialize_via_fallback_compatibility(config)
|
61
|
-
$stderr.puts(
|
61
|
+
$stderr.puts('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
|
62
62
|
config.before :all do
|
63
63
|
# nothing to do for now
|
64
64
|
end
|
@@ -79,11 +79,11 @@ module Puppet
|
|
79
79
|
|
80
80
|
# Set the confdir and vardir to gibberish so that tests
|
81
81
|
# have to be correctly mocked.
|
82
|
-
Puppet[:confdir] =
|
83
|
-
Puppet[:vardir] =
|
82
|
+
Puppet[:confdir] = '/dev/null'
|
83
|
+
Puppet[:vardir] = '/dev/null'
|
84
84
|
|
85
85
|
# Avoid opening ports to the outside world
|
86
|
-
Puppet.settings[:bindaddress] =
|
86
|
+
Puppet.settings[:bindaddress] = '127.0.0.1'
|
87
87
|
end
|
88
88
|
|
89
89
|
config.after :each do
|
@@ -91,7 +91,7 @@ module Puppet
|
|
91
91
|
|
92
92
|
Puppet::Node::Environment.clear
|
93
93
|
Puppet::Util::Storage.clear
|
94
|
-
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include?
|
94
|
+
Puppet::Util::ExecutionStub.reset if Puppet::Util.constants.include? 'ExecutionStub'
|
95
95
|
|
96
96
|
PuppetlabsSpec::Files.cleanup
|
97
97
|
end
|
@@ -100,7 +100,7 @@ module Puppet
|
|
100
100
|
end
|
101
101
|
|
102
102
|
# JJM Hack to make the stdlib tests run in Puppet 2.6 (See puppet commit cf183534)
|
103
|
-
|
103
|
+
unless Puppet.constants.include? 'Test'
|
104
104
|
module Puppet::Test
|
105
105
|
class LogCollector
|
106
106
|
def initialize(logs)
|
@@ -113,7 +113,7 @@ if not Puppet.constants.include? "Test" then
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
Puppet::Util::Log.newdesttype :log_collector do
|
116
|
-
match
|
116
|
+
match 'Puppet::Test::LogCollector'
|
117
117
|
|
118
118
|
def initialize(messages)
|
119
119
|
@messages = messages
|
@@ -137,7 +137,7 @@ RSpec.configure do |config|
|
|
137
137
|
end
|
138
138
|
|
139
139
|
# determine whether we can use the new API or not, and call the appropriate initializer method.
|
140
|
-
if
|
140
|
+
if defined?(Puppet::Test::TestHelper)
|
141
141
|
# This case is handled by rspec-puppet since v1.0.0 (via 41257b33cb1f9ade4426b044f70be511b0c89112)
|
142
142
|
else
|
143
143
|
Puppet::PuppetSpecInitializer.initialize_via_fallback_compatibility(config)
|
@@ -173,5 +173,4 @@ RSpec.configure do |config|
|
|
173
173
|
Puppet::Util::Log.close_all
|
174
174
|
Puppet::Util::Log.level = @log_level
|
175
175
|
end
|
176
|
-
|
177
176
|
end
|
@@ -18,11 +18,11 @@ module PuppetlabsSpec::Files
|
|
18
18
|
|
19
19
|
def self.cleanup
|
20
20
|
$global_tempfiles ||= []
|
21
|
-
while path = $global_tempfiles.pop
|
22
|
-
|
21
|
+
while path = $global_tempfiles.pop
|
22
|
+
raise "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path)
|
23
23
|
|
24
24
|
begin
|
25
|
-
FileUtils.rm_r path, :
|
25
|
+
FileUtils.rm_r path, secure: true
|
26
26
|
rescue Errno::ENOENT
|
27
27
|
# nothing to do
|
28
28
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# methods are designed to help when you have a conforming fixture layout so we
|
3
3
|
# get project consistency.
|
4
4
|
module PuppetlabsSpec::Fixtures
|
5
|
-
|
6
5
|
# Returns the joined path of the global FIXTURE_DIR plus any path given to it
|
7
6
|
def fixtures(*rest)
|
8
7
|
File.join(PuppetlabsSpec::FIXTURE_DIR, *rest)
|
@@ -13,21 +12,21 @@ module PuppetlabsSpec::Fixtures
|
|
13
12
|
# <project>/spec/fixture/unit/facter/foo
|
14
13
|
def my_fixture_dir
|
15
14
|
callers = caller
|
16
|
-
while line = callers.shift
|
15
|
+
while line = callers.shift
|
17
16
|
next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
|
18
17
|
return fixtures(found[1])
|
19
18
|
end
|
20
|
-
|
19
|
+
raise "sorry, I couldn't work out your path from the caller stack!"
|
21
20
|
end
|
22
21
|
|
23
22
|
# Given a name, returns the full path of a file from your relative fixture
|
24
23
|
# dir as returned by my_fixture_dir.
|
25
24
|
def my_fixture(name)
|
26
25
|
file = File.join(my_fixture_dir, name)
|
27
|
-
unless File.readable? file
|
28
|
-
|
26
|
+
unless File.readable? file
|
27
|
+
raise "fixture '#{name}' for #{my_fixture_dir} is not readable"
|
29
28
|
end
|
30
|
-
|
29
|
+
file
|
31
30
|
end
|
32
31
|
|
33
32
|
# Return the contents of the file using read when given a name. Uses
|
@@ -40,10 +39,10 @@ module PuppetlabsSpec::Fixtures
|
|
40
39
|
# area.
|
41
40
|
def my_fixtures(glob = '*', flags = 0)
|
42
41
|
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
|
43
|
-
|
44
|
-
|
42
|
+
if files.empty?
|
43
|
+
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
|
45
44
|
end
|
46
|
-
block_given?
|
45
|
+
block_given? && files.each { |file| yield file }
|
47
46
|
files
|
48
47
|
end
|
49
48
|
end
|
@@ -7,17 +7,16 @@ module RSpec
|
|
7
7
|
module Matchers
|
8
8
|
module BlockAliases
|
9
9
|
if method_defined? :should
|
10
|
-
|
10
|
+
alias to should unless method_defined? :to
|
11
11
|
end
|
12
12
|
if method_defined? :should_not
|
13
|
-
|
14
|
-
|
13
|
+
alias to_not should_not unless method_defined? :to_not
|
14
|
+
alias not_to should_not unless method_defined? :not_to
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
20
|
########################################################################
|
22
21
|
# Custom matchers...
|
23
22
|
RSpec::Matchers.define :have_matching_element do |expected|
|
@@ -26,7 +25,6 @@ RSpec::Matchers.define :have_matching_element do |expected|
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
28
|
RSpec::Matchers.define :exit_with do |expected|
|
31
29
|
actual = nil
|
32
30
|
match do |block|
|
@@ -35,13 +33,13 @@ RSpec::Matchers.define :exit_with do |expected|
|
|
35
33
|
rescue SystemExit => e
|
36
34
|
actual = e.status
|
37
35
|
end
|
38
|
-
actual
|
36
|
+
actual && actual == expected
|
39
37
|
end
|
40
|
-
failure_message_for_should do |
|
38
|
+
failure_message_for_should do |_block|
|
41
39
|
"expected exit with code #{expected} but " +
|
42
|
-
(actual.nil? ?
|
40
|
+
(actual.nil? ? ' exit was not called' : "we exited with #{actual} instead")
|
43
41
|
end
|
44
|
-
failure_message_for_should_not do |
|
42
|
+
failure_message_for_should_not do |_block|
|
45
43
|
"expected that exit would not be called with #{expected}"
|
46
44
|
end
|
47
45
|
description do
|
@@ -49,7 +47,6 @@ RSpec::Matchers.define :exit_with do |expected|
|
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
|
-
|
53
50
|
RSpec::Matchers.define :have_printed do |expected|
|
54
51
|
match do |block|
|
55
52
|
$stderr = $stdout = StringIO.new
|
@@ -64,7 +61,7 @@ RSpec::Matchers.define :have_printed do |expected|
|
|
64
61
|
$stderr = STDERR
|
65
62
|
end
|
66
63
|
|
67
|
-
if @actual
|
64
|
+
if @actual
|
68
65
|
case expected
|
69
66
|
when String
|
70
67
|
@actual.include? expected
|
@@ -77,7 +74,7 @@ RSpec::Matchers.define :have_printed do |expected|
|
|
77
74
|
end
|
78
75
|
|
79
76
|
failure_message_for_should do |actual|
|
80
|
-
if actual.nil?
|
77
|
+
if actual.nil?
|
81
78
|
"expected #{expected.inspect}, but nothing was printed"
|
82
79
|
else
|
83
80
|
"expected #{expected.inspect} to be printed; got:\n#{actual}"
|
@@ -8,9 +8,9 @@ module PuppetlabsSpec
|
|
8
8
|
# instance suitable for placing in a test harness with the intent of
|
9
9
|
# testing parser functions from modules.
|
10
10
|
def scope(parts = {})
|
11
|
-
RSpec.deprecate('scope', :
|
11
|
+
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
|
12
12
|
|
13
|
-
if Puppet.version =~
|
13
|
+
if Puppet.version =~ %r{^2\.[67]}
|
14
14
|
# loadall should only be necessary prior to 3.x
|
15
15
|
# Please note, loadall needs to happen first when creating a scope, otherwise
|
16
16
|
# you might receive undefined method `function_*' errors
|
@@ -19,15 +19,15 @@ module PuppetlabsSpec
|
|
19
19
|
|
20
20
|
scope_compiler = parts[:compiler] || compiler
|
21
21
|
scope_parent = parts[:parent] || scope_compiler.topscope
|
22
|
-
scope_resource = parts[:resource] || resource(:
|
22
|
+
scope_resource = parts[:resource] || resource(type: :node, title: scope_compiler.node.name)
|
23
23
|
|
24
|
-
if Puppet.version =~
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
scope = if Puppet.version =~ %r{^2\.[67]}
|
25
|
+
Puppet::Parser::Scope.new(compiler: scope_compiler)
|
26
|
+
else
|
27
|
+
Puppet::Parser::Scope.new(scope_compiler)
|
28
|
+
end
|
29
29
|
|
30
|
-
scope.source = Puppet::Resource::Type.new(:node,
|
30
|
+
scope.source = Puppet::Resource::Type.new(:node, 'foo')
|
31
31
|
scope.parent = scope_parent
|
32
32
|
scope
|
33
33
|
end
|
@@ -35,13 +35,13 @@ module PuppetlabsSpec
|
|
35
35
|
|
36
36
|
def resource(parts = {})
|
37
37
|
resource_type = parts[:type] || :hostclass
|
38
|
-
resource_name = parts[:name] ||
|
38
|
+
resource_name = parts[:name] || 'testing'
|
39
39
|
Puppet::Resource::Type.new(resource_type, resource_name)
|
40
40
|
end
|
41
41
|
module_function :resource
|
42
42
|
|
43
43
|
def compiler(parts = {})
|
44
|
-
compiler_node = parts[:node] || node
|
44
|
+
compiler_node = parts[:node] || node
|
45
45
|
Puppet::Parser::Compiler.new(compiler_node)
|
46
46
|
end
|
47
47
|
module_function :compiler
|
@@ -49,12 +49,12 @@ module PuppetlabsSpec
|
|
49
49
|
def node(parts = {})
|
50
50
|
node_name = parts[:name] || 'testinghost'
|
51
51
|
options = parts[:options] || {}
|
52
|
-
if Puppet.version.to_f >= 4.0
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
options
|
52
|
+
node_environment = if Puppet.version.to_f >= 4.0
|
53
|
+
Puppet::Node::Environment.create(parts[:environment] || 'test', [])
|
54
|
+
else
|
55
|
+
Puppet::Node::Environment.new(parts[:environment] || 'test')
|
56
|
+
end
|
57
|
+
options[:environment] = node_environment
|
58
58
|
Puppet::Node.new(node_name, options)
|
59
59
|
end
|
60
60
|
module_function :node
|
@@ -3,7 +3,7 @@ module PuppetlabsSpec
|
|
3
3
|
# FIXTURE_DIR represents the standard locations of all fixture data. Normally
|
4
4
|
# this represents <project>/spec/fixtures. This will be used by the fixtures
|
5
5
|
# library to find relative fixture data.
|
6
|
-
FIXTURE_DIR = File.join(
|
6
|
+
FIXTURE_DIR = File.join('spec', 'fixtures') unless defined?(FIXTURE_DIR)
|
7
7
|
end
|
8
8
|
|
9
9
|
# Require all necessary helper libraries so they can be used later
|
@@ -22,7 +22,7 @@ rescue LoadError
|
|
22
22
|
# ignore
|
23
23
|
end
|
24
24
|
|
25
|
-
task :
|
25
|
+
task default: [:help]
|
26
26
|
|
27
27
|
pattern = 'spec/{aliases,classes,defines,unit,functions,hosts,integration,plans,type_aliases,types}/**/*_spec.rb'
|
28
28
|
|
@@ -38,25 +38,25 @@ RSpec::Core::RakeTask.new(:spec_standalone) do |t, args|
|
|
38
38
|
t.pattern = if args.extras.nil? || args.extras.empty?
|
39
39
|
files.each_slice(per_node).to_a[ci_index - 1] || files.first
|
40
40
|
else
|
41
|
-
args.extras.join(
|
41
|
+
args.extras.join(',')
|
42
42
|
end
|
43
43
|
else
|
44
|
-
if args.extras.nil? || args.extras.empty?
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
t.pattern = if args.extras.nil? || args.extras.empty?
|
45
|
+
pattern
|
46
|
+
else
|
47
|
+
args.extras.join(',')
|
48
|
+
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
desc
|
52
|
+
desc 'List spec tests in a JSON document'
|
53
53
|
RSpec::Core::RakeTask.new(:spec_list_json) do |t|
|
54
54
|
t.rspec_opts = ['--dry-run', '--format', 'json']
|
55
55
|
t.pattern = pattern
|
56
56
|
end
|
57
57
|
|
58
|
-
desc
|
59
|
-
task :spec do |
|
58
|
+
desc 'Run spec tests and clean the fixtures directory if successful'
|
59
|
+
task :spec do |_t, args|
|
60
60
|
begin
|
61
61
|
Rake::Task[:spec_prep].invoke
|
62
62
|
Rake::Task[:spec_standalone].invoke(*args.extras)
|
@@ -66,8 +66,16 @@ task :spec do |t, args|
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
desc
|
70
|
-
|
69
|
+
desc 'Run spec tests with ruby simplecov code coverage'
|
70
|
+
namespace :spec do
|
71
|
+
task :simplecov do
|
72
|
+
ENV['SIMPLECOV'] = 'yes'
|
73
|
+
Rake::Task['spec'].execute
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'Run spec tests in parallel and clean the fixtures directory if successful'
|
78
|
+
task :parallel_spec do |_t, args|
|
71
79
|
begin
|
72
80
|
Rake::Task[:spec_prep].invoke
|
73
81
|
Rake::Task[:parallel_spec_standalone].invoke(*args.extras)
|
@@ -77,11 +85,11 @@ task :parallel_spec do |t, args|
|
|
77
85
|
end
|
78
86
|
end
|
79
87
|
|
80
|
-
desc
|
81
|
-
task :parallel_spec_standalone do |
|
88
|
+
desc 'Parallel spec tests'
|
89
|
+
task :parallel_spec_standalone do |_t, args|
|
82
90
|
raise 'Add the parallel_tests gem to Gemfile to enable this task' unless parallel_tests_loaded
|
83
91
|
if Rake::FileList[pattern].to_a.empty?
|
84
|
-
warn
|
92
|
+
warn 'No files for parallel_spec to run against'
|
85
93
|
else
|
86
94
|
begin
|
87
95
|
args = ['-t', 'rspec']
|
@@ -93,7 +101,7 @@ task :parallel_spec_standalone do |t, args|
|
|
93
101
|
end
|
94
102
|
end
|
95
103
|
|
96
|
-
desc
|
104
|
+
desc 'Build puppet module package'
|
97
105
|
task :build do
|
98
106
|
# This will be deprecated once puppet-module is a face.
|
99
107
|
begin
|
@@ -105,9 +113,9 @@ task :build do
|
|
105
113
|
end
|
106
114
|
end
|
107
115
|
|
108
|
-
desc
|
116
|
+
desc 'Clean a built module package'
|
109
117
|
task :clean do
|
110
|
-
FileUtils.rm_rf(
|
118
|
+
FileUtils.rm_rf('pkg/')
|
111
119
|
end
|
112
120
|
|
113
121
|
require 'puppet-lint/tasks/puppet-lint'
|
@@ -118,34 +126,35 @@ Rake::Task[:lint].clear
|
|
118
126
|
PuppetLint.configuration.relative = true
|
119
127
|
PuppetLint::RakeTask.new(:lint) do |config|
|
120
128
|
config.fail_on_warnings = true
|
121
|
-
config.disable_checks = [
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
129
|
+
config.disable_checks = %w[
|
130
|
+
80chars
|
131
|
+
140chars
|
132
|
+
class_inherits_from_params_class
|
133
|
+
class_parameter_defaults
|
134
|
+
documentation
|
135
|
+
single_quote_string_with_variables
|
136
|
+
]
|
128
137
|
config.ignore_paths = [
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
138
|
+
'bundle/**/*.pp',
|
139
|
+
'pkg/**/*.pp',
|
140
|
+
'spec/**/*.pp',
|
141
|
+
'tests/**/*.pp',
|
142
|
+
'types/**/*.pp',
|
143
|
+
'vendor/**/*.pp',
|
135
144
|
]
|
136
145
|
end
|
137
146
|
|
138
147
|
require 'puppet-syntax/tasks/puppet-syntax'
|
139
148
|
PuppetSyntax.exclude_paths ||= []
|
140
|
-
PuppetSyntax.exclude_paths <<
|
141
|
-
PuppetSyntax.exclude_paths <<
|
142
|
-
PuppetSyntax.exclude_paths <<
|
149
|
+
PuppetSyntax.exclude_paths << 'spec/fixtures/**/*'
|
150
|
+
PuppetSyntax.exclude_paths << 'pkg/**/*'
|
151
|
+
PuppetSyntax.exclude_paths << 'vendor/**/*'
|
143
152
|
if Puppet.version.to_f < 4.0
|
144
|
-
PuppetSyntax.exclude_paths <<
|
153
|
+
PuppetSyntax.exclude_paths << 'types/**/*'
|
145
154
|
end
|
146
155
|
PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'yes'
|
147
156
|
|
148
|
-
desc
|
157
|
+
desc 'Check syntax of Ruby files and call :syntax and :metadata_lint'
|
149
158
|
task :validate do
|
150
159
|
Dir['lib/**/*.rb'].each do |lib_file|
|
151
160
|
sh "ruby -c #{lib_file}"
|
@@ -156,7 +165,7 @@ task :validate do
|
|
156
165
|
if Rake::Task.task_defined?(:metadata_lint)
|
157
166
|
Rake::Task[:metadata_lint].invoke
|
158
167
|
else
|
159
|
-
warn
|
168
|
+
warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
|
160
169
|
end
|
161
170
|
end
|
162
171
|
end
|
@@ -166,23 +175,23 @@ task :metadata do
|
|
166
175
|
if Rake::Task.task_defined?(:metadata_lint)
|
167
176
|
Rake::Task[:metadata_lint].invoke
|
168
177
|
else
|
169
|
-
warn
|
178
|
+
warn 'Skipping metadata validation; the metadata-json-lint gem was not found'
|
170
179
|
end
|
171
180
|
end
|
172
181
|
|
173
|
-
desc
|
182
|
+
desc 'Print development version of module'
|
174
183
|
task :compute_dev_version do
|
175
184
|
version = ''
|
176
|
-
if File.
|
185
|
+
if File.exist?('metadata.json')
|
177
186
|
require 'json'
|
178
187
|
|
179
|
-
modinfo = JSON.parse(File.read(
|
188
|
+
modinfo = JSON.parse(File.read('metadata.json'))
|
180
189
|
version = modinfo['version']
|
181
|
-
elsif File.
|
190
|
+
elsif File.exist?('Modulefile')
|
182
191
|
modfile = File.read('Modulefile')
|
183
|
-
version = modfile.match(
|
192
|
+
version = modfile.match(%r{\nversion[ ]+['"](.*)['"]})[1]
|
184
193
|
else
|
185
|
-
|
194
|
+
raise 'Could not find a metadata.json or Modulefile! Cannot compute dev version without one or the other!'
|
186
195
|
end
|
187
196
|
|
188
197
|
sha = `git rev-parse HEAD`[0..7]
|
@@ -192,20 +201,20 @@ task :compute_dev_version do
|
|
192
201
|
# If the branch is a release branch we append an 'r' into the new_version,
|
193
202
|
# this is due to the release branch buildID conflicting with master branch when trying to push to the staging forge.
|
194
203
|
# More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
|
195
|
-
if build = ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
+
new_version = if build = ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']
|
205
|
+
if branch.eql? 'release'
|
206
|
+
'%s-%s%04d-%s' % [version, 'r', build, sha]
|
207
|
+
else
|
208
|
+
'%s-%04d-%s' % [version, build, sha]
|
209
|
+
end
|
210
|
+
else
|
211
|
+
"#{version}-#{sha}"
|
212
|
+
end
|
204
213
|
|
205
214
|
print new_version
|
206
215
|
end
|
207
216
|
|
208
|
-
desc
|
217
|
+
desc 'Runs all necessary checks on a module in preparation for a release'
|
209
218
|
task :release_checks do
|
210
219
|
Rake::Task[:lint].invoke
|
211
220
|
Rake::Task[:validate].invoke
|
@@ -214,56 +223,56 @@ task :release_checks do
|
|
214
223
|
else
|
215
224
|
Rake::Task[:spec].invoke
|
216
225
|
end
|
217
|
-
Rake::Task[
|
218
|
-
Rake::Task[
|
219
|
-
Rake::Task[
|
220
|
-
Rake::Task[
|
226
|
+
Rake::Task['check:symlinks'].invoke
|
227
|
+
Rake::Task['check:test_file'].invoke
|
228
|
+
Rake::Task['check:dot_underscore'].invoke
|
229
|
+
Rake::Task['check:git_ignore'].invoke
|
221
230
|
end
|
222
231
|
|
223
232
|
namespace :check do
|
224
|
-
desc
|
233
|
+
desc 'Fails if symlinks are present in directory'
|
225
234
|
task :symlinks do
|
226
235
|
symlinks = check_directory_for_symlinks
|
227
236
|
unless symlinks.empty?
|
228
|
-
symlinks.each { |r| puts "Symlink found: #{r
|
229
|
-
|
237
|
+
symlinks.each { |r| puts "Symlink found: #{r} => #{r.readlink}" }
|
238
|
+
raise 'Symlink(s) exist within this directory'
|
230
239
|
end
|
231
240
|
end
|
232
241
|
|
233
|
-
desc
|
242
|
+
desc 'Fails if .pp files present in tests folder'
|
234
243
|
task :test_file do
|
235
|
-
if Dir.exist?(
|
236
|
-
Dir.chdir(
|
237
|
-
ppfiles = Dir[
|
244
|
+
if Dir.exist?('tests')
|
245
|
+
Dir.chdir('tests')
|
246
|
+
ppfiles = Dir['*.pp']
|
238
247
|
unless ppfiles.empty?
|
239
248
|
puts ppfiles
|
240
|
-
|
249
|
+
raise '.pp files present in tests folder; Move them to an examples folder following the new convention'
|
241
250
|
end
|
242
251
|
end
|
243
252
|
end
|
244
253
|
|
245
|
-
desc
|
254
|
+
desc 'Fails if any ._ files are present in directory'
|
246
255
|
task :dot_underscore do
|
247
|
-
dirs = Dir[
|
256
|
+
dirs = Dir['._*']
|
248
257
|
unless dirs.empty?
|
249
258
|
puts dirs
|
250
|
-
|
259
|
+
raise '._ files are present in the directory'
|
251
260
|
end
|
252
261
|
end
|
253
262
|
|
254
|
-
desc
|
263
|
+
desc 'Fails if directories contain the files specified in .gitignore'
|
255
264
|
task :git_ignore do
|
256
265
|
matched = `git ls-files --ignored --exclude-standard`
|
257
|
-
unless matched ==
|
266
|
+
unless matched == ''
|
258
267
|
puts matched
|
259
|
-
|
268
|
+
raise 'File specified in .gitignore has been committed'
|
260
269
|
end
|
261
270
|
end
|
262
271
|
end
|
263
272
|
|
264
|
-
desc
|
273
|
+
desc 'Display the list of available rake tasks'
|
265
274
|
task :help do
|
266
|
-
system(
|
275
|
+
system('rake -T')
|
267
276
|
end
|
268
277
|
|
269
278
|
begin
|
@@ -273,17 +282,17 @@ begin
|
|
273
282
|
task.options = ['-D', '-S', '-E']
|
274
283
|
end
|
275
284
|
rescue LoadError
|
276
|
-
desc
|
285
|
+
desc 'rubocop is not available in this installation'
|
277
286
|
task :rubocop do
|
278
|
-
|
287
|
+
raise 'rubocop is not available in this installation'
|
279
288
|
end
|
280
289
|
end
|
281
290
|
|
282
291
|
module_dir = Dir.pwd
|
283
|
-
locales_dir = File.absolute_path('locales',
|
292
|
+
locales_dir = File.absolute_path('locales', module_dir)
|
284
293
|
# if the task is allowed to run when the module does not have a locales directory,
|
285
294
|
# the task is run in the puppet gem instead and creates a POT there.
|
286
|
-
puts
|
295
|
+
puts 'gettext-setup tasks will only be loaded if the locales/ directory is present' if Rake.verbose == true
|
287
296
|
if File.exist? locales_dir
|
288
297
|
begin
|
289
298
|
spec = Gem::Specification.find_by_name 'gettext-setup'
|
@@ -291,13 +300,13 @@ if File.exist? locales_dir
|
|
291
300
|
# Initialization requires a valid locales directory
|
292
301
|
GettextSetup.initialize_config(locales_dir)
|
293
302
|
namespace :module do
|
294
|
-
desc
|
303
|
+
desc 'Runs all tasks to build a modules POT file for internationalization'
|
295
304
|
task :pot_gen do
|
296
|
-
Rake::Task[
|
297
|
-
Rake::Task[
|
305
|
+
Rake::Task['gettext:pot'].invoke
|
306
|
+
Rake::Task['gettext:metadata_pot'].invoke("#{module_dir}/metadata.json")
|
298
307
|
end
|
299
308
|
end
|
300
309
|
rescue Gem::LoadError
|
301
|
-
puts
|
310
|
+
puts 'No gettext-setup gem found, skipping GettextSetup config initialization' if Rake.verbose == true
|
302
311
|
end
|
303
312
|
end
|