pdksync 0.2.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +26 -15
- data/.travis.yml +17 -16
- data/CHANGELOG.md +65 -2
- data/CODEOWNERS +2 -0
- data/Gemfile +6 -3
- data/README.md +441 -25
- data/Rakefile +14 -50
- data/lib/pdksync.rb +317 -300
- data/lib/pdksync/conf/puppet_abs_supported_platforms.yaml +41 -0
- data/lib/pdksync/configuration.rb +155 -0
- data/lib/pdksync/githubclient.rb +77 -0
- data/lib/pdksync/gitlabclient.rb +91 -0
- data/lib/pdksync/gitplatformclient.rb +109 -0
- data/lib/pdksync/jenkinsclient.rb +50 -0
- data/lib/pdksync/logger.rb +116 -0
- data/lib/pdksync/pullrequest.rb +35 -0
- data/lib/pdksync/rake_tasks.rb +157 -0
- data/lib/pdksync/utils.rb +1293 -0
- data/managed_modules.yml +24 -28
- data/pdksync.gemspec +21 -16
- data/spec/configuration_spec.rb +56 -0
- data/spec/fixtures/fake_managed_modules.yaml +2 -0
- data/spec/fixtures/pdksync.yml +2 -0
- data/spec/logger_spec.rb +44 -0
- data/spec/pdksync_spec.rb +185 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/utils_spec.rb +131 -0
- metadata +121 -16
- data/lib/pdksync/constants.rb +0 -12
- data/spec/lib/pdksync_spec.rb +0 -54
data/spec/utils_spec.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pdksync/utils'
|
3
|
+
require 'tempfile'
|
4
|
+
describe 'PdkSync::Utils' do
|
5
|
+
before(:all) do
|
6
|
+
@tmp_dir = Dir.mktmpdir('testing')
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:cloned_module) do
|
10
|
+
begin
|
11
|
+
Git.open(@tmp_dir)
|
12
|
+
rescue ArgumentError
|
13
|
+
PdkSync::Utils.clone_directory('puppetlabs',
|
14
|
+
'puppetlabs-testing', @tmp_dir)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:metadata_file) do
|
19
|
+
File.join(@tmp_dir, 'metadata.json')
|
20
|
+
end
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
cloned_module
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:all) do
|
27
|
+
FileUtils.remove_entry @tmp_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
it '#self.clone_directory' do
|
31
|
+
Dir.mktmpdir do |dir|
|
32
|
+
PdkSync::Utils.clone_directory('puppetlabs',
|
33
|
+
'puppetlabs-testing', dir)
|
34
|
+
expect(cloned_module).to be_a Git::Base
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#self.create_commit' do
|
39
|
+
File.write(File.join(@tmp_dir, 'README.md'), rand(32_332))
|
40
|
+
expect(PdkSync::Utils.create_commit(cloned_module, 'main', 'boom')).to match(%r{README})
|
41
|
+
end
|
42
|
+
|
43
|
+
it '#self.run_command' do
|
44
|
+
expect(PdkSync::Utils.run_command('./', 'pwd', nil)).to eq(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it '#self.pdk_update' do
|
48
|
+
expect(PdkSync::Utils.pdk_update(@tmp_dir)).to eq(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it '#self.return_template_ref' do
|
52
|
+
expect(PdkSync::Utils.return_template_ref(metadata_file)).to match(%r{^heads\/main\S+$})
|
53
|
+
end
|
54
|
+
|
55
|
+
it '#self.module_templates_url' do
|
56
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: 'v1.14.1' }])
|
57
|
+
url, version = PdkSync::Utils.module_templates_url(metadata_file).split('#')
|
58
|
+
expect(url).to eq('https://github.com/puppetlabs/pdk-templates')
|
59
|
+
expect(version).to match(%r{main})
|
60
|
+
end
|
61
|
+
|
62
|
+
it '#self.change_module_template_url' do
|
63
|
+
url = 'https://github.com/nwops/pdk-templates'
|
64
|
+
ref = 'special'
|
65
|
+
expect(PdkSync::Utils.change_module_template_url(url, ref, metadata_file)).to eq('https://github.com/nwops/pdk-templates#special')
|
66
|
+
end
|
67
|
+
|
68
|
+
it '#self.checkout_branch' do
|
69
|
+
PdkSync::Utils.checkout_branch(cloned_module, 'sync1234')
|
70
|
+
branch = cloned_module.branches.find { |b| b.name.eql?('pdksync_sync1234') }
|
71
|
+
expect(branch).to be_a Git::Branch
|
72
|
+
end
|
73
|
+
|
74
|
+
it '#self.check_pdk_version is false' do
|
75
|
+
process = double
|
76
|
+
allow(process).to receive(:exitstatus).and_return(true)
|
77
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: 'v1.14.1' }])
|
78
|
+
allow(PdkSync::Utils).to receive(:return_pdk_path).and_return('/opt/puppetlabs/pdk/bin/pdk')
|
79
|
+
allow(Open3).to receive(:capture3).with('/opt/puppetlabs/pdk/bin/pdk --version').and_return(['1.14.0', nil, process])
|
80
|
+
expect(PdkSync::Utils.check_pdk_version).to be false
|
81
|
+
end
|
82
|
+
|
83
|
+
it '#self.check_pdk_version is true' do
|
84
|
+
process = double
|
85
|
+
allow(process).to receive(:exitstatus).and_return(true)
|
86
|
+
allow(PdkSync::Utils).to receive(:return_pdk_path).and_return('/opt/puppetlabs/pdk/bin/pdk')
|
87
|
+
allow(Open3).to receive(:capture3).with('/opt/puppetlabs/pdk/bin/pdk --version').and_return(['1.14.0', nil, process])
|
88
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: 'v1.14.0' }])
|
89
|
+
expect(PdkSync::Utils.check_pdk_version).to be true
|
90
|
+
end
|
91
|
+
|
92
|
+
it '#self.check_gem_latest_version' do
|
93
|
+
process = double
|
94
|
+
allow(process).to receive(:exitstatus).and_return(true)
|
95
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/puppet_module_gems').and_return([{ name: '0.4.0' }])
|
96
|
+
expect(PdkSync::Utils.check_gem_latest_version('puppet_module_gems')).to eq '0.4.0'
|
97
|
+
end
|
98
|
+
|
99
|
+
it '#self.update_gem_latest_version_by_one' do
|
100
|
+
expect(PdkSync::Utils.update_gem_latest_version_by_one('0.4.0')).to eq Gem::Version.new('0.5')
|
101
|
+
end
|
102
|
+
|
103
|
+
it '#self.create_filespace' do
|
104
|
+
expect(PdkSync::Utils.create_filespace).to eq('modules_pdksync')
|
105
|
+
end
|
106
|
+
|
107
|
+
it '#self.setup_client' do
|
108
|
+
g = double(PdkSync::GitPlatformClient)
|
109
|
+
expect(PdkSync::GitPlatformClient).to receive(:new).with(:github,
|
110
|
+
access_token: 'github-token',
|
111
|
+
api_endpoint: nil,
|
112
|
+
gitlab_api_endpoint: 'https://gitlab.com/api/v4').and_return(g)
|
113
|
+
expect(PdkSync::Utils.setup_client).to eq(g)
|
114
|
+
end
|
115
|
+
|
116
|
+
it '#self.return_modules' do
|
117
|
+
allow_any_instance_of(PdkSync::Configuration).to receive(:managed_modules).and_return(File.join(fixtures_dir, 'fake_managed_modules.yaml'))
|
118
|
+
expect(PdkSync::Utils.return_modules).to eq(['puppetlabs/puppetlabs-testing'])
|
119
|
+
end
|
120
|
+
|
121
|
+
it '#self.validate_modules_exist' do
|
122
|
+
client = double
|
123
|
+
allow_any_instance_of(PdkSync::Configuration).to receive(:managed_modules).and_return(File.join(fixtures_dir, 'fake_managed_modules.yaml'))
|
124
|
+
allow(client).to receive(:repository?).with('puppetlabs/puppetlabs-testing').and_return(true)
|
125
|
+
expect(PdkSync::Utils.validate_modules_exist(client, ['puppetlabs-testing'])).to be true
|
126
|
+
end
|
127
|
+
|
128
|
+
it '#self.create_filespace_gem' do
|
129
|
+
expect(PdkSync::Utils.create_filespace_gem).to eq('gems_pdksync')
|
130
|
+
end
|
131
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdksync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,7 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: codecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 0.50.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: simplecov
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: simplecov-console
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pdk
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.14.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.14.1
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: git
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,19 +137,75 @@ dependencies:
|
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '1.3'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: gitlab
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: octokit
|
113
169
|
requirement: !ruby/object:Gem::Requirement
|
114
170
|
requirements:
|
115
171
|
- - ">="
|
116
172
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
173
|
+
version: '0'
|
118
174
|
type: :runtime
|
119
175
|
prerelease: false
|
120
176
|
version_requirements: !ruby/object:Gem::Requirement
|
121
177
|
requirements:
|
122
178
|
- - ">="
|
123
179
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: colorize
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: jenkins_api_client
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
125
209
|
description: Utility to synchronize common files across puppet modules using PDK Update.
|
126
210
|
email:
|
127
211
|
- ''
|
@@ -135,20 +219,36 @@ files:
|
|
135
219
|
- ".rubocop_todo.yml"
|
136
220
|
- ".travis.yml"
|
137
221
|
- CHANGELOG.md
|
222
|
+
- CODEOWNERS
|
138
223
|
- Gemfile
|
139
224
|
- LICENSE
|
140
225
|
- README.md
|
141
226
|
- Rakefile
|
142
227
|
- lib/pdksync.rb
|
143
|
-
- lib/pdksync/
|
228
|
+
- lib/pdksync/conf/puppet_abs_supported_platforms.yaml
|
229
|
+
- lib/pdksync/configuration.rb
|
230
|
+
- lib/pdksync/githubclient.rb
|
231
|
+
- lib/pdksync/gitlabclient.rb
|
232
|
+
- lib/pdksync/gitplatformclient.rb
|
233
|
+
- lib/pdksync/jenkinsclient.rb
|
234
|
+
- lib/pdksync/logger.rb
|
235
|
+
- lib/pdksync/pullrequest.rb
|
236
|
+
- lib/pdksync/rake_tasks.rb
|
237
|
+
- lib/pdksync/utils.rb
|
144
238
|
- managed_modules.yml
|
145
239
|
- pdksync.gemspec
|
146
|
-
- spec/
|
240
|
+
- spec/configuration_spec.rb
|
241
|
+
- spec/fixtures/fake_managed_modules.yaml
|
242
|
+
- spec/fixtures/pdksync.yml
|
243
|
+
- spec/logger_spec.rb
|
244
|
+
- spec/pdksync_spec.rb
|
245
|
+
- spec/spec_helper.rb
|
246
|
+
- spec/utils_spec.rb
|
147
247
|
homepage: http://github.com/puppetlabs/pdksync
|
148
248
|
licenses:
|
149
249
|
- Apache-2.0
|
150
250
|
metadata: {}
|
151
|
-
post_install_message:
|
251
|
+
post_install_message:
|
152
252
|
rdoc_options: []
|
153
253
|
require_paths:
|
154
254
|
- lib
|
@@ -163,10 +263,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
263
|
- !ruby/object:Gem::Version
|
164
264
|
version: '0'
|
165
265
|
requirements: []
|
166
|
-
|
167
|
-
|
168
|
-
signing_key:
|
266
|
+
rubygems_version: 3.1.6
|
267
|
+
signing_key:
|
169
268
|
specification_version: 4
|
170
269
|
summary: Puppet Module PDK Synchronizer
|
171
270
|
test_files:
|
172
|
-
- spec/
|
271
|
+
- spec/configuration_spec.rb
|
272
|
+
- spec/fixtures/fake_managed_modules.yaml
|
273
|
+
- spec/fixtures/pdksync.yml
|
274
|
+
- spec/logger_spec.rb
|
275
|
+
- spec/pdksync_spec.rb
|
276
|
+
- spec/spec_helper.rb
|
277
|
+
- spec/utils_spec.rb
|
data/lib/pdksync/constants.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# @summary
|
2
|
-
# A module used to contain a set of variables that are expected to remain constant across all iterations of the main pdksync module.
|
3
|
-
module PdkSync # rubocop:disable Style/ClassAndModuleChildren
|
4
|
-
module Constants
|
5
|
-
ACCESS_TOKEN = ENV['GITHUB_TOKEN'].freeze
|
6
|
-
NAMESPACE = 'puppetlabs'.freeze
|
7
|
-
PDKSYNC_DIR = 'modules_pdksync'.freeze
|
8
|
-
PUSH_FILE_DESTINATION = 'origin'.freeze
|
9
|
-
CREATE_PR_AGAINST = 'master'.freeze
|
10
|
-
MANAGED_MODULES = 'managed_modules.yml'.freeze
|
11
|
-
end
|
12
|
-
end
|
data/spec/lib/pdksync_spec.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require_relative '../../lib/pdksync'
|
2
|
-
require 'git'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'octokit'
|
5
|
-
|
6
|
-
describe PdkSync do
|
7
|
-
before(:all) do
|
8
|
-
@pdksync_dir = './modules_pdksync'
|
9
|
-
module_name = 'puppetlabs-testing'
|
10
|
-
@module_names = ['puppetlabs-testing']
|
11
|
-
@output_path = "#{@pdksync_dir}/#{module_name}"
|
12
|
-
@folder = Dir.pwd
|
13
|
-
end
|
14
|
-
|
15
|
-
before(:each) do
|
16
|
-
allow(PdkSync).to receive(:return_modules).and_return(@module_names)
|
17
|
-
Dir.chdir(@folder)
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'main method' do
|
21
|
-
it 'runs clone sucessfully' do
|
22
|
-
FileUtils.rm_rf(@pdksync_dir)
|
23
|
-
PdkSync.create_filespace
|
24
|
-
PdkSync.main(steps: [:clone])
|
25
|
-
expect(Dir.exist?(@pdksync_dir)).to be(true)
|
26
|
-
expect(Dir.exist?(@output_path)).to be(true)
|
27
|
-
end
|
28
|
-
it 'runs pdk convert, and files have changed' do
|
29
|
-
PdkSync.main(steps: [:pdk_convert])
|
30
|
-
File.exist?("#{@output_path}/convert_report.txt")
|
31
|
-
end
|
32
|
-
it 'raise when running a command with no argument' do
|
33
|
-
expect { PdkSync.main(steps: [:run_a_command]) }.to raise_error(RuntimeError, %r{"run_a_command" requires an argument to run.})
|
34
|
-
end
|
35
|
-
it 'runs a command "touch cat.meow"' do
|
36
|
-
PdkSync.main(steps: [:run_a_command], args: 'touch cat.meow')
|
37
|
-
expect File.exist?("#{@output_path}/cat.meow")
|
38
|
-
end
|
39
|
-
it 'raise when create_commit with no arguments' do
|
40
|
-
expect { PdkSync.main(steps: [:create_commit]) }.to raise_error(RuntimeError, %r{Needs a branch_name and commit_message})
|
41
|
-
end
|
42
|
-
it 'create_commit runs, and contains the "kittens in mittens"' do
|
43
|
-
PdkSync.main(steps: [:create_commit], args: { branch_name: 'temp_branch', commit_message: 'kittens in mittens' })
|
44
|
-
git_repo = Git.open(@output_path)
|
45
|
-
expect(git_repo.show).to include('kittens in mittens')
|
46
|
-
end
|
47
|
-
it 'raise when push_and_create_pr with no arguments' do
|
48
|
-
expect { PdkSync.main(steps: [:push_and_create_pr]) }.to raise_error(RuntimeError, %r{Needs a pr_title})
|
49
|
-
end
|
50
|
-
it 'raise when clean_branches with no arguments' do
|
51
|
-
expect { PdkSync.main(steps: [:clean_branches]) }.to raise_error(RuntimeError, %r{Needs a branch_name, and the branch name contains the string pdksync})
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|