puppet_metadata 0.2.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd0637a24f15f5fbe1876402af082cfdb245d68683de8397dd11703cdc996788
4
- data.tar.gz: 5ec9738ce657cc4dba65d4af0a4b40093acdd934fcf1d302001efae788633fdd
3
+ metadata.gz: 6300f8af60fd02edd766e7150d921ab9cfc544f50215af3e3785462206c994fe
4
+ data.tar.gz: 1a912db344e52bef3577323236cb76d049ff5d16014e0dd24d969956ebd17698
5
5
  SHA512:
6
- metadata.gz: 444af6b66b4dc964b254767c1f8fed67219e7e0d7e8504318700d50f3cca7e2cba367b32a75c871b36b1089a65af016322522086b6d0a197658f34b70f175520
7
- data.tar.gz: 873eb62634fb24e2a904225ceb730e1349c8f216a475e530601b1724d7bc35ad08c6e34b9ef3afe38f5cfb8dabcb64bbaab74a04dbae75e7d8f323c6f40652c8
6
+ metadata.gz: 225051ea9c406954d3f32561b07666e4aa47f1c23a7a770d167d465b42273e1c0d95bbf92439cdb423a1ec183cfdcbbe87fe76ee8668ee55e7bc3f90d0099297
7
+ data.tar.gz: 2e26cc837bf2672bf114fa0a5538e6453060a6e3c9b3363a7c815a867f3efd479eca2f35e42f2cf6e0ee24b93083eff07196ac8b296524d6fe315b18ae6ebd86
data/README.md CHANGED
@@ -1,3 +1,119 @@
1
1
  # puppet_metadata
2
2
 
3
+ [![License](https://img.shields.io/github/license/voxpupuli/puppet_metadata.svg)](https://github.com/voxpupuli/puppet_metadata/blob/master/LICENSE)
4
+ [![Test](https://github.com/voxpupuli/puppet_metadata/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet_metadata/actions/workflows/test.yml)
5
+ [![codecov](https://codecov.io/gh/voxpupuli/puppet_metadata/branch/master/graph/badge.svg?token=Mypkl78hvK)](https://codecov.io/gh/voxpupuli/puppet_metadata)
6
+ [![Release](https://github.com/voxpupuli/puppet_metadata/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet_metadata/actions/workflows/release.yml)
7
+ [![RubyGem Version](https://img.shields.io/gem/v/puppet_metadata.svg)](https://rubygems.org/gems/puppet_metadata)
8
+ [![RubyGem Downloads](https://img.shields.io/gem/dt/puppet_metadata.svg)](https://rubygems.org/gems/puppet_metadata)
9
+ [![Donated by Ewoud Kohl van Wijngaarden](https://img.shields.io/badge/donated%20by-Ewoud%20Kohl%20van%20Wijngaarden-fb7047.svg)](#copyright)
10
+
3
11
  The gem intends to provide an abstraction over Puppet's metadata.json file. Its API allow easy iteration over its illogical data structures.
12
+
13
+ ## Generating Github Actions outputs
14
+
15
+ To get outputs [usable in Github Actions](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions), there is the `metadata2gha` command available. This generates based on metadata.json, such as [Beaker](https://github.com/voxpupuli/beaker) setfiles, Puppet major versions and a Puppet unit test matrix.
16
+
17
+ ```console
18
+ $ metadata2gha-beaker
19
+ ::set-output name=beaker_setfiles::[{"name":"CentOS 7","value":"centos7-64"},{"name":"CentOS 8","value":"centos8-64"},{"name":"Debian 10","value":"debian10-64"},{"name":"Ubuntu 18.04","value":"ubuntu1804-64"}]
20
+ ::set-output name=puppet_major_versions::[{"name":"Puppet 6","value":6,"collection":"puppet6"},{"name":"Puppet 5","value":5,"collection":"puppet5"}]
21
+ ::set-output name=puppet_unit_test_matrix::[{"puppet":6,"ruby":"2.5"},{"puppet":5,"ruby":"2.4"}]
22
+ ```
23
+
24
+ Beaker setfiles formatted for readability:
25
+ ```json
26
+ [
27
+ {
28
+ "name": "CentOS 7",
29
+ "value": "centos7-64"
30
+ },
31
+ {
32
+ "name": "CentOS 8",
33
+ "value": "centos8-64"
34
+ },
35
+ {
36
+ "name": "Debian 10",
37
+ "value": "debian10-64"
38
+ },
39
+ {
40
+ "name": "Ubuntu 18.04",
41
+ "value": "ubuntu1804-64"
42
+ }
43
+ ]
44
+ ```
45
+
46
+ Puppet major versions formatted for readability:
47
+ ```json
48
+ [
49
+ {
50
+ "name": "Puppet 6",
51
+ "value": 6,
52
+ "collection": "puppet6"
53
+ },
54
+ {
55
+ "name": "Puppet 5",
56
+ "value": 5,
57
+ "collection": "puppet5"
58
+ }
59
+ ]
60
+ ```
61
+
62
+ Puppet unit test matrix formatted for readability:
63
+ ```json
64
+ [
65
+ {
66
+ "puppet": 6,
67
+ "ruby": "2.5"
68
+ },
69
+ {
70
+ "puppet": 5,
71
+ "ruby": "2.4"
72
+ }
73
+ ]
74
+ ```
75
+
76
+ It is also possible to specify the path to metadata.json and customize the setfiles. For example, to ensure the setfiles use FQDNs and apply the [systemd PIDFile workaround under docker](https://github.com/docker/for-linux/issues/835). This either means either using an older image (CentOS 7, Ubuntu 16.04) or skipping (CentOS 8).
77
+
78
+ ```console
79
+ $ metadata2gha --use-fqdn --pidfile-workaround true /path/to/metadata.json
80
+ ```
81
+
82
+ This results in the following JSON data
83
+ ```json
84
+ [
85
+ {
86
+ "name": "CentOS 7",
87
+ "value": "centos7-64{hostname=centos7-64.example.com,image=centos:7.6.1810}"
88
+ },
89
+ {
90
+ "name": "Debian 10",
91
+ "value": "debian10-64{hostname=debian10-64.example.com}"
92
+ },
93
+ {
94
+ "name": "Ubuntu 18.04",
95
+ "value": "ubuntu1804-64{hostname=ubuntu1804-64.example.com}"
96
+ }
97
+ ]
98
+ ```
99
+
100
+ It is also possible to specify a comma separated list of operating systems as used in `metadata.json` (`CentOS,Ubuntu`).
101
+
102
+ ## Transfer Notice
103
+
104
+ This plugin was originally authored by [Ewoud Kohl van Wijngaarden](https://github.com/ekohl).
105
+ The maintainer preferred that [Vox Pupuli](https://voxpupuli.org/) take ownership of the module for future improvement and maintenance.
106
+ Existing pull requests and issues were transferred, please fork and continue to contribute [here](https://github.com/voxpupuli/puppet_metadata).
107
+
108
+ ## License
109
+
110
+ This gem is licensed under the Apache-2 license.
111
+
112
+ ## Release information
113
+
114
+ To make a new release, please do:
115
+ * Update the version in the puppet_metadata.gemspec file
116
+ * Install gems with `bundle install --with release --path .vendor`
117
+ * generate the changelog with `bundle exec rake changelog`
118
+ * Create a PR with it
119
+ * After it got merged, push a tag. A github workflow will do the actual release
data/bin/metadata2gha ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'json'
4
+ require 'puppet_metadata'
5
+
6
+ PidfileWorkaround = Object.new
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.accept(PidfileWorkaround) do |value|
11
+ case value
12
+ when 'true'
13
+ true
14
+ when 'false'
15
+ false
16
+ else
17
+ value.split(',')
18
+ end
19
+ end
20
+
21
+ opts.banner = "Usage: #{$0} [options] metadata"
22
+
23
+ opts.on("--[no-]use-fqdn", "Generate beaker setfiles with a FQDN")
24
+ opts.on("--pidfile-workaround VALUE", "Generate the systemd PIDFile workaround to work around a docker bug", PidfileWorkaround)
25
+ end.parse!(into: options)
26
+
27
+ filename = ARGV[0]
28
+ if filename.nil? || filename.empty?
29
+ filename = 'metadata.json'
30
+ end
31
+
32
+ begin
33
+ metadata = PuppetMetadata.read(filename)
34
+ rescue StandardError => e
35
+ STDERR.puts "Failed to read #{filename}: #{e}"
36
+ exit 2
37
+ end
38
+
39
+ metadata.github_actions.outputs(beaker_use_fqdn: options[:'use-fqdn'], beaker_pidfile_workaround: options[:'pidfile-workaround']).each do |name, value|
40
+ puts "::set-output name=#{name}::#{value.to_json}"
41
+ end
@@ -1,6 +1,8 @@
1
1
  # A module that provides abstractions around Puppet's metadata format.
2
2
  module PuppetMetadata
3
+ autoload :AIO, 'puppet_metadata/aio'
3
4
  autoload :Beaker, 'puppet_metadata/beaker'
5
+ autoload :GithubActions, 'puppet_metadata/github_actions'
4
6
  autoload :Metadata, 'puppet_metadata/metadata'
5
7
  autoload :OperatingSystem, 'puppet_metadata/operatingsystem'
6
8
 
@@ -0,0 +1,59 @@
1
+ module PuppetMetadata
2
+ class AIO
3
+ COMPATIBLE = {
4
+ 'AlmaLinux' => 'RedHat',
5
+ 'Amazon' => 'RedHat',
6
+ 'CentOS' => 'RedHat',
7
+ 'OracleLinux' => 'RedHat',
8
+ 'Rocky' => 'RedHat',
9
+ 'Scientific' => 'RedHat',
10
+ }
11
+
12
+ BUILDS = {
13
+ # RPM-based
14
+ 'RedHat' => {
15
+ '5' => 5..7,
16
+ '6' => 5..7,
17
+ '7' => 5..7,
18
+ '8' => 5..7,
19
+ },
20
+ 'Fedora' => {
21
+ '26' => [5],
22
+ '27' => 5..6,
23
+ '28' => 5..6,
24
+ '29' => 5..6,
25
+ '30' => 5..7,
26
+ '31' => 5..7,
27
+ '32' => 6..7,
28
+ '34' => 6..7,
29
+ },
30
+ 'SLES' => {
31
+ '11' => [7],
32
+ '12' => [7],
33
+ '15' => [7],
34
+ },
35
+ # deb-based
36
+ 'Debian' => {
37
+ '7' => [5],
38
+ '8' => 5..7,
39
+ '9' => 5..7,
40
+ '10' => 5..7,
41
+ '11' => 6..7,
42
+ },
43
+ 'Ubuntu' => {
44
+ '14.04' => 5..6,
45
+ '16.04' => 5..7,
46
+ '18.04' => 5..7,
47
+ '20.04' => 6..7,
48
+ },
49
+ }
50
+
51
+ def self.find_base_os(os)
52
+ COMPATIBLE.fetch(os, os)
53
+ end
54
+
55
+ def self.has_aio_build?(os, release, puppet_version)
56
+ BUILDS.dig(find_base_os(os), release)&.include?(puppet_version)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,94 @@
1
+ module PuppetMetadata
2
+ class GithubActions
3
+ attr_reader :metadata
4
+
5
+ # @param [PuppetMetadata::Metadata] metadata
6
+ def initialize(metadata)
7
+ @metadata = metadata
8
+ end
9
+
10
+ # @return [Hash[Symbol, Any]] The outputs for Github Actions
11
+ def outputs(beaker_use_fqdn: false, beaker_pidfile_workaround: false)
12
+ {
13
+ beaker_setfiles: beaker_setfiles(beaker_use_fqdn, beaker_pidfile_workaround),
14
+ puppet_major_versions: puppet_major_versions,
15
+ puppet_unit_test_matrix: puppet_unit_test_matrix,
16
+ github_action_test_matrix: github_action_test_matrix,
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def beaker_setfiles(use_fqdn, pidfile_workaround)
23
+ setfiles = []
24
+ metadata.beaker_setfiles(use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround) do |setfile, name|
25
+ setfiles << {
26
+ name: name,
27
+ value: setfile,
28
+ }
29
+ end
30
+ setfiles
31
+ end
32
+
33
+ def puppet_major_versions
34
+ metadata.puppet_major_versions.sort.reverse.map do |version|
35
+ {
36
+ name: "Puppet #{version}",
37
+ value: version,
38
+ collection: "puppet#{version}",
39
+ }
40
+ end
41
+ end
42
+
43
+ def puppet_unit_test_matrix
44
+ metadata.puppet_major_versions.sort.reverse.map do |puppet|
45
+ ruby = puppet_ruby_version(puppet)
46
+ next unless ruby
47
+
48
+ {
49
+ puppet: puppet,
50
+ ruby: ruby,
51
+ }
52
+ end.compact
53
+ end
54
+
55
+ def puppet_ruby_version(puppet_version)
56
+ case puppet_version
57
+ when 4
58
+ '2.1'
59
+ when 5
60
+ '2.4'
61
+ when 6
62
+ '2.5'
63
+ when 7
64
+ '2.7'
65
+ end
66
+ end
67
+
68
+
69
+ def github_action_test_matrix(use_fqdn: false, pidfile_workaround: false)
70
+ matrix_include = []
71
+
72
+ metadata.operatingsystems.each do |os, releases|
73
+ releases&.each do |release|
74
+ puppet_major_versions.each do |puppet_version|
75
+ next unless AIO.has_aio_build?(os, release, puppet_version[:value])
76
+
77
+ setfile = PuppetMetadata::Beaker.os_release_to_setfile(os, release, use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround)
78
+ next unless setfile
79
+
80
+ matrix_include << {
81
+ setfile: {
82
+ name: setfile[1],
83
+ value: setfile[0],
84
+ },
85
+ puppet: puppet_version
86
+ }
87
+ end
88
+ end
89
+ end
90
+
91
+ matrix_include
92
+ end
93
+ end
94
+ end
@@ -135,6 +135,21 @@ module PuppetMetadata
135
135
  matches?(requirements[name], version)
136
136
  end
137
137
 
138
+ # @return [Array[Integer]] Supported major Puppet versions
139
+ # @see #requirements
140
+ def puppet_major_versions
141
+ requirement = requirements['puppet']
142
+ raise Exception, 'No Puppet requirement found' unless requirement
143
+
144
+ # Current latest major is 7. It is highly recommended that modules
145
+ # actually specify exact bounds, but this prevents an infinite loop.
146
+ end_major = requirement.end == SemanticPuppet::Version::MAX ? 7 : requirement.end.major
147
+
148
+ (requirement.begin.major..end_major).select do |major|
149
+ requirement.include?(SemanticPuppet::Version.new(major, 0, 0)) || requirement.include?(SemanticPuppet::Version.new(major, 99, 99))
150
+ end
151
+ end
152
+
138
153
  # A hash representation of the dependencies
139
154
  #
140
155
  # Every element in the original array is converted. The name is used as a
@@ -167,6 +182,11 @@ module PuppetMetadata
167
182
  matches?(dependencies[name], version)
168
183
  end
169
184
 
185
+ # @return [PuppetMetadata::GithubActions] A GithubActions instance
186
+ def github_actions
187
+ PuppetMetadata::GithubActions.new(self)
188
+ end
189
+
170
190
  # @param [Boolean] use_fqdn
171
191
  # Whether to set the hostname to a fully qualified domain name
172
192
  # @param [Boolean] pidfile_workaround
@@ -22,9 +22,10 @@ module PuppetMetadata
22
22
  # https://wiki.debian.org/DebianReleases
23
23
  'Debian' => {
24
24
  # TODO: EOL is standard support, not the extended life cycle
25
+ '11' => nil, # '~2024',
25
26
  '10' => nil, # '~2022',
26
- '9' => nil, # '~2020',
27
- '8' => '2018-06-06',
27
+ '9' => '2020-07-06',
28
+ '8' => '2018-06-17',
28
29
  '7' => '2016-04-26',
29
30
  '6' => '2015-05-31',
30
31
  '5' => '2012-02-06',
metadata CHANGED
@@ -1,30 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  - Ewoud Kohl van Wijngaarden
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-05 00:00:00.000000000 Z
12
+ date: 2021-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metadata-json-lint
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '2.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '4'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
30
  version: '2.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: semantic_puppet
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -112,21 +118,25 @@ dependencies:
112
118
  description: A package that provides abstractions for the Puppet Metadata
113
119
  email:
114
120
  - voxpupuli@groups.io
115
- executables: []
121
+ executables:
122
+ - metadata2gha
116
123
  extensions: []
117
124
  extra_rdoc_files:
118
125
  - README.md
119
126
  files:
120
127
  - README.md
128
+ - bin/metadata2gha
121
129
  - lib/puppet_metadata.rb
130
+ - lib/puppet_metadata/aio.rb
122
131
  - lib/puppet_metadata/beaker.rb
132
+ - lib/puppet_metadata/github_actions.rb
123
133
  - lib/puppet_metadata/metadata.rb
124
134
  - lib/puppet_metadata/operatingsystem.rb
125
135
  homepage: http://github.com/voxpupuli/puppet_metadata
126
136
  licenses:
127
137
  - Apache-2.0
128
138
  metadata: {}
129
- post_install_message:
139
+ post_install_message:
130
140
  rdoc_options:
131
141
  - "--main"
132
142
  - README.md
@@ -143,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
153
  - !ruby/object:Gem::Version
144
154
  version: '0'
145
155
  requirements: []
146
- rubygems_version: 3.1.4
147
- signing_key:
156
+ rubygems_version: 3.2.22
157
+ signing_key:
148
158
  specification_version: 4
149
159
  summary: Data structures for the Puppet Metadata
150
160
  test_files: []