Skip to content

Commit 3ee38dc

Browse files
authored
Merge pull request #4 from innogames/feature/port-functions
Port old-style puppet functions to new API
2 parents bbf0d05 + 0361b63 commit 3ee38dc

20 files changed

+224
-128
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
/convert_report.txt
2323
/update_report.txt
2424
.DS_Store
25+
.project
26+
.envrc
27+
/inventory.yaml

.gitlab-ci.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@ cache:
1010
before_script:
1111
- bundle -v
1212
- rm Gemfile.lock || true
13-
- gem update --system $RUBYGEMS_VERSION
13+
- "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner"
14+
- "# Set `rubygems_version` in the .sync.yml to set a value"
15+
- "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set"
16+
- '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION'
1417
- gem --version
1518
- bundle -v
1619
- bundle install --without system_tests --path vendor/bundle --jobs $(nproc)
1720

18-
parallel_spec-Ruby 2.1.9-Puppet ~> 4.0:
19-
stage: unit
20-
image: ruby:2.1.9
21+
syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.5.7-Puppet ~> 6:
22+
stage: syntax
23+
image: ruby:2.5.7
2124
script:
22-
- bundle exec rake parallel_spec
25+
- bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
2326
variables:
24-
PUPPET_GEM_VERSION: '~> 4.0'
25-
RUBYGEMS_VERSION: '2.7.8'
27+
PUPPET_GEM_VERSION: '~> 6'
2628

27-
syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop-Ruby 2.4.4-Puppet ~> 5.5:
28-
stage: syntax
29-
image: ruby:2.4.4
29+
parallel_spec-Ruby 2.5.7-Puppet ~> 6:
30+
stage: unit
31+
image: ruby:2.5.7
3032
script:
31-
- bundle exec rake syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
33+
- bundle exec rake parallel_spec
3234
variables:
33-
PUPPET_GEM_VERSION: '~> 5.5'
35+
PUPPET_GEM_VERSION: '~> 6'
3436

35-
parallel_spec-Ruby 2.4.4-Puppet ~> 5.5:
37+
parallel_spec-Ruby 2.4.5-Puppet ~> 5:
3638
stage: unit
37-
image: ruby:2.4.4
39+
image: ruby:2.4.5
3840
script:
3941
- bundle exec rake parallel_spec
4042
variables:
41-
PUPPET_GEM_VERSION: '~> 5.5'
43+
PUPPET_GEM_VERSION: '~> 5'
4244

.pdkignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
/convert_report.txt
2323
/update_report.txt
2424
.DS_Store
25+
.project
26+
.envrc
27+
/inventory.yaml
2528
/appveyor.yml
2629
/.fixtures.yml
2730
/Gemfile
@@ -30,8 +33,10 @@
3033
/.gitlab-ci.yml
3134
/.pdkignore
3235
/Rakefile
36+
/rakelib/
3337
/.rspec
3438
/.rubocop.yml
3539
/.travis.yml
3640
/.yardopts
3741
/spec/
42+
/.vscode/

.puppet-lint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
--relative

.rubocop.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
2-
require: rubocop-rspec
2+
require:
3+
- rubocop-rspec
4+
- rubocop-i18n
35
AllCops:
46
DisplayCopNames: true
57
TargetRubyVersion: '2.1'
@@ -19,10 +21,13 @@ AllCops:
1921
Metrics/LineLength:
2022
Description: People have wide screens, use them.
2123
Max: 200
24+
GetText:
25+
Enabled: false
2226
GetText/DecorateString:
2327
Description: We don't want to decorate test output.
2428
Exclude:
25-
- spec/*
29+
- spec/**/*
30+
Enabled: false
2631
RSpec/BeforeAfterAll:
2732
Description: Beware of using after(:all) as it may cause state to leak between tests.
2833
A necessary evil in acceptance testing.
@@ -35,6 +40,10 @@ Style/BlockDelimiters:
3540
Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to
3641
be consistent then.
3742
EnforcedStyle: braces_for_chaining
43+
Style/BracesAroundHashParameters:
44+
Description: Braces are required by Ruby 2.7. Cop removed from RuboCop v0.80.0.
45+
See https://github.com/rubocop-hq/rubocop/pull/7643
46+
Enabled: true
3847
Style/ClassAndModuleChildren:
3948
Description: Compact style reduces the required amount of indentation.
4049
EnforcedStyle: compact
@@ -84,6 +93,12 @@ Style/MethodCalledOnDoEndBlock:
8493
Enabled: true
8594
Style/StringMethods:
8695
Enabled: true
96+
GetText/DecorateFunctionMessage:
97+
Enabled: false
98+
GetText/DecorateStringFormattingUsingInterpolation:
99+
Enabled: false
100+
GetText/DecorateStringFormattingUsingPercent:
101+
Enabled: false
87102
Layout/EndOfLine:
88103
Enabled: false
89104
Layout/IndentHeredoc:

.travis.yml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
11
---
2-
dist: trusty
2+
os: linux
3+
dist: xenial
34
language: ruby
45
cache: bundler
56
before_install:
67
- bundle -v
78
- rm -f Gemfile.lock
8-
- gem update --system $RUBYGEMS_VERSION
9+
- "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner"
10+
- "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used"
11+
- "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set"
12+
- '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION'
913
- gem --version
1014
- bundle -v
1115
script:
1216
- 'bundle exec rake $CHECK'
1317
bundler_args: --without system_tests
1418
rvm:
15-
- 2.5.1
16-
env:
17-
global:
18-
- BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0"
19+
- 2.5.7
1920
stages:
21+
- static
22+
- spec
23+
- acceptance
2024
- test
2125
-
2226
if: tag =~ ^v
2327
name: deploy
24-
matrix:
28+
-
29+
if: tag =~ ^v\d
30+
name: deploy
31+
jobs:
2532
fast_finish: true
2633
include:
2734
-
28-
env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop"
29-
-
30-
env: CHECK=parallel_spec
35+
env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint"
36+
stage: static
3137
-
3238
env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec
33-
rvm: 2.4.4
39+
rvm: 2.4.5
40+
stage: spec
3441
-
35-
env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec RUBYGEMS_VERSION=2.7.8
36-
rvm: 2.1.9
42+
env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
43+
rvm: 2.5.7
44+
stage: spec
45+
-
46+
env: DEPLOY_TO_FORGE=yes
47+
stage: deploy
3748
-
3849
env: CHECK='build' DEPLOY_TO_FORGE=yes
3950
stage: deploy
@@ -45,7 +56,7 @@ notifications:
4556
email: false
4657
deploy:
4758
provider: puppetforge
48-
user: innogames
59+
username: innogames
4960
password:
5061
secure: "YsTvDpCHiuMpQ41X5GMUz8kbbHUAXVVoUWsnzXdsq5UnSMgVVTrQTnrzRSwFSKtkQJkm+N5BOn1WXj3te+eGsV+Ca4hXk/hygKcHMZNBT3ZKJs1GJdW4CfOxBzdgHjT7cY7UFaDFB1vb8S6dC36R03kqizVuiWI3KC9cO5msgPB5LSIxnJYDkRqZcHPQFF8EAgIP/zidlt18fYhbTOcG61vN59aGcl3aYHxD8YGgKe5OOQk41GxvWe6tsFFHW9f8Bg7FwwMLfA7sii4TV3tW9XXP9WhfL+/VhazIPf8cLK017W4RaHi3NW+GT9d3fz15UWYta7/69i8fzg+1w+0y7hA4Fm2+aunuArYvKIzf+3erBa8RvJE563wP3xx20czjsmP26ecTo0uyHiqvovhHUF7s39EWyQgv6zNPOT5IfYKDTZxj/wMIYUEas9GPJOYjyPi08TkIK2ABi2SQsPeXz7gTaANaTeIR8jcvxNItZ9Kr0SkazZaRMUJI3Lhn1dx2jt705H5FdjFFC2xLfVdFgJVNHUTuO9ZWEH73QJnj6g11lwFDejz8xAdcpi287kpOQ59rVit8Tn2y+CJY9R30o1ac5CKQ6EXpP7DuZRiPx7+S4OQItwX7ep5GiOgo6mD5VsaPr3uHebT9islxzvCboIFv+FcPkmrTwFI0fJQFY5A="
5162
on:

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"puppet.puppet-vscode",
4+
"rebornix.Ruby"
5+
]
6+
}

Gemfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ ruby_version_segments = Gem::Version.new(RUBY_VERSION.dup).segments
1717
minor_version = ruby_version_segments[0..1].join('.')
1818

1919
group :development do
20-
gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0')
21-
gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
22-
gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
23-
gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9')
24-
gem "json", '<= 2.0.4', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4')
25-
gem "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby]
26-
gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby]
27-
gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
28-
gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
29-
gem "pdk", require: false
20+
gem "fast_gettext", '1.1.0', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.1.0')
21+
gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
22+
gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
23+
gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9')
24+
gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
25+
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
26+
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
27+
gem "puppet-module-posix-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby]
28+
gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:ruby]
29+
gem "puppet-module-win-default-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
30+
gem "puppet-module-win-dev-r#{minor_version}", '~> 0.4', require: false, platforms: [:mswin, :mingw, :x64_mingw]
31+
gem "pdk", require: false
3032
end
3133
group :dependencies do
3234
gem "xml-simple", require: false

REFERENCE.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@
1212

1313
### hash_to_xml
1414

15-
Type: Ruby 3.x API
15+
Type: Ruby 4.x API
1616

1717
Function that converts a hash to an XML string
1818

19+
#### `hash_to_xml(Hash $data)`
20+
21+
The hash_to_xml function.
22+
23+
Returns: `String` xml is generated from `$data`
24+
25+
##### `data`
26+
27+
Data type: `Hash`
28+
29+
Hash to be converted into xml
30+
1931
#### `hash_to_xml(Hash $data, Hash $options)`
2032

21-
Function that converts a hash to an XML string
33+
The hash_to_xml function.
2234

2335
Returns: `String` xml is generated from `$data`
2436

@@ -32,21 +44,33 @@ Hash to be converted into xml
3244

3345
Data type: `Hash`
3446

35-
(optional) second parameter will be passed into XmlSimple.xml_out
47+
The second parameter will be passed into XmlSimple.xml_out
3648

3749
### xml_to_hash
3850

39-
Type: Ruby 3.x API
51+
Type: Ruby 4.x API
4052

4153
Function to convert an xml file into a hash via xml-simple
4254

43-
#### `xml_to_hash(String $xml, Hash $options)`
55+
#### `xml_to_hash(String $xml_file)`
4456

45-
Function to convert an xml file into a hash via xml-simple
57+
The xml_to_hash function.
58+
59+
Returns: `Hash` data are converted from xml
60+
61+
##### `xml_file`
62+
63+
Data type: `String`
64+
65+
Local file name to be passed into XmlSimple.xml_in
66+
67+
#### `xml_to_hash(String $xml_file, Hash $options)`
68+
69+
The xml_to_hash function.
4670

4771
Returns: `Hash` data are converted from xml
4872

49-
##### `xml`
73+
##### `xml_file`
5074

5175
Data type: `String`
5276

Rakefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?
14
require 'puppetlabs_spec_helper/rake_tasks'
25
require 'puppet-syntax/tasks/puppet-syntax'
36
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
@@ -14,15 +17,24 @@ end
1417

1518
def changelog_project
1619
return unless Rake.application.top_level_tasks.include? "changelog"
17-
returnVal = nil || JSON.load(File.read('metadata.json'))['name']
18-
raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil?
20+
21+
returnVal = nil
22+
returnVal ||= begin
23+
metadata_source = JSON.load(File.read('metadata.json'))['source']
24+
metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})
25+
26+
metadata_source_match && metadata_source_match[1]
27+
end
28+
29+
raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?
30+
1931
puts "GitHubChangelogGenerator project:#{returnVal}"
2032
returnVal
2133
end
2234

2335
def changelog_future_release
2436
return unless Rake.application.top_level_tasks.include? "changelog"
25-
returnVal = JSON.load(File.read('metadata.json'))['version']
37+
returnVal = "v%s" % JSON.load(File.read('metadata.json'))['version']
2638
raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
2739
puts "GitHubChangelogGenerator future_release:#{returnVal}"
2840
returnVal

appveyor.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: 1.1.x.{build}
33
branches:
44
only:
55
- master
6+
- release
67
skip_commits:
78
message: /^\(?doc\)?.*/
89
clone_depth: 10
@@ -17,14 +18,6 @@ environment:
1718
-
1819
RUBY_VERSION: 24-x64
1920
CHECK: syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop
20-
-
21-
PUPPET_GEM_VERSION: ~> 4.0
22-
RUBY_VERSION: 21
23-
CHECK: parallel_spec
24-
-
25-
PUPPET_GEM_VERSION: ~> 4.0
26-
RUBY_VERSION: 21-x64
27-
CHECK: parallel_spec
2821
-
2922
PUPPET_GEM_VERSION: ~> 5.0
3023
RUBY_VERSION: 24

lib/puppet/functions/hash_to_xml.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'xmlsimple'
2+
3+
# @summary
4+
# Function that converts a hash to an XML string
5+
Puppet::Functions.create_function(:hash_to_xml) do
6+
# @param [Hash] data Hash to be converted into xml
7+
#
8+
# @return [String]
9+
# xml is generated from `$data`
10+
dispatch :default_impl do
11+
param 'Hash', :data
12+
end
13+
14+
# @param [Hash] data Hash to be converted into xml
15+
# @param [Hash] options The second parameter will be passed into XmlSimple.xml_out
16+
#
17+
# @return [String]
18+
# xml is generated from `$data`
19+
dispatch :with_options do
20+
param 'Hash', :data
21+
param 'Hash', :options
22+
end
23+
24+
def default_impl(data)
25+
XmlSimple.xml_out(data)
26+
end
27+
28+
def with_options(data, options)
29+
XmlSimple.xml_out(data, options)
30+
end
31+
end

0 commit comments

Comments
 (0)