puppetlabs_spec_helper 2.14.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +15 -0
- data/.rubocop.yml +23 -6
- data/.rubocop_todo.yml +18 -18
- data/.travis.yml +14 -26
- data/CHANGELOG.md +87 -2
- data/CODEOWNERS +2 -0
- data/Gemfile +28 -10
- data/HISTORY.md +1 -1
- data/README.md +11 -34
- data/Rakefile +1 -1
- data/lib/puppetlabs_spec_helper/module_spec_helper.rb +10 -0
- data/lib/puppetlabs_spec_helper/puppet_spec_helper.rb +4 -2
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/files.rb +2 -0
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/fixtures.rb +7 -2
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/matchers.rb +4 -2
- data/lib/puppetlabs_spec_helper/puppetlabs_spec/puppet_internals.rb +5 -2
- data/lib/puppetlabs_spec_helper/puppetlabs_spec_helper.rb +2 -0
- data/lib/puppetlabs_spec_helper/rake_tasks.rb +131 -78
- data/lib/puppetlabs_spec_helper/tasks/check_symlinks.rb +4 -1
- data/lib/puppetlabs_spec_helper/tasks/fixtures.rb +161 -91
- data/lib/puppetlabs_spec_helper/version.rb +3 -1
- data/puppet_spec_helper.rb +2 -0
- data/puppetlabs_spec_helper.gemspec +8 -7
- data/puppetlabs_spec_helper.rb +2 -0
- metadata +61 -50
- data/lib/puppetlabs_spec_helper/tasks/beaker.rb +0 -112
data/HISTORY.md
CHANGED
@@ -450,7 +450,7 @@ compatible yet.
|
|
450
450
|
### Added
|
451
451
|
* Initial release
|
452
452
|
|
453
|
-
[unreleased]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.8.0...
|
453
|
+
[unreleased]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.8.0...main
|
454
454
|
[2.8.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.7.0...v2.8.0
|
455
455
|
[2.7.0]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.6.2...v2.7.0
|
456
456
|
[2.6.2]: https://github.com/puppetlabs/puppetlabs_spec_helper/compare/v2.6.1...v2.6.2
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ Host github.com
|
|
59
59
|
|
60
60
|
```
|
61
61
|
|
62
|
-
Note: parallel downloads
|
62
|
+
Note: parallel downloads are available for repositories and forge modules.
|
63
63
|
|
64
64
|
### Parallel tests
|
65
65
|
It is also possible to use the `parallel_tests` Gem via the `:parallel_spec` Rake task to run rspec commands in parallel on groups of spec files.
|
@@ -102,10 +102,10 @@ This project is intended to serve two purposes:
|
|
102
102
|
To Use this Project
|
103
103
|
===================
|
104
104
|
|
105
|
-
The most common usage scenario is that you will check out the '
|
105
|
+
The most common usage scenario is that you will check out the 'main'
|
106
106
|
branch of this project from github, and install it as a rubygem.
|
107
107
|
There should be few or no cases where you would want to have any other
|
108
|
-
branch of this project besides
|
108
|
+
branch of this project besides main/HEAD.
|
109
109
|
|
110
110
|
Running on non-current ruby versions
|
111
111
|
------------------------------------
|
@@ -156,7 +156,7 @@ variables for the spec run. These are:
|
|
156
156
|
* ``TRUSTED_NODE_DATA`` _(Puppet 3.x, starting with 3.4)_ - set to "yes" to enable [the $facts hash and trusted node data](https://puppet.com/docs/puppet/3.8/lang_facts_and_builtin_vars.html#trusted-facts),
|
157
157
|
which enabled ``$facts`` and ``$trusted`` hashes. This is equivalent to setting
|
158
158
|
[trusted_node_data=true](https://puppet.com/docs/puppet/3.8/configuration.html#trustednodedata)
|
159
|
-
in puppet.conf.
|
159
|
+
in puppet.conf.
|
160
160
|
* ``STRINGIFY_FACTS`` _(Puppet 3.x, starting with 3.5)_ - set to "no" to enable [structured facts](http://docs.puppetlabs.com/facter/2.0/fact_overview.html#writing-structured-facts),
|
161
161
|
otherwise leave unset to retain the current default behavior. This is equivalent to setting
|
162
162
|
[stringify_facts=false](https://puppet.com/docs/puppet/3.8/configuration.html#stringifyfacts)
|
@@ -203,7 +203,7 @@ When specifying the repo source of the fixture you have a few options as to whic
|
|
203
203
|
|
204
204
|
* `target` - the directory name to clone the repo into ie. `target: mymodule` defaults to the repo name (Optional)
|
205
205
|
* `subdir` - directory to be removed from the cloned repo. Its contents will be moved to the root directory (Optional)
|
206
|
-
* `ref` - used to specify the tag name like version hash
|
206
|
+
* `ref` - used to specify the tag name (like version) or commit hash to be checked out (Optional). Branch names should use the `branch` option instead.
|
207
207
|
|
208
208
|
```yaml
|
209
209
|
ref: 1.0.0
|
@@ -335,6 +335,10 @@ fixtures:
|
|
335
335
|
ref: "2.6.0"
|
336
336
|
```
|
337
337
|
|
338
|
+
Fixture Loading
|
339
|
+
---------------
|
340
|
+
Any module that has a `spec/lib` directory will be available on the ruby `LOAD_PATH` for tests to consume. This allows modules to provide additional helper code to be supplied. The [augeasprovider_core](https://github.com/hercules-team/augeasproviders_core) module has [some examples](https://github.com/hercules-team/augeasproviders_core/tree/master/spec/lib).
|
341
|
+
|
338
342
|
Testing Parser Functions
|
339
343
|
========================
|
340
344
|
|
@@ -389,7 +393,7 @@ environment variable``TEST_TIERS=high,medium``
|
|
389
393
|
|
390
394
|
By default ``TEST_TIERS`` only accepts low, medium and high as valid tiers. If you would like to use your own keywords to set the environment variable ``TEST_TIERS_ALLOWED``.
|
391
395
|
|
392
|
-
For example: to use the keywords dev, rnd, staging and production you can set
|
396
|
+
For example: to use the keywords dev, rnd, staging and production you can set
|
393
397
|
``TEST_TIERS_ALLOWED=dev,rnd,staging,production``. Then you would be able to run tests marked ``tier_dev => true``, ``tier_production => true`` with ``TEST_TIERS=dev,production``
|
394
398
|
|
395
399
|
Note, if the ``TEST_TIERS`` environment variable is set to empty string or nil, all tiers will be executed.
|
@@ -416,34 +420,7 @@ You can enable it, set the following environment variable:s
|
|
416
420
|
|
417
421
|
``SIMPLECOV=yes``
|
418
422
|
|
419
|
-
Remember to add the simplecov-console and codecov gems to your `Gemfile`.
|
420
|
-
|
421
|
-
Using Coveralls
|
422
|
-
---------------
|
423
|
-
|
424
|
-
You can also use [Coveralls](https://coveralls.io/) together with SimpleCov:
|
425
|
-
|
426
|
-
```Ruby
|
427
|
-
# First line of spec/spec_helper.rb
|
428
|
-
require 'simplecov'
|
429
|
-
require 'coveralls'
|
430
|
-
|
431
|
-
SimpleCov.formatters = [
|
432
|
-
SimpleCov::Formatter::HTMLFormatter,
|
433
|
-
Coveralls::SimpleCov::Formatter
|
434
|
-
]
|
435
|
-
|
436
|
-
SimpleCov.start do
|
437
|
-
add_filter '/spec/'
|
438
|
-
# Exclude bundled Gems in `/.vendor/`
|
439
|
-
add_filter '/.vendor/'
|
440
|
-
end
|
441
|
-
|
442
|
-
require 'puppetlabs_spec_helper/module_spec_helper'
|
443
|
-
# Further content
|
444
|
-
```
|
445
|
-
|
446
|
-
Remember to add `gem 'coveralls', require: false` to your `Gemfile`.
|
423
|
+
Remember to add the simplecov-console and codecov gems to your `Gemfile`. If you run `spec:simplecov` on Travis-CI or any of the other supported CI services, reports gets automatically uploaded to https://codecov.io/ .
|
447
424
|
|
448
425
|
Some Notes for Windows Users
|
449
426
|
============================
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rspec-puppet'
|
2
4
|
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
3
5
|
require 'puppetlabs_spec_helper/puppetlabs_spec/puppet_internals'
|
@@ -50,6 +52,14 @@ if ENV['SIMPLECOV'] == 'yes'
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
55
|
+
# Add all spec lib dirs to LOAD_PATH
|
56
|
+
components = module_path.split(File::PATH_SEPARATOR).collect do |dir|
|
57
|
+
Dir.entries(dir).reject { |f| f =~ %r{^\.} }.collect { |f| File.join(dir, f, 'spec', 'lib') }
|
58
|
+
end
|
59
|
+
components.flatten.each do |d|
|
60
|
+
$LOAD_PATH << d if FileTest.directory?(d) && !$LOAD_PATH.include?(d)
|
61
|
+
end
|
62
|
+
|
53
63
|
RSpec.configure do |c|
|
54
64
|
c.environmentpath = spec_path if Puppet.version.to_f >= 4.0
|
55
65
|
c.module_path = module_path
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'puppetlabs_spec_helper/puppetlabs_spec_helper'
|
2
4
|
|
3
5
|
# Don't want puppet getting the command line arguments for rake or autotest
|
@@ -45,7 +47,7 @@ require 'puppetlabs_spec_helper/puppetlabs_spec/files'
|
|
45
47
|
# to compatibility mode for older versions of puppet.
|
46
48
|
begin
|
47
49
|
require 'puppet/test/test_helper'
|
48
|
-
rescue LoadError
|
50
|
+
rescue LoadError
|
49
51
|
end
|
50
52
|
|
51
53
|
# This is just a utility class to allow us to isolate the various version-specific
|
@@ -58,7 +60,7 @@ module Puppet
|
|
58
60
|
# Puppet's Settings singleton object, and other fun implementation details
|
59
61
|
# that code external to puppet should really never know about.
|
60
62
|
def self.initialize_via_fallback_compatibility(config)
|
61
|
-
|
63
|
+
warn('Warning: you appear to be using an older version of puppet; spec_helper will use fallback compatibility mode.')
|
62
64
|
config.before :all do
|
63
65
|
# nothing to do for now
|
64
66
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This module provides some helper methods to assist with fixtures. It's
|
2
4
|
# methods are designed to help when you have a conforming fixture layout so we
|
3
5
|
# get project consistency.
|
@@ -14,6 +16,7 @@ module PuppetlabsSpec::Fixtures
|
|
14
16
|
callers = caller
|
15
17
|
while line = callers.shift
|
16
18
|
next unless found = line.match(%r{/spec/(.*)_spec\.rb:})
|
19
|
+
|
17
20
|
return fixtures(found[1])
|
18
21
|
end
|
19
22
|
raise "sorry, I couldn't work out your path from the caller stack!"
|
@@ -26,6 +29,7 @@ module PuppetlabsSpec::Fixtures
|
|
26
29
|
unless File.readable? file
|
27
30
|
raise "fixture '#{name}' for #{my_fixture_dir} is not readable"
|
28
31
|
end
|
32
|
+
|
29
33
|
file
|
30
34
|
end
|
31
35
|
|
@@ -37,12 +41,13 @@ module PuppetlabsSpec::Fixtures
|
|
37
41
|
|
38
42
|
# Provides a block mechanism for iterating across the files in your fixture
|
39
43
|
# area.
|
40
|
-
def my_fixtures(glob = '*', flags = 0)
|
44
|
+
def my_fixtures(glob = '*', flags = 0, &block)
|
41
45
|
files = Dir.glob(File.join(my_fixture_dir, glob), flags)
|
42
46
|
if files.empty?
|
43
47
|
raise "fixture '#{glob}' for #{my_fixture_dir} had no files!"
|
44
48
|
end
|
45
|
-
|
49
|
+
|
50
|
+
block_given? && files.each(&block)
|
46
51
|
files
|
47
52
|
end
|
48
53
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'stringio'
|
2
4
|
require 'rspec/expectations'
|
3
5
|
|
@@ -6,8 +8,8 @@ require 'rspec/expectations'
|
|
6
8
|
module RSpec
|
7
9
|
module Matchers
|
8
10
|
module BlockAliases
|
9
|
-
if method_defined? :
|
10
|
-
alias to should
|
11
|
+
if method_defined?(:should) && !method_defined?(:to)
|
12
|
+
alias to should
|
11
13
|
end
|
12
14
|
if method_defined? :should_not
|
13
15
|
alias to_not should_not unless method_defined? :to_not
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Initialize puppet for testing by loading the
|
2
4
|
# 'puppetlabs_spec_helper/puppet_spec_helper' library
|
3
5
|
require 'puppetlabs_spec_helper/puppet_spec_helper'
|
@@ -10,7 +12,7 @@ module PuppetlabsSpec
|
|
10
12
|
def scope(parts = {})
|
11
13
|
RSpec.deprecate('scope', replacement: 'rspec-puppet 2.2.0 provides a scope property')
|
12
14
|
|
13
|
-
if
|
15
|
+
if %r{^2\.[67]}.match?(Puppet.version)
|
14
16
|
# loadall should only be necessary prior to 3.x
|
15
17
|
# Please note, loadall needs to happen first when creating a scope, otherwise
|
16
18
|
# you might receive undefined method `function_*' errors
|
@@ -21,7 +23,7 @@ module PuppetlabsSpec
|
|
21
23
|
scope_parent = parts[:parent] || scope_compiler.topscope
|
22
24
|
scope_resource = parts[:resource] || resource(type: :node, title: scope_compiler.node.name)
|
23
25
|
|
24
|
-
scope = if
|
26
|
+
scope = if %r{^2\.[67]}.match?(Puppet.version)
|
25
27
|
Puppet::Parser::Scope.new(compiler: scope_compiler)
|
26
28
|
else
|
27
29
|
Puppet::Parser::Scope.new(scope_compiler)
|
@@ -67,6 +69,7 @@ module PuppetlabsSpec
|
|
67
69
|
# exists. This is a hack, but at least it's a hidden hack and not an
|
68
70
|
# exposed hack.
|
69
71
|
return nil unless Puppet::Parser::Functions.function(name)
|
72
|
+
|
70
73
|
scope.method("function_#{name}".intern)
|
71
74
|
end
|
72
75
|
module_function :function_method
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fileutils'
|
2
4
|
require 'rake'
|
3
5
|
require 'rspec/core/rake_task'
|
4
6
|
require 'tmpdir'
|
5
7
|
require 'pathname'
|
6
8
|
require 'puppetlabs_spec_helper/version'
|
7
|
-
require 'puppetlabs_spec_helper/tasks/beaker'
|
8
9
|
require 'puppetlabs_spec_helper/tasks/fixtures'
|
9
10
|
require 'puppetlabs_spec_helper/tasks/check_symlinks'
|
10
11
|
require 'English'
|
@@ -53,6 +54,7 @@ RSpec::Core::RakeTask.new(:spec_standalone) do |t, args|
|
|
53
54
|
ci_total = ENV['CI_NODE_TOTAL'].to_i
|
54
55
|
ci_index = ENV['CI_NODE_INDEX'].to_i
|
55
56
|
raise "CI_NODE_INDEX must be between 1-#{ci_total}" unless ci_index >= 1 && ci_index <= ci_total
|
57
|
+
|
56
58
|
files = Rake::FileList[pattern].to_a
|
57
59
|
per_node = (files.size / ci_total.to_f).ceil
|
58
60
|
t.pattern = if args.extras.nil? || args.extras.empty?
|
@@ -108,16 +110,17 @@ end
|
|
108
110
|
desc 'Parallel spec tests'
|
109
111
|
task :parallel_spec_standalone do |_t, args|
|
110
112
|
raise 'Add the parallel_tests gem to Gemfile to enable this task' unless parallel_tests_loaded
|
113
|
+
|
111
114
|
if Rake::FileList[pattern].to_a.empty?
|
112
115
|
warn 'No files for parallel_spec to run against'
|
113
116
|
else
|
114
|
-
begin
|
115
|
-
args = ['-t', 'rspec']
|
116
|
-
args.push('--').concat(ENV['CI_SPEC_OPTIONS'].strip.split(' ')).push('--') unless ENV['CI_SPEC_OPTIONS'].nil? || ENV['CI_SPEC_OPTIONS'].strip.empty?
|
117
|
-
args.concat(Rake::FileList[pattern].to_a)
|
118
117
|
|
119
|
-
|
120
|
-
|
118
|
+
args = ['-t', 'rspec']
|
119
|
+
args.push('--').concat(ENV['CI_SPEC_OPTIONS'].strip.split(' ')).push('--') unless ENV['CI_SPEC_OPTIONS'].nil? || ENV['CI_SPEC_OPTIONS'].strip.empty?
|
120
|
+
args.concat(Rake::FileList[pattern].to_a)
|
121
|
+
|
122
|
+
ParallelTests::CLI.new.run(args)
|
123
|
+
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
@@ -142,14 +145,15 @@ namespace :build do
|
|
142
145
|
desc 'Build Puppet module with PDK'
|
143
146
|
task :pdk do
|
144
147
|
begin
|
148
|
+
require 'pdk/util'
|
145
149
|
require 'pdk/module/build'
|
146
150
|
|
147
|
-
path = PDK::Module::Build.invoke(:
|
151
|
+
path = PDK::Module::Build.invoke(force: true, 'target-dir': File.join(Dir.pwd, 'pkg'))
|
148
152
|
puts "Module built: #{path}"
|
149
153
|
rescue LoadError
|
150
154
|
_ = `pdk --version`
|
151
155
|
unless $CHILD_STATUS.success?
|
152
|
-
|
156
|
+
warn 'Unable to build module. Please install PDK or add the `pdk` gem to your Gemfile.'
|
153
157
|
abort
|
154
158
|
end
|
155
159
|
|
@@ -167,52 +171,34 @@ require 'puppet-lint/tasks/puppet-lint'
|
|
167
171
|
# Must clear as it will not override the existing puppet-lint rake task since we require to import for
|
168
172
|
# the PuppetLint::RakeTask
|
169
173
|
Rake::Task[:lint].clear
|
170
|
-
#
|
174
|
+
# Utilize PuppetLint global configuration so that these settings can be tweaked by
|
175
|
+
# spec_helper.rb in an individual module
|
171
176
|
PuppetLint.configuration.relative = true
|
172
|
-
PuppetLint
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
]
|
177
|
+
PuppetLint.configuration.ignore_paths ||= []
|
178
|
+
PuppetLint.configuration.ignore_paths << '.vendor/**/*.pp'
|
179
|
+
PuppetLint.configuration.ignore_paths << 'bundle/**/*.pp'
|
180
|
+
PuppetLint.configuration.ignore_paths << 'pkg/**/*.pp'
|
181
|
+
PuppetLint.configuration.ignore_paths << 'spec/**/*.pp'
|
182
|
+
PuppetLint.configuration.ignore_paths << 'tests/**/*.pp'
|
183
|
+
PuppetLint.configuration.ignore_paths << 'types/**/*.pp'
|
184
|
+
PuppetLint.configuration.ignore_paths << 'vendor/**/*.pp'
|
185
|
+
puppet_lint_disable_checks = %w[
|
186
|
+
80chars
|
187
|
+
140chars
|
188
|
+
class_inherits_from_params_class
|
189
|
+
class_parameter_defaults
|
190
|
+
disable_autoloader_layout
|
191
|
+
documentation
|
192
|
+
single_quote_string_with_variables
|
193
|
+
]
|
194
|
+
puppet_lint_disable_checks.each do |check|
|
195
|
+
PuppetLint.configuration.send("disable_#{check}")
|
192
196
|
end
|
197
|
+
PuppetLint::RakeTask.new(:lint)
|
193
198
|
|
194
199
|
desc 'Run puppet-lint and fix issues automatically'
|
195
200
|
PuppetLint::RakeTask.new(:lint_fix) do |config|
|
196
|
-
config.fail_on_warnings = true
|
197
201
|
config.fix = true
|
198
|
-
config.disable_checks = %w[
|
199
|
-
80chars
|
200
|
-
140chars
|
201
|
-
class_inherits_from_params_class
|
202
|
-
class_parameter_defaults
|
203
|
-
disable_autoloader_layout
|
204
|
-
documentation
|
205
|
-
single_quote_string_with_variables
|
206
|
-
]
|
207
|
-
config.ignore_paths = [
|
208
|
-
'.vendor/**/*.pp',
|
209
|
-
'bundle/**/*.pp',
|
210
|
-
'pkg/**/*.pp',
|
211
|
-
'spec/**/*.pp',
|
212
|
-
'tests/**/*.pp',
|
213
|
-
'types/**/*.pp',
|
214
|
-
'vendor/**/*.pp',
|
215
|
-
]
|
216
202
|
end
|
217
203
|
|
218
204
|
require 'puppet-syntax/tasks/puppet-syntax'
|
@@ -220,7 +206,8 @@ PuppetSyntax.exclude_paths ||= []
|
|
220
206
|
PuppetSyntax.exclude_paths << 'spec/fixtures/**/*'
|
221
207
|
PuppetSyntax.exclude_paths << 'pkg/**/*'
|
222
208
|
PuppetSyntax.exclude_paths << 'vendor/**/*'
|
223
|
-
PuppetSyntax.exclude_paths << '
|
209
|
+
PuppetSyntax.exclude_paths << '.vendor/**/*'
|
210
|
+
PuppetSyntax.exclude_paths << 'plans/**/*'
|
224
211
|
if Puppet.version.to_f < 4.0
|
225
212
|
PuppetSyntax.exclude_paths << 'types/**/*'
|
226
213
|
end
|
@@ -261,7 +248,7 @@ task :compute_dev_version do
|
|
261
248
|
version = modinfo['version']
|
262
249
|
elsif File.exist?('Modulefile')
|
263
250
|
modfile = File.read('Modulefile')
|
264
|
-
version = modfile.match(%r{\nversion
|
251
|
+
version = modfile.match(%r{\nversion +['"](.*)['"]})[1]
|
265
252
|
else
|
266
253
|
raise 'Could not find a metadata.json or Modulefile! Cannot compute dev version without one or the other!'
|
267
254
|
end
|
@@ -271,14 +258,14 @@ task :compute_dev_version do
|
|
271
258
|
|
272
259
|
# If we're in a CI environment include our build number
|
273
260
|
# If the branch is a release branch we append an 'r' into the new_version,
|
274
|
-
# this is due to the release branch buildID conflicting with
|
261
|
+
# this is due to the release branch buildID conflicting with main branch when trying to push to the staging forge.
|
275
262
|
# More info can be found at https://tickets.puppetlabs.com/browse/FM-6170
|
276
|
-
new_version = if build = ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER']
|
263
|
+
new_version = if build = (ENV['BUILD_NUMBER'] || ENV['TRAVIS_BUILD_NUMBER'])
|
277
264
|
if branch.eql? 'release'
|
278
|
-
'%s-%s%04d-%s' % [version, 'r', build, sha]
|
265
|
+
'%s-%s%04d-%s' % [version, 'r', build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
|
279
266
|
else
|
280
|
-
'%s-%04d-%s' % [version, build, sha]
|
281
|
-
|
267
|
+
'%s-%04d-%s' % [version, build, sha] # legacy support code # rubocop:disable Style/FormatStringToken
|
268
|
+
end
|
282
269
|
else
|
283
270
|
"#{version}-#{sha}"
|
284
271
|
end
|
@@ -295,10 +282,7 @@ task :release_checks do
|
|
295
282
|
else
|
296
283
|
Rake::Task[:spec].invoke
|
297
284
|
end
|
298
|
-
Rake::Task[
|
299
|
-
Rake::Task['check:test_file'].invoke
|
300
|
-
Rake::Task['check:dot_underscore'].invoke
|
301
|
-
Rake::Task['check:git_ignore'].invoke
|
285
|
+
Rake::Task[:check].invoke
|
302
286
|
end
|
303
287
|
|
304
288
|
namespace :check do
|
@@ -339,6 +323,9 @@ namespace :check do
|
|
339
323
|
end
|
340
324
|
end
|
341
325
|
|
326
|
+
desc 'Run static pre release checks'
|
327
|
+
task check: ['check:symlinks', 'check:test_file', 'check:dot_underscore', 'check:git_ignore']
|
328
|
+
|
342
329
|
desc 'Display the list of available rake tasks'
|
343
330
|
task :help do
|
344
331
|
system('rake -T')
|
@@ -349,6 +336,14 @@ begin
|
|
349
336
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
350
337
|
# These make the rubocop experience maybe slightly less terrible
|
351
338
|
task.options = ['-D', '-S', '-E']
|
339
|
+
|
340
|
+
# Use Rubocop's Github Actions formatter if possible
|
341
|
+
if ENV['GITHUB_ACTIONS'] == 'true'
|
342
|
+
rubocop_spec = Gem::Specification.find_by_name('rubocop')
|
343
|
+
if Gem::Version.new(rubocop_spec.version) >= Gem::Version.new('1.2')
|
344
|
+
task.formatters << 'github'
|
345
|
+
end
|
346
|
+
end
|
352
347
|
end
|
353
348
|
rescue LoadError
|
354
349
|
desc 'rubocop is not available in this installation'
|
@@ -357,25 +352,83 @@ rescue LoadError
|
|
357
352
|
end
|
358
353
|
end
|
359
354
|
|
360
|
-
|
361
|
-
|
362
|
-
#
|
363
|
-
#
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
355
|
+
def create_gch_task(changelog_user = nil, changelog_project = nil, changelog_since_tag = nil, changelog_tag_pattern = 'v%s')
|
356
|
+
if Bundler.rubygems.find_name('github_changelog_generator').any?
|
357
|
+
# needed a place to hide these methods
|
358
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
359
|
+
def changelog_user_from_metadata
|
360
|
+
result = JSON.parse(File.read('metadata.json'))['author']
|
361
|
+
raise 'unable to find the changelog_user in .sync.yml, or the author in metadata.json' if result.nil?
|
362
|
+
|
363
|
+
puts "GitHubChangelogGenerator user:#{result}"
|
364
|
+
result
|
365
|
+
end
|
366
|
+
|
367
|
+
def changelog_project_from_metadata
|
368
|
+
result = JSON.parse(File.read('metadata.json'))['name']
|
369
|
+
raise 'unable to find the changelog_project in .sync.yml or the name in metadata.json' if result.nil?
|
370
|
+
|
371
|
+
puts "GitHubChangelogGenerator project:#{result}"
|
372
|
+
result
|
373
|
+
end
|
374
|
+
|
375
|
+
def changelog_future_release
|
376
|
+
return unless Rake.application.top_level_tasks.include? 'changelog'
|
377
|
+
|
378
|
+
result = JSON.parse(File.read('metadata.json'))['version']
|
379
|
+
raise 'unable to find the future_release (version) in metadata.json' if result.nil?
|
380
|
+
|
381
|
+
puts "GitHubChangelogGenerator future_release:#{result}"
|
382
|
+
result
|
383
|
+
end
|
384
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
385
|
+
|
386
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
387
|
+
if ENV['CHANGELOG_GITHUB_TOKEN'].nil?
|
388
|
+
raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'"
|
376
389
|
end
|
390
|
+
|
391
|
+
config.user = changelog_user || changelog_user_from_metadata
|
392
|
+
config.project = changelog_project || changelog_project_from_metadata
|
393
|
+
config.since_tag = changelog_since_tag if changelog_since_tag
|
394
|
+
config.future_release = changelog_tag_pattern % changelog_future_release.to_s
|
395
|
+
config.exclude_labels = ['maintenance']
|
396
|
+
config.header = "# Change log\n\nAll notable changes to this project will be documented in this file. " \
|
397
|
+
'The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres ' \
|
398
|
+
'to [Semantic Versioning](https://semver.org).'
|
399
|
+
config.add_pr_wo_labels = true
|
400
|
+
config.issues = false
|
401
|
+
config.merge_prefix = '### UNCATEGORIZED PRS; GO LABEL THEM'
|
402
|
+
config.configure_sections = {
|
403
|
+
'Changed' => {
|
404
|
+
'prefix' => '### Changed',
|
405
|
+
'labels' => ['backwards-incompatible'],
|
406
|
+
},
|
407
|
+
'Added' => {
|
408
|
+
'prefix' => '### Added',
|
409
|
+
'labels' => %w[feature enhancement],
|
410
|
+
},
|
411
|
+
'Fixed' => {
|
412
|
+
'prefix' => '### Fixed',
|
413
|
+
'labels' => ['bugfix'],
|
414
|
+
},
|
415
|
+
}
|
416
|
+
end
|
417
|
+
else
|
418
|
+
desc 'Generate a Changelog from GitHub'
|
419
|
+
task :changelog do
|
420
|
+
raise <<~MESSAGE
|
421
|
+
The changelog tasks depends on unreleased features of the github_changelog_generator gem.
|
422
|
+
Please manually add it to your .sync.yml for now, and run `pdk update`:
|
423
|
+
---
|
424
|
+
Gemfile:
|
425
|
+
optional:
|
426
|
+
':development':
|
427
|
+
- gem: 'github_changelog_generator'
|
428
|
+
git: 'https://github.com/skywinder/github-changelog-generator'
|
429
|
+
ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018'
|
430
|
+
condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')"
|
431
|
+
MESSAGE
|
377
432
|
end
|
378
|
-
rescue Gem::LoadError
|
379
|
-
puts 'No gettext-setup gem found, skipping GettextSetup config initialization' if Rake.verbose == true
|
380
433
|
end
|
381
434
|
end
|