puppet_metadata 0.2.0 → 0.3.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: 98140c70afa012445fc26f6db9b1f6f2a5b1fb58660d2d9c450c4f93bafc9b6d
4
+ data.tar.gz: 1078ef0d2c8d722ad76f2a9aae5160182ccbc50169a95e45989a48eadbc5abbc
5
5
  SHA512:
6
- metadata.gz: 444af6b66b4dc964b254767c1f8fed67219e7e0d7e8504318700d50f3cca7e2cba367b32a75c871b36b1089a65af016322522086b6d0a197658f34b70f175520
7
- data.tar.gz: 873eb62634fb24e2a904225ceb730e1349c8f216a475e530601b1724d7bc35ad08c6e34b9ef3afe38f5cfb8dabcb64bbaab74a04dbae75e7d8f323c6f40652c8
6
+ metadata.gz: 6382308409c4cf5043b0296ecef6242a1ff71a9e1682bdcb31906214dacc367c128f72ff2fb431dcb8d431b89f5a0123358c9e4e8319ea95c8359e26ce6b8141
7
+ data.tar.gz: cbef56666c77918ab1789ebe89bebaa54eb8fdde34c993ae82cb53bcd426154f252b12ff58c0efbfb695bc8f47a33066506615a147679f20df1a73705469fc47
data/README.md CHANGED
@@ -1,3 +1,92 @@
1
1
  # puppet_metadata
2
2
 
3
3
  The gem intends to provide an abstraction over Puppet's metadata.json file. Its API allow easy iteration over its illogical data structures.
4
+
5
+ ## Generating Github Actions outputs
6
+
7
+ 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.
8
+
9
+ ```console
10
+ $ metadata2gha-beaker
11
+ ::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"}]
12
+ ::set-output name=puppet_major_versions::[{"name":"Puppet 6","value":6,"collection":"puppet6"},{"name":"Puppet 5","value":5,"collection":"puppet5"}]
13
+ ::set-output name=puppet_unit_test_matrix::[{"puppet":6,"ruby":"2.5"},{"puppet":5,"ruby":"2.4"}]
14
+ ```
15
+
16
+ Beaker setfiles formatted for readability:
17
+ ```json
18
+ [
19
+ {
20
+ "name": "CentOS 7",
21
+ "value": "centos7-64"
22
+ },
23
+ {
24
+ "name": "CentOS 8",
25
+ "value": "centos8-64"
26
+ },
27
+ {
28
+ "name": "Debian 10",
29
+ "value": "debian10-64"
30
+ },
31
+ {
32
+ "name": "Ubuntu 18.04",
33
+ "value": "ubuntu1804-64"
34
+ }
35
+ ]
36
+ ```
37
+
38
+ Puppet major versions formatted for readability:
39
+ ```json
40
+ [
41
+ {
42
+ "name": "Puppet 6",
43
+ "value": 6,
44
+ "collection": "puppet6"
45
+ },
46
+ {
47
+ "name": "Puppet 5",
48
+ "value": 5,
49
+ "collection": "puppet5"
50
+ }
51
+ ]
52
+ ```
53
+
54
+ Puppet unit test matrix formatted for readability:
55
+ ```json
56
+ [
57
+ {
58
+ "puppet": 6,
59
+ "ruby": "2.5"
60
+ },
61
+ {
62
+ "puppet": 5,
63
+ "ruby": "2.4"
64
+ }
65
+ ]
66
+ ```
67
+
68
+ 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).
69
+
70
+ ```console
71
+ $ metadata2gha --use-fqdn --pidfile-workaround true /path/to/metadata.json
72
+ ```
73
+
74
+ This results in the following JSON data
75
+ ```json
76
+ [
77
+ {
78
+ "name": "CentOS 7",
79
+ "value": "centos7-64{hostname=centos7-64.example.com,image=centos:7.6.1810}"
80
+ },
81
+ {
82
+ "name": "Debian 10",
83
+ "value": "debian10-64{hostname=debian10-64.example.com}"
84
+ },
85
+ {
86
+ "name": "Ubuntu 18.04",
87
+ "value": "ubuntu1804-64{hostname=ubuntu1804-64.example.com}"
88
+ }
89
+ ]
90
+ ```
91
+
92
+ It is also possible to specify a comma separated list of operating systems as used in `metadata.json` (`CentOS,Ubuntu`).
@@ -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,7 @@
1
1
  # A module that provides abstractions around Puppet's metadata format.
2
2
  module PuppetMetadata
3
3
  autoload :Beaker, 'puppet_metadata/beaker'
4
+ autoload :GithubActions, 'puppet_metadata/github_actions'
4
5
  autoload :Metadata, 'puppet_metadata/metadata'
5
6
  autoload :OperatingSystem, 'puppet_metadata/operatingsystem'
6
7
 
@@ -0,0 +1,67 @@
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
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def beaker_setfiles(use_fqdn, pidfile_workaround)
22
+ setfiles = []
23
+ metadata.beaker_setfiles(use_fqdn: use_fqdn, pidfile_workaround: pidfile_workaround) do |setfile, name|
24
+ setfiles << {
25
+ name: name,
26
+ value: setfile,
27
+ }
28
+ end
29
+ setfiles
30
+ end
31
+
32
+ def puppet_major_versions
33
+ metadata.puppet_major_versions.sort.reverse.map do |version|
34
+ {
35
+ name: "Puppet #{version}",
36
+ value: version,
37
+ collection: "puppet#{version}",
38
+ }
39
+ end
40
+ end
41
+
42
+ def puppet_unit_test_matrix
43
+ metadata.puppet_major_versions.sort.reverse.map do |puppet|
44
+ ruby = puppet_ruby_version(puppet)
45
+ next unless ruby
46
+
47
+ {
48
+ puppet: puppet,
49
+ ruby: ruby,
50
+ }
51
+ end.compact
52
+ end
53
+
54
+ def puppet_ruby_version(puppet_version)
55
+ case puppet_version
56
+ when 4
57
+ '2.1'
58
+ when 5
59
+ '2.4'
60
+ when 6
61
+ '2.5'
62
+ when 7
63
+ '2.7'
64
+ end
65
+ end
66
+ end
67
+ end
@@ -135,6 +135,17 @@ 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
+ (requirement.begin.major..requirement.end.major).select do |major|
145
+ requirement.include?(SemanticPuppet::Version.new(major, 0, 0)) || requirement.include?(SemanticPuppet::Version.new(major, 99, 99))
146
+ end
147
+ end
148
+
138
149
  # A hash representation of the dependencies
139
150
  #
140
151
  # Every element in the original array is converted. The name is used as a
@@ -167,6 +178,11 @@ module PuppetMetadata
167
178
  matches?(dependencies[name], version)
168
179
  end
169
180
 
181
+ # @return [PuppetMetadata::GithubActions] A GithubActions instance
182
+ def github_actions
183
+ PuppetMetadata::GithubActions.new(self)
184
+ end
185
+
170
186
  # @param [Boolean] use_fqdn
171
187
  # Whether to set the hostname to a fully qualified domain name
172
188
  # @param [Boolean] pidfile_workaround
metadata CHANGED
@@ -1,7 +1,7 @@
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: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-05 00:00:00.000000000 Z
12
+ date: 2020-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metadata-json-lint
@@ -112,14 +112,17 @@ dependencies:
112
112
  description: A package that provides abstractions for the Puppet Metadata
113
113
  email:
114
114
  - voxpupuli@groups.io
115
- executables: []
115
+ executables:
116
+ - metadata2gha
116
117
  extensions: []
117
118
  extra_rdoc_files:
118
119
  - README.md
119
120
  files:
120
121
  - README.md
122
+ - bin/metadata2gha
121
123
  - lib/puppet_metadata.rb
122
124
  - lib/puppet_metadata/beaker.rb
125
+ - lib/puppet_metadata/github_actions.rb
123
126
  - lib/puppet_metadata/metadata.rb
124
127
  - lib/puppet_metadata/operatingsystem.rb
125
128
  homepage: http://github.com/voxpupuli/puppet_metadata