modulesync 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/CHANGELOG.md +16 -0
- data/Gemfile +2 -0
- data/features/step_definitions/git_steps.rb +23 -0
- data/features/update.feature +73 -1
- data/lib/modulesync.rb +7 -4
- data/lib/modulesync/cli.rb +7 -2
- data/lib/modulesync/git.rb +24 -7
- data/lib/monkey_patches.rb +15 -0
- data/modulesync.gemspec +1 -1
- data/spec/unit/modulesync_spec.rb +14 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba3647204bfcc8853cafeddbf1e4f1083ceaade7fb1806bd06b36e37d6d593e
|
4
|
+
data.tar.gz: ce4305980ed768ffd80580c4618c7d921e0c7c6e17b57edc3dae0c10eacbeef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cfda65f2a020913fa4cd928e22daac9e5c141f7881afaed928b28af846fe86466fff64314e89b04b9d3cb32bf8e4387ec0410e7142215ac5e0412b15c845d62
|
7
|
+
data.tar.gz: 083fdbb949ce978be0958f3ac2baa8390d38d7221c846b934b5b2e3e49cc60992d662b0afd8322d4efeb3bbec9643faf73b7cba95ba3f91d388953365837494a
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2018-02-15
|
4
|
+
|
5
|
+
## Summary
|
6
|
+
|
7
|
+
This is an awesome release - Now honors the repo default branch[#142](https://github.com/voxpupuli/modulesync/pull/142)
|
8
|
+
|
9
|
+
### Bugfixes
|
10
|
+
|
11
|
+
* Monkey patch ls_files until ruby-git/ruby-git#320 is resolved
|
12
|
+
* Reraise exception rather than exit so we can rescue a derived StandardError when using skip_broken option
|
13
|
+
|
14
|
+
### Enhancements
|
15
|
+
|
16
|
+
* Add new option to produce a failure exit code on warnings
|
17
|
+
* Remove hard coding of managed_modules.yml which means that options passed to ModuleSync.update can override the filename
|
18
|
+
|
3
19
|
## 2017-11-03 - 0.8.2
|
4
20
|
|
5
21
|
### Summary
|
data/Gemfile
CHANGED
@@ -22,3 +22,26 @@ Given 'a remote module repository' do
|
|
22
22
|
git_base: file://#{expand_path('.')}/
|
23
23
|
CONFIG
|
24
24
|
end
|
25
|
+
|
26
|
+
Given /a remote module repository with "(.+?)" as the default branch/ do |branch| # rubocop:disable Lint/AmbiguousRegexpLiteral
|
27
|
+
steps %(
|
28
|
+
Given a directory named "sources"
|
29
|
+
And I run `git clone --mirror https://github.com/maestrodev/puppet-test sources/puppet-test`
|
30
|
+
And a file named "managed_modules.yml" with:
|
31
|
+
"""
|
32
|
+
---
|
33
|
+
- puppet-test
|
34
|
+
"""
|
35
|
+
)
|
36
|
+
write_file('modulesync.yml', <<-CONFIG)
|
37
|
+
---
|
38
|
+
namespace: sources
|
39
|
+
git_base: file://#{expand_path('.')}/
|
40
|
+
CONFIG
|
41
|
+
cd('sources/puppet-test') do
|
42
|
+
steps %(
|
43
|
+
And I run `git branch -M master #{branch}`
|
44
|
+
And I run `git symbolic-ref HEAD refs/heads/#{branch}`
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
data/features/update.feature
CHANGED
@@ -34,6 +34,32 @@ Feature: update
|
|
34
34
|
Given I run `cat modules/puppet-test/test`
|
35
35
|
Then the output should contain "aruba"
|
36
36
|
|
37
|
+
Scenario: Using skip_broken option and adding a new file to repo without write access
|
38
|
+
Given a file named "managed_modules.yml" with:
|
39
|
+
"""
|
40
|
+
---
|
41
|
+
- puppet-test
|
42
|
+
"""
|
43
|
+
And a file named "modulesync.yml" with:
|
44
|
+
"""
|
45
|
+
---
|
46
|
+
namespace: maestrodev
|
47
|
+
git_base: 'git@github.com:'
|
48
|
+
"""
|
49
|
+
And a file named "config_defaults.yml" with:
|
50
|
+
"""
|
51
|
+
---
|
52
|
+
test:
|
53
|
+
name: aruba
|
54
|
+
"""
|
55
|
+
And a directory named "moduleroot"
|
56
|
+
And a file named "moduleroot/test.erb" with:
|
57
|
+
"""
|
58
|
+
<%= @configs['name'] %>
|
59
|
+
"""
|
60
|
+
When I run `msync update -s -m "Add test"`
|
61
|
+
Then the exit status should be 0
|
62
|
+
|
37
63
|
Scenario: Adding a new file to repo without write access
|
38
64
|
Given a file named "managed_modules.yml" with:
|
39
65
|
"""
|
@@ -44,7 +70,7 @@ Feature: update
|
|
44
70
|
"""
|
45
71
|
---
|
46
72
|
namespace: maestrodev
|
47
|
-
git_base: git@github.com:
|
73
|
+
git_base: 'git@github.com:'
|
48
74
|
"""
|
49
75
|
And a file named "config_defaults.yml" with:
|
50
76
|
"""
|
@@ -258,6 +284,34 @@ Feature: update
|
|
258
284
|
When I run `msync update --noop -s`
|
259
285
|
Then the exit status should be 0
|
260
286
|
|
287
|
+
Scenario: Using skip_broken and fail_on_warnings options with invalid files
|
288
|
+
Given a file named "managed_modules.yml" with:
|
289
|
+
"""
|
290
|
+
---
|
291
|
+
- puppet-test
|
292
|
+
"""
|
293
|
+
And a file named "modulesync.yml" with:
|
294
|
+
"""
|
295
|
+
---
|
296
|
+
namespace: maestrodev
|
297
|
+
git_base: https://github.com/
|
298
|
+
"""
|
299
|
+
And a file named "config_defaults.yml" with:
|
300
|
+
"""
|
301
|
+
---
|
302
|
+
test:
|
303
|
+
name: aruba
|
304
|
+
"""
|
305
|
+
And a directory named "moduleroot"
|
306
|
+
And a file named "moduleroot/test.erb" with:
|
307
|
+
"""
|
308
|
+
<% @configs.each do |c| -%>
|
309
|
+
<%= c['name'] %>
|
310
|
+
<% end %>
|
311
|
+
"""
|
312
|
+
When I run `msync update --noop --skip_broken --fail_on_warnings`
|
313
|
+
Then the exit status should be 1
|
314
|
+
|
261
315
|
Scenario: Modifying an existing file
|
262
316
|
Given a file named "managed_modules.yml" with:
|
263
317
|
"""
|
@@ -831,3 +885,21 @@ Feature: update
|
|
831
885
|
Then the exit status should be 0
|
832
886
|
Then the output should not contain "error"
|
833
887
|
Then the output should not contain "rejected"
|
888
|
+
|
889
|
+
Scenario: Repository with a default branch other than master
|
890
|
+
Given a mocked git configuration
|
891
|
+
And a remote module repository with "develop" as the default branch
|
892
|
+
And a file named "config_defaults.yml" with:
|
893
|
+
"""
|
894
|
+
---
|
895
|
+
Gemfile:
|
896
|
+
gem_source: https://somehost.com
|
897
|
+
"""
|
898
|
+
And a directory named "moduleroot"
|
899
|
+
And a file named "moduleroot/Gemfile.erb" with:
|
900
|
+
"""
|
901
|
+
source '<%= @configs['gem_source'] %>'
|
902
|
+
"""
|
903
|
+
When I run `msync update -m "Update Gemfile"`
|
904
|
+
Then the exit status should be 0
|
905
|
+
Then the output should contain "Using repository's default branch: develop"
|
data/lib/modulesync.rb
CHANGED
@@ -43,10 +43,10 @@ module ModuleSync
|
|
43
43
|
local_files.map { |file| file.sub(/#{path}/, '') }
|
44
44
|
end
|
45
45
|
|
46
|
-
def self.managed_modules(
|
47
|
-
managed_modules = Util.parse_config(
|
46
|
+
def self.managed_modules(config_file, filter, negative_filter)
|
47
|
+
managed_modules = Util.parse_config(config_file)
|
48
48
|
if managed_modules.empty?
|
49
|
-
puts "No modules found
|
49
|
+
puts "No modules found in #{config_file}. Check that you specified the right :configs directory and :managed_modules_conf file."
|
50
50
|
exit
|
51
51
|
end
|
52
52
|
managed_modules.select! { |m| m =~ Regexp.new(filter) } unless filter.nil?
|
@@ -126,8 +126,9 @@ module ModuleSync
|
|
126
126
|
local_files = self.local_files(path)
|
127
127
|
module_files = self.module_files(local_files, path)
|
128
128
|
|
129
|
-
managed_modules = self.managed_modules("#{options[:configs]}
|
129
|
+
managed_modules = self.managed_modules("#{options[:configs]}/#{options[:managed_modules_conf]}", options[:filter], options[:negative_filter])
|
130
130
|
|
131
|
+
errors = false
|
131
132
|
# managed_modules is either an array or a hash
|
132
133
|
managed_modules.each do |puppet_module, module_options|
|
133
134
|
begin
|
@@ -135,8 +136,10 @@ module ModuleSync
|
|
135
136
|
rescue # rubocop:disable Lint/RescueWithoutErrorClass
|
136
137
|
STDERR.puts "Error while updating #{puppet_module}"
|
137
138
|
raise unless options[:skip_broken]
|
139
|
+
errors = true
|
138
140
|
puts "Skipping #{puppet_module} as update process failed"
|
139
141
|
end
|
140
142
|
end
|
143
|
+
exit 1 if errors && options[:fail_on_warnings]
|
141
144
|
end
|
142
145
|
end
|
data/lib/modulesync/cli.rb
CHANGED
@@ -53,8 +53,8 @@ module ModuleSync
|
|
53
53
|
:desc => 'A regular expression to skip repositories.'
|
54
54
|
class_option :branch,
|
55
55
|
:aliases => '-b',
|
56
|
-
:desc => 'Branch name to make the changes in. Defaults to master.',
|
57
|
-
:default => CLI.defaults[:branch]
|
56
|
+
:desc => 'Branch name to make the changes in. Defaults to the default branch of the upstream repository, but falls back to "master".',
|
57
|
+
:default => CLI.defaults[:branch]
|
58
58
|
|
59
59
|
desc 'update', 'Update the modules in managed_modules.yml'
|
60
60
|
option :message,
|
@@ -106,6 +106,11 @@ module ModuleSync
|
|
106
106
|
option :pre_commit_script,
|
107
107
|
:desc => 'A script to be run before commiting',
|
108
108
|
:default => CLI.defaults[:pre_commit_script]
|
109
|
+
option :fail_on_warnings,
|
110
|
+
:type => :boolean,
|
111
|
+
:aliases => '-F',
|
112
|
+
:desc => 'Produce a failure exit code when there are warnings (only has effect when --skip_broken is enabled)',
|
113
|
+
:default => false
|
109
114
|
|
110
115
|
def update
|
111
116
|
config = { :command => 'update' }.merge(options)
|
data/lib/modulesync/git.rb
CHANGED
@@ -2,7 +2,7 @@ require 'git'
|
|
2
2
|
require 'puppet_blacksmith'
|
3
3
|
|
4
4
|
module ModuleSync
|
5
|
-
module Git
|
5
|
+
module Git # rubocop:disable Metrics/ModuleLength
|
6
6
|
include Constants
|
7
7
|
|
8
8
|
def self.remote_branch_exists?(repo, branch)
|
@@ -18,7 +18,17 @@ module ModuleSync
|
|
18
18
|
repo.diff("#{local_branch}..origin/#{remote_branch}").any?
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.default_branch(repo)
|
22
|
+
symbolic_ref = repo.branches.find { |b| b.full =~ %r{remotes/origin/HEAD} }
|
23
|
+
return unless symbolic_ref
|
24
|
+
%r{remotes/origin/HEAD\s+->\s+origin/(?<branch>.+?)$}.match(symbolic_ref.full)[:branch]
|
25
|
+
end
|
26
|
+
|
21
27
|
def self.switch_branch(repo, branch)
|
28
|
+
unless branch
|
29
|
+
branch = default_branch(repo)
|
30
|
+
puts "Using repository's default branch: #{branch}"
|
31
|
+
end
|
22
32
|
return if repo.current_branch == branch
|
23
33
|
|
24
34
|
if local_branch_exists?(repo, branch)
|
@@ -95,12 +105,19 @@ module ModuleSync
|
|
95
105
|
repo.push('origin', tag)
|
96
106
|
end
|
97
107
|
|
108
|
+
def self.checkout_branch(repo, branch)
|
109
|
+
selected_branch = branch || repo.current_branch || 'master'
|
110
|
+
repo.branch(selected_branch).checkout
|
111
|
+
selected_branch
|
112
|
+
end
|
113
|
+
private_class_method :checkout_branch
|
114
|
+
|
98
115
|
# Git add/rm, git commit, git push
|
99
116
|
def self.update(name, files, options)
|
100
117
|
module_root = "#{options[:project_root]}/#{name}"
|
101
118
|
message = options[:message]
|
102
119
|
repo = ::Git.open(module_root)
|
103
|
-
|
120
|
+
branch = checkout_branch(repo, options[:branch])
|
104
121
|
files.each do |file|
|
105
122
|
if repo.status.deleted.include?(file)
|
106
123
|
repo.remove(file)
|
@@ -119,11 +136,11 @@ module ModuleSync
|
|
119
136
|
end
|
120
137
|
repo.commit(message, opts_commit)
|
121
138
|
if options[:remote_branch]
|
122
|
-
if remote_branch_differ?(repo,
|
123
|
-
repo.push('origin', "#{
|
139
|
+
if remote_branch_differ?(repo, branch, options[:remote_branch])
|
140
|
+
repo.push('origin', "#{branch}:#{options[:remote_branch]}", opts_push)
|
124
141
|
end
|
125
142
|
else
|
126
|
-
repo.push('origin',
|
143
|
+
repo.push('origin', branch, opts_push)
|
127
144
|
end
|
128
145
|
# Only bump/tag if pushing didn't fail (i.e. there were changes)
|
129
146
|
m = Blacksmith::Modulefile.new("#{module_root}/metadata.json")
|
@@ -136,7 +153,7 @@ module ModuleSync
|
|
136
153
|
puts "There were no files to update in #{name}. Not committing."
|
137
154
|
else
|
138
155
|
puts git_error
|
139
|
-
|
156
|
+
raise
|
140
157
|
end
|
141
158
|
end
|
142
159
|
end
|
@@ -154,7 +171,7 @@ module ModuleSync
|
|
154
171
|
puts "Using no-op. Files in #{name} may be changed but will not be committed."
|
155
172
|
|
156
173
|
repo = ::Git.open("#{options[:project_root]}/#{name}")
|
157
|
-
repo
|
174
|
+
checkout_branch(repo, options[:branch])
|
158
175
|
|
159
176
|
puts 'Files changed:'
|
160
177
|
repo.diff('HEAD', '--').each do |diff|
|
data/lib/monkey_patches.rb
CHANGED
@@ -37,4 +37,19 @@ module Git
|
|
37
37
|
final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
class Lib
|
42
|
+
# Monkey patch ls_files until https://github.com/ruby-git/ruby-git/pull/320 is resolved
|
43
|
+
def ls_files(location=nil)
|
44
|
+
location ||= '.'
|
45
|
+
hsh = {}
|
46
|
+
command_lines('ls-files', ['--stage', location]).each do |line|
|
47
|
+
(info, file) = line.split("\t")
|
48
|
+
(mode, sha, stage) = info.split
|
49
|
+
file = eval(file) if file =~ /^\".*\"$/ # This takes care of quoted strings returned from git
|
50
|
+
hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
|
51
|
+
end
|
52
|
+
hsh
|
53
|
+
end
|
54
|
+
end
|
40
55
|
end
|
data/modulesync.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = 'modulesync'
|
6
|
-
spec.version = '0.
|
6
|
+
spec.version = '0.9.0'
|
7
7
|
spec.authors = ['Vox Pupuli']
|
8
8
|
spec.email = ['voxpupuli@groups.io']
|
9
9
|
spec.summary = 'Puppet Module Synchronizer'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ModuleSync do
|
4
|
+
context '::update' do
|
5
|
+
it 'loads the managed modules from the specified :managed_modules_conf' do
|
6
|
+
allow(ModuleSync).to receive(:local_files).and_return([])
|
7
|
+
allow(ModuleSync::Util).to receive(:parse_config).with('./config_defaults.yml').and_return({})
|
8
|
+
expect(ModuleSync).to receive(:managed_modules).with('./test_file.yml', nil, nil).and_return([])
|
9
|
+
|
10
|
+
options = { managed_modules_conf: 'test_file.yml' }
|
11
|
+
ModuleSync.update(options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modulesync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- modulesync.gemspec
|
160
160
|
- spec/spec_helper.rb
|
161
161
|
- spec/unit/modulesync/settings_spec.rb
|
162
|
+
- spec/unit/modulesync_spec.rb
|
162
163
|
homepage: http://github.com/voxpupuli/modulesync
|
163
164
|
licenses:
|
164
165
|
- Apache-2.0
|
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
180
|
version: '0'
|
180
181
|
requirements: []
|
181
182
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.7.
|
183
|
+
rubygems_version: 2.7.6
|
183
184
|
signing_key:
|
184
185
|
specification_version: 4
|
185
186
|
summary: Puppet Module Synchronizer
|
@@ -191,3 +192,4 @@ test_files:
|
|
191
192
|
- features/update.feature
|
192
193
|
- spec/spec_helper.rb
|
193
194
|
- spec/unit/modulesync/settings_spec.rb
|
195
|
+
- spec/unit/modulesync_spec.rb
|