modulesync 0.7.2 → 0.8.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 +4 -4
- data/.rubocop.yml +6 -2
- data/.travis.yml +5 -3
- data/CHANGELOG.md +20 -0
- data/Gemfile +0 -5
- data/README.md +12 -10
- data/Rakefile +1 -1
- data/features/update.feature +160 -18
- data/lib/modulesync/git.rb +1 -1
- data/lib/modulesync/renderer.rb +13 -7
- data/lib/modulesync/settings.rb +19 -10
- data/lib/modulesync.rb +5 -3
- data/lib/monkey_patches.rb +40 -0
- data/modulesync.gemspec +12 -10
- data/spec/unit/modulesync/settings_spec.rb +2 -2
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68055a15d6cb04e09aa817ca80d02daaa18d871e
|
4
|
+
data.tar.gz: 734cb292972fb267ed1e5139caf970d8a5678d2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eed0ed67ad09ac3a2fe29e7d0acb516c7f07cd6626a9d1390258aa8ca18653f1c8744ed84a1107753855eb7557f52e45404fead5012b198119deb2ef3f5eb8e
|
7
|
+
data.tar.gz: 6530399b6eebe0c779c41995f39a7e4e3d2fab6a562a525b02b05e76ae75a7df885e8822f9b30bfdc2b9ee2c46b15fa4d0ee069012ef9e6773335521887c11d6
|
data/.rubocop.yml
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion:
|
4
|
+
TargetRubyVersion: 2.0
|
5
5
|
Exclude:
|
6
6
|
- 'vendor/**/*'
|
7
7
|
- 'tmp/**/*'
|
8
8
|
- 'pkg/**/*'
|
9
|
+
- 'lib/monkey_patches.rb'
|
9
10
|
|
10
|
-
# we still support ruby 1.8
|
11
11
|
Style/HashSyntax:
|
12
12
|
Enabled: false
|
13
13
|
|
14
14
|
# dealbreaker:
|
15
15
|
Style/TrailingCommaInLiteral:
|
16
16
|
Enabled: false
|
17
|
+
|
18
|
+
# would require external library
|
19
|
+
Style/IndentHeredoc:
|
20
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -2,17 +2,19 @@
|
|
2
2
|
sudo: false
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
|
+
dist: trusty
|
5
6
|
before_install:
|
6
7
|
- gem update --system
|
7
8
|
- gem install bundler
|
8
9
|
script: 'bundle exec rake test'
|
9
10
|
rvm:
|
10
|
-
- 1.9.3
|
11
11
|
- 2.0
|
12
|
-
- 2.1
|
13
|
-
- 2.2
|
12
|
+
- 2.1.9
|
13
|
+
- 2.2.6
|
14
14
|
- 2.3.3
|
15
15
|
- 2.4.0
|
16
|
+
notifications:
|
17
|
+
email: false
|
16
18
|
deploy:
|
17
19
|
provider: rubygems
|
18
20
|
api_key:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2017-05-05 - 0.8.0
|
4
|
+
|
5
|
+
### Summary
|
6
|
+
|
7
|
+
This release now prefers `.erb` suffixes on template files. To convert your moduleroot directory, run this command in your configs repo:
|
8
|
+
|
9
|
+
find moduleroot/ -type f -exec git mv {} {}.erb \;
|
10
|
+
|
11
|
+
Note that any `.erb`-suffixed configuration keys in `config_defaults.yml`, and `.sync.yml` need to be removed by hand. (This was unreleased functionality, will not affect most users.)
|
12
|
+
|
13
|
+
#### Refactoring
|
14
|
+
|
15
|
+
- Prefer `.erb` suffixes on template files, issue deprecation warning for templates without the extension
|
16
|
+
- Require Ruby 2.0 or higher
|
17
|
+
|
18
|
+
#### Bugfixes
|
19
|
+
|
20
|
+
- Fix dependency on `git` gem for diff functionality
|
21
|
+
- Fix error from `git` gem when diff contained line ending changes
|
22
|
+
|
3
23
|
## 2017-02-13 - 0.7.2
|
4
24
|
|
5
25
|
Fixes an issue releasing 0.7.1, no functional changes.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Puppet Labs module engineers manage the zoo of Puppet modules on GitHub, and
|
|
27
27
|
has now been restructured and generalized to be used within other
|
28
28
|
organizations. Puppet modules within an organization tend to have a number of
|
29
29
|
meta-files that are identical or very similar between modules, such as the
|
30
|
-
Gemfile
|
30
|
+
`Gemfile`, `.travis.yml`, `.gitignore`, or `spec\_helper.rb`. If a file needs to
|
31
31
|
change in one module, it likely needs to change in the same way in every other
|
32
32
|
module that the organization manages.
|
33
33
|
|
@@ -60,22 +60,24 @@ of this configuration directory. [The configuration for the Puppet Labs
|
|
60
60
|
modules](https://github.com/puppetlabs/modulesync\_configs), can be used as an
|
61
61
|
example for your own configuration. The configuration directory contains a
|
62
62
|
directory called moduleroot which mirrors the structure of a module. The files
|
63
|
-
in the moduleroot
|
64
|
-
|
63
|
+
in the moduleroot are ERB templates, and MUST be named after the target file,
|
64
|
+
with `.erb.` appended. The templates are
|
65
|
+
rendered using values from a file called `config\_defaults.yml` in the root (not
|
65
66
|
moduleroot) of the configuration directory. The default values can be
|
66
|
-
overridden or extended by adding a file called
|
67
|
+
overridden or extended by adding a file called `.sync.yml` to the module itself.
|
67
68
|
This allows us to, for example, have a set of "required" gems that are added
|
68
69
|
to all Gemfiles, and a set of "optional" gems that a single module might add.
|
69
70
|
|
70
71
|
Within the templates, values can be accessed in the `@configs` hash, which is
|
71
|
-
merged from the values under the keys `:global` and the
|
72
|
+
merged from the values under the keys `:global` and the target file name (no
|
73
|
+
`.erb` suffix).
|
72
74
|
|
73
|
-
The list of modules to manage is in managed\_modules.yml in the configuration
|
75
|
+
The list of modules to manage is in `managed\_modules.yml` in the configuration
|
74
76
|
directory. This lists just the names of the modules to be managed.
|
75
77
|
|
76
78
|
ModuleSync can be called from the command line with parameters to change the
|
77
79
|
branch you're working on or the remote to clone from and push to. You can also
|
78
|
-
define these parameters in a file named modulesync.yml in the configuration
|
80
|
+
define these parameters in a file named `modulesync.yml` in the configuration
|
79
81
|
directory.
|
80
82
|
|
81
83
|
Installing
|
@@ -122,6 +124,7 @@ msync update --noop
|
|
122
124
|
```
|
123
125
|
|
124
126
|
#### Offline support
|
127
|
+
|
125
128
|
The --offline flag was added to allow a user to disable git support within
|
126
129
|
msync. One reason for this is because the user wants to control git commands
|
127
130
|
external to msync. Note, when using this command, msync assumes you have
|
@@ -359,6 +362,5 @@ As commented, files within moduleroot directory can be flat files or ERB templat
|
|
359
362
|
The Templates
|
360
363
|
-------------
|
361
364
|
|
362
|
-
See
|
363
|
-
|
364
|
-
modules.
|
365
|
+
See [Puppet's modulesync\_configs](https://github.com/puppetlabs/modulesync_configs) and [Vox Pupuli's modulesync\_configs](https://github.com/voxpupuli/modulesync_configs)
|
366
|
+
repositories for different templates currently in use.
|
data/Rakefile
CHANGED
data/features/update.feature
CHANGED
@@ -2,6 +2,39 @@ Feature: update
|
|
2
2
|
ModuleSync needs to update module boilerplate
|
3
3
|
|
4
4
|
Scenario: Adding a new file
|
5
|
+
Given a file named "managed_modules.yml" with:
|
6
|
+
"""
|
7
|
+
---
|
8
|
+
- puppet-test
|
9
|
+
"""
|
10
|
+
And a file named "modulesync.yml" with:
|
11
|
+
"""
|
12
|
+
---
|
13
|
+
namespace: maestrodev
|
14
|
+
git_base: https://github.com/
|
15
|
+
"""
|
16
|
+
And a file named "config_defaults.yml" with:
|
17
|
+
"""
|
18
|
+
---
|
19
|
+
test:
|
20
|
+
name: aruba
|
21
|
+
"""
|
22
|
+
And a directory named "moduleroot"
|
23
|
+
And a file named "moduleroot/test.erb" with:
|
24
|
+
"""
|
25
|
+
<%= @configs['name'] %>
|
26
|
+
"""
|
27
|
+
When I run `msync update --noop`
|
28
|
+
Then the exit status should be 0
|
29
|
+
And the output should match:
|
30
|
+
"""
|
31
|
+
Files added:
|
32
|
+
test
|
33
|
+
"""
|
34
|
+
Given I run `cat modules/puppet-test/test`
|
35
|
+
Then the output should contain "aruba"
|
36
|
+
|
37
|
+
Scenario: Adding a new file, without the .erb suffix
|
5
38
|
Given a file named "managed_modules.yml" with:
|
6
39
|
"""
|
7
40
|
---
|
@@ -26,6 +59,115 @@ Feature: update
|
|
26
59
|
"""
|
27
60
|
When I run `msync update --noop`
|
28
61
|
Then the exit status should be 0
|
62
|
+
And the output should match:
|
63
|
+
"""
|
64
|
+
Warning: using './moduleroot//test' as template without '.erb' suffix
|
65
|
+
"""
|
66
|
+
And the output should match:
|
67
|
+
"""
|
68
|
+
Files added:
|
69
|
+
test
|
70
|
+
"""
|
71
|
+
Given I run `cat modules/puppet-test/test`
|
72
|
+
Then the output should contain "aruba"
|
73
|
+
|
74
|
+
Scenario: Adding a new file using global values
|
75
|
+
Given a file named "managed_modules.yml" with:
|
76
|
+
"""
|
77
|
+
---
|
78
|
+
- puppet-test
|
79
|
+
"""
|
80
|
+
And a file named "modulesync.yml" with:
|
81
|
+
"""
|
82
|
+
---
|
83
|
+
namespace: maestrodev
|
84
|
+
git_base: https://github.com/
|
85
|
+
"""
|
86
|
+
And a file named "config_defaults.yml" with:
|
87
|
+
"""
|
88
|
+
---
|
89
|
+
:global:
|
90
|
+
name: aruba
|
91
|
+
"""
|
92
|
+
And a directory named "moduleroot"
|
93
|
+
And a file named "moduleroot/test.erb" with:
|
94
|
+
"""
|
95
|
+
<%= @configs['name'] %>
|
96
|
+
"""
|
97
|
+
When I run `msync update --noop`
|
98
|
+
Then the exit status should be 0
|
99
|
+
And the output should match:
|
100
|
+
"""
|
101
|
+
Files added:
|
102
|
+
test
|
103
|
+
"""
|
104
|
+
Given I run `cat modules/puppet-test/test`
|
105
|
+
Then the output should contain "aruba"
|
106
|
+
|
107
|
+
Scenario: Adding a new file overriding global values
|
108
|
+
Given a file named "managed_modules.yml" with:
|
109
|
+
"""
|
110
|
+
---
|
111
|
+
- puppet-test
|
112
|
+
"""
|
113
|
+
And a file named "modulesync.yml" with:
|
114
|
+
"""
|
115
|
+
---
|
116
|
+
namespace: maestrodev
|
117
|
+
git_base: https://github.com/
|
118
|
+
"""
|
119
|
+
And a file named "config_defaults.yml" with:
|
120
|
+
"""
|
121
|
+
---
|
122
|
+
:global:
|
123
|
+
name: global
|
124
|
+
|
125
|
+
test:
|
126
|
+
name: aruba
|
127
|
+
"""
|
128
|
+
And a directory named "moduleroot"
|
129
|
+
And a file named "moduleroot/test.erb" with:
|
130
|
+
"""
|
131
|
+
<%= @configs['name'] %>
|
132
|
+
"""
|
133
|
+
When I run `msync update --noop`
|
134
|
+
Then the exit status should be 0
|
135
|
+
And the output should match:
|
136
|
+
"""
|
137
|
+
Files added:
|
138
|
+
test
|
139
|
+
"""
|
140
|
+
Given I run `cat modules/puppet-test/test`
|
141
|
+
Then the output should contain "aruba"
|
142
|
+
|
143
|
+
Scenario: Adding a new file ignoring global values
|
144
|
+
Given a file named "managed_modules.yml" with:
|
145
|
+
"""
|
146
|
+
---
|
147
|
+
- puppet-test
|
148
|
+
"""
|
149
|
+
And a file named "modulesync.yml" with:
|
150
|
+
"""
|
151
|
+
---
|
152
|
+
namespace: maestrodev
|
153
|
+
git_base: https://github.com/
|
154
|
+
"""
|
155
|
+
And a file named "config_defaults.yml" with:
|
156
|
+
"""
|
157
|
+
---
|
158
|
+
:global:
|
159
|
+
key: global
|
160
|
+
|
161
|
+
test:
|
162
|
+
name: aruba
|
163
|
+
"""
|
164
|
+
And a directory named "moduleroot"
|
165
|
+
And a file named "moduleroot/test.erb" with:
|
166
|
+
"""
|
167
|
+
<%= @configs['name'] %>
|
168
|
+
"""
|
169
|
+
When I run `msync update --noop`
|
170
|
+
Then the exit status should be 0
|
29
171
|
And the output should match:
|
30
172
|
"""
|
31
173
|
Files added:
|
@@ -53,7 +195,7 @@ Feature: update
|
|
53
195
|
name: aruba
|
54
196
|
"""
|
55
197
|
And a directory named "moduleroot"
|
56
|
-
And a file named "moduleroot/test" with:
|
198
|
+
And a file named "moduleroot/test.erb" with:
|
57
199
|
"""
|
58
200
|
<% @configs.each do |c| -%>
|
59
201
|
<%= c['name'] %>
|
@@ -81,7 +223,7 @@ Feature: update
|
|
81
223
|
name: aruba
|
82
224
|
"""
|
83
225
|
And a directory named "moduleroot"
|
84
|
-
And a file named "moduleroot/test" with:
|
226
|
+
And a file named "moduleroot/test.erb" with:
|
85
227
|
"""
|
86
228
|
<% @configs.each do |c| -%>
|
87
229
|
<%= c['name'] %>
|
@@ -109,7 +251,7 @@ Feature: update
|
|
109
251
|
gem_source: https://somehost.com
|
110
252
|
"""
|
111
253
|
And a directory named "moduleroot"
|
112
|
-
And a file named "moduleroot/Gemfile" with:
|
254
|
+
And a file named "moduleroot/Gemfile.erb" with:
|
113
255
|
"""
|
114
256
|
source '<%= @configs['gem_source'] %>'
|
115
257
|
"""
|
@@ -136,7 +278,7 @@ Feature: update
|
|
136
278
|
gem_source: https://somehost.com
|
137
279
|
"""
|
138
280
|
And a directory named "moduleroot"
|
139
|
-
And a file named "moduleroot/Gemfile" with:
|
281
|
+
And a file named "moduleroot/Gemfile.erb" with:
|
140
282
|
"""
|
141
283
|
source '<%= @configs['gem_source'] %>'
|
142
284
|
"""
|
@@ -168,7 +310,7 @@ Feature: update
|
|
168
310
|
unmanaged: true
|
169
311
|
"""
|
170
312
|
And a directory named "moduleroot"
|
171
|
-
And a file named "moduleroot/Gemfile" with:
|
313
|
+
And a file named "moduleroot/Gemfile.erb" with:
|
172
314
|
"""
|
173
315
|
source '<%= @configs['gem_source'] %>'
|
174
316
|
"""
|
@@ -208,7 +350,7 @@ Feature: update
|
|
208
350
|
delete: true
|
209
351
|
"""
|
210
352
|
And a directory named "moduleroot"
|
211
|
-
And a file named "moduleroot/Gemfile" with:
|
353
|
+
And a file named "moduleroot/Gemfile.erb" with:
|
212
354
|
"""
|
213
355
|
source '<%= @configs['gem_source'] %>'
|
214
356
|
"""
|
@@ -262,7 +404,7 @@ Feature: update
|
|
262
404
|
unmanaged: true
|
263
405
|
"""
|
264
406
|
And a directory named "moduleroot/spec"
|
265
|
-
And a file named "moduleroot/spec/spec_helper.rb" with:
|
407
|
+
And a file named "moduleroot/spec/spec_helper.rb.erb" with:
|
266
408
|
"""
|
267
409
|
some spec_helper fud
|
268
410
|
"""
|
@@ -303,7 +445,7 @@ Feature: update
|
|
303
445
|
require:
|
304
446
|
- puppetlabs_spec_helper/module_helper
|
305
447
|
"""
|
306
|
-
And a file named "moduleroot/spec/spec_helper.rb" with:
|
448
|
+
And a file named "moduleroot/spec/spec_helper.rb.erb" with:
|
307
449
|
"""
|
308
450
|
<% @configs['require'].each do |required| -%>
|
309
451
|
require '<%= required %>'
|
@@ -341,7 +483,7 @@ Feature: update
|
|
341
483
|
require:
|
342
484
|
- puppetlabs_spec_helper/module_helper
|
343
485
|
"""
|
344
|
-
And a file named "moduleroot/spec/spec_helper.rb" with:
|
486
|
+
And a file named "moduleroot/spec/spec_helper.rb.erb" with:
|
345
487
|
"""
|
346
488
|
<% @configs['require'].each do |required| -%>
|
347
489
|
require '<%= required %>'
|
@@ -369,7 +511,7 @@ Feature: update
|
|
369
511
|
require:
|
370
512
|
- puppetlabs_spec_helper/module_helper
|
371
513
|
"""
|
372
|
-
And a file named "moduleroot/spec/spec_helper.rb" with:
|
514
|
+
And a file named "moduleroot/spec/spec_helper.rb.erb" with:
|
373
515
|
"""
|
374
516
|
<% @configs['require'].each do |required| -%>
|
375
517
|
require '<%= required %>'
|
@@ -434,7 +576,7 @@ Feature: update
|
|
434
576
|
name: aruba
|
435
577
|
"""
|
436
578
|
And a directory named "moduleroot"
|
437
|
-
And a file named "moduleroot/test" with:
|
579
|
+
And a file named "moduleroot/test.erb" with:
|
438
580
|
"""
|
439
581
|
<%= @configs['name'] %>
|
440
582
|
"""
|
@@ -469,7 +611,7 @@ Feature: update
|
|
469
611
|
name: aruba
|
470
612
|
"""
|
471
613
|
And a directory named "moduleroot"
|
472
|
-
And a file named "moduleroot/test" with:
|
614
|
+
And a file named "moduleroot/test.erb" with:
|
473
615
|
"""
|
474
616
|
<%= @configs['name'] %>
|
475
617
|
"""
|
@@ -505,7 +647,7 @@ Feature: update
|
|
505
647
|
name: aruba
|
506
648
|
"""
|
507
649
|
And a directory named "moduleroot"
|
508
|
-
And a file named "moduleroot/test" with:
|
650
|
+
And a file named "moduleroot/test.erb" with:
|
509
651
|
"""
|
510
652
|
<%= @configs['name'] %>
|
511
653
|
"""
|
@@ -538,7 +680,7 @@ Feature: update
|
|
538
680
|
require:
|
539
681
|
- puppetlabs_spec_helper/module_helper
|
540
682
|
"""
|
541
|
-
And a file named "moduleroot/spec/spec_helper.rb" with:
|
683
|
+
And a file named "moduleroot/spec/spec_helper.rb.erb" with:
|
542
684
|
"""
|
543
685
|
<% @configs['require'].each do |required| -%>
|
544
686
|
require '<%= required %>'
|
@@ -591,7 +733,7 @@ Feature: update
|
|
591
733
|
name: aruba
|
592
734
|
"""
|
593
735
|
And a directory named "moduleroot"
|
594
|
-
And a file named "moduleroot/test" with:
|
736
|
+
And a file named "moduleroot/test.erb" with:
|
595
737
|
"""
|
596
738
|
<%= @configs['name'] %>
|
597
739
|
"""
|
@@ -607,7 +749,7 @@ Feature: update
|
|
607
749
|
Given I run `cat modules/puppet-lib-file_concat/.git/config`
|
608
750
|
Then the output should contain "url = https://github.com/electrical/puppet-lib-file_concat.git"
|
609
751
|
|
610
|
-
Scenario: Modifying an existing file with values
|
752
|
+
Scenario: Modifying an existing file with values exposed by the module
|
611
753
|
Given a file named "managed_modules.yml" with:
|
612
754
|
"""
|
613
755
|
---
|
@@ -625,7 +767,7 @@ Feature: update
|
|
625
767
|
README.md:
|
626
768
|
"""
|
627
769
|
And a directory named "moduleroot"
|
628
|
-
And a file named "moduleroot/README.md" with:
|
770
|
+
And a file named "moduleroot/README.md.erb" with:
|
629
771
|
"""
|
630
772
|
echo '<%= @configs[:git_base] + @configs[:namespace] %>'
|
631
773
|
"""
|
@@ -652,7 +794,7 @@ Feature: update
|
|
652
794
|
gem_source: https://somehost.com
|
653
795
|
"""
|
654
796
|
And a directory named "moduleroot"
|
655
|
-
And a file named "moduleroot/Gemfile" with:
|
797
|
+
And a file named "moduleroot/Gemfile.erb" with:
|
656
798
|
"""
|
657
799
|
source '<%= @configs['gem_source'] %>'
|
658
800
|
"""
|
data/lib/modulesync/git.rb
CHANGED
@@ -147,7 +147,7 @@ module ModuleSync
|
|
147
147
|
def self.untracked_unignored_files(repo)
|
148
148
|
ignore_path = "#{repo.dir.path}/.gitignore"
|
149
149
|
ignored = File.exist?(ignore_path) ? File.open(ignore_path).read.split : []
|
150
|
-
repo.status.untracked.keep_if { |f, _|
|
150
|
+
repo.status.untracked.keep_if { |f, _| ignored.none? { |i| File.fnmatch(i, f) } }
|
151
151
|
end
|
152
152
|
|
153
153
|
def self.update_noop(name, options)
|
data/lib/modulesync/renderer.rb
CHANGED
@@ -9,10 +9,16 @@ module ModuleSync
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.build(
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def self.build(target_name)
|
13
|
+
template_file = if !File.exist?("#{target_name}.erb") && File.exist?(target_name)
|
14
|
+
STDERR.puts "Warning: using '#{target_name}' as template without '.erb' suffix"
|
15
|
+
target_name
|
16
|
+
else
|
17
|
+
"#{target_name}.erb"
|
18
|
+
end
|
19
|
+
erb_obj = ERB.new(File.read(template_file), nil, '-')
|
20
|
+
erb_obj.filename = template_file
|
21
|
+
erb_obj.def_method(ForgeModuleFile, 'render()', template_file)
|
16
22
|
erb_obj
|
17
23
|
end
|
18
24
|
|
@@ -24,10 +30,10 @@ module ModuleSync
|
|
24
30
|
ForgeModuleFile.new(configs).render
|
25
31
|
end
|
26
32
|
|
27
|
-
def self.sync(template,
|
28
|
-
path =
|
33
|
+
def self.sync(template, target_name)
|
34
|
+
path = target_name.rpartition('/').first
|
29
35
|
FileUtils.mkdir_p(path) unless path.empty?
|
30
|
-
File.open(
|
36
|
+
File.open(target_name, 'w') do |file|
|
31
37
|
file.write(template)
|
32
38
|
end
|
33
39
|
end
|
data/lib/modulesync/settings.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
2
|
module ModuleSync
|
3
3
|
# Encapsulate a configs for a module, providing easy access to its parts
|
4
|
+
# All configs MUST be keyed by the relative target filename
|
4
5
|
class Settings
|
5
6
|
attr_reader :global_defaults, :defaults, :module_defaults, :module_configs, :additional_settings
|
6
7
|
|
@@ -12,28 +13,36 @@ module ModuleSync
|
|
12
13
|
@additional_settings = additional_settings
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
16
|
+
def lookup_config(hash, target_name)
|
17
|
+
hash[target_name] || {}
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
20
|
+
def build_file_configs(target_name)
|
21
|
+
file_def = lookup_config(defaults, target_name)
|
22
|
+
file_md = lookup_config(module_defaults, target_name)
|
23
|
+
file_mc = lookup_config(module_configs, target_name)
|
24
|
+
|
25
|
+
global_defaults.merge(file_def).merge(file_md).merge(file_mc).merge(additional_settings)
|
26
|
+
end
|
27
|
+
|
28
|
+
def managed?(target_name)
|
29
|
+
Pathname.new(target_name).ascend do |v|
|
21
30
|
configs = build_file_configs(v.to_s)
|
22
31
|
return false if configs['unmanaged']
|
23
32
|
end
|
24
33
|
true
|
25
34
|
end
|
26
35
|
|
27
|
-
# given a list of
|
28
|
-
def managed_files(
|
29
|
-
(
|
36
|
+
# given a list of templates in the repo, return everything that we might want to act on
|
37
|
+
def managed_files(target_name_list)
|
38
|
+
(target_name_list | defaults.keys | module_configs.keys).select do |f|
|
30
39
|
(f != ModuleSync::GLOBAL_DEFAULTS_KEY) && managed?(f)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
34
|
-
# returns a list of
|
35
|
-
def unmanaged_files(
|
36
|
-
(
|
43
|
+
# returns a list of templates that should not be touched
|
44
|
+
def unmanaged_files(target_name_list)
|
45
|
+
(target_name_list | defaults.keys | module_configs.keys).select do |f|
|
37
46
|
(f != ModuleSync::GLOBAL_DEFAULTS_KEY) && !managed?(f)
|
38
47
|
end
|
39
48
|
end
|
data/lib/modulesync.rb
CHANGED
@@ -7,6 +7,7 @@ require 'modulesync/hook'
|
|
7
7
|
require 'modulesync/renderer'
|
8
8
|
require 'modulesync/settings'
|
9
9
|
require 'modulesync/util'
|
10
|
+
require 'monkey_patches'
|
10
11
|
|
11
12
|
module ModuleSync
|
12
13
|
include Constants
|
@@ -30,7 +31,8 @@ module ModuleSync
|
|
30
31
|
|
31
32
|
def self.local_files(path)
|
32
33
|
if File.exist?(path)
|
33
|
-
|
34
|
+
# only select *.erb files, and strip the extension. This way all the code will only have to handle bare paths, except when reading the actual ERB text
|
35
|
+
local_files = Find.find(path).find_all { |p| p =~ /.erb$/ && !File.directory?(p) }.collect { |p| p.chomp('.erb') }.to_a
|
34
36
|
else
|
35
37
|
puts "#{path} does not exist. Check that you are working in your module configs directory or that you have passed in the correct directory with -c."
|
36
38
|
exit
|
@@ -48,7 +50,7 @@ module ModuleSync
|
|
48
50
|
exit
|
49
51
|
end
|
50
52
|
managed_modules.select! { |m| m =~ Regexp.new(filter) } unless filter.nil?
|
51
|
-
managed_modules.
|
53
|
+
managed_modules.reject! { |m| m =~ Regexp.new(negative_filter) } unless negative_filter.nil?
|
52
54
|
managed_modules
|
53
55
|
end
|
54
56
|
|
@@ -88,7 +90,7 @@ module ModuleSync
|
|
88
90
|
|
89
91
|
def self.manage_module(puppet_module, module_files, module_options, defaults, options)
|
90
92
|
puts "Syncing #{puppet_module}"
|
91
|
-
namespace, module_name =
|
93
|
+
namespace, module_name = module_name(puppet_module, options[:namespace])
|
92
94
|
unless options[:offline]
|
93
95
|
git_base = options[:git_base]
|
94
96
|
git_uri = "#{git_base}#{namespace}"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Git
|
2
|
+
class Diff
|
3
|
+
# Monkey patch process_full_diff until https://github.com/schacon/ruby-git/issues/326 is resolved
|
4
|
+
def process_full_diff
|
5
|
+
defaults = {
|
6
|
+
:mode => '',
|
7
|
+
:src => '',
|
8
|
+
:dst => '',
|
9
|
+
:type => 'modified'
|
10
|
+
}
|
11
|
+
final = {}
|
12
|
+
current_file = nil
|
13
|
+
full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", {
|
14
|
+
:invalid => :replace,
|
15
|
+
:undef => :replace
|
16
|
+
})
|
17
|
+
full_diff_utf8_encoded.split("\n").each do |line|
|
18
|
+
if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line)
|
19
|
+
current_file = m[1]
|
20
|
+
final[current_file] = defaults.merge({:patch => line, :path => current_file})
|
21
|
+
elsif !current_file.nil?
|
22
|
+
if m = /^index (.......)\.\.(.......)( ......)*/.match(line)
|
23
|
+
final[current_file][:src] = m[1]
|
24
|
+
final[current_file][:dst] = m[2]
|
25
|
+
final[current_file][:mode] = m[3].strip if m[3]
|
26
|
+
end
|
27
|
+
if m = /^([[:alpha:]]*?) file mode (......)/.match(line)
|
28
|
+
final[current_file][:type] = m[1]
|
29
|
+
final[current_file][:mode] = m[2]
|
30
|
+
end
|
31
|
+
if m = /^Binary files /.match(line)
|
32
|
+
final[current_file][:binary] = true
|
33
|
+
end
|
34
|
+
final[current_file][:patch] << "\n" + line
|
35
|
+
end
|
36
|
+
end
|
37
|
+
final.map { |e| [e[0], DiffFile.new(@base, e[1])] }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/modulesync.gemspec
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
10
|
-
spec.summary
|
11
|
-
spec.description
|
12
|
-
spec.homepage
|
13
|
-
spec.license
|
7
|
+
spec.name = 'modulesync'
|
8
|
+
spec.version = '0.8.0'
|
9
|
+
spec.authors = ['Vox Pupuli']
|
10
|
+
spec.email = ['voxpupuli@groups.io']
|
11
|
+
spec.summary = 'Puppet Module Synchronizer'
|
12
|
+
spec.description = 'Utility to synchronize common files across puppet modules in Github.'
|
13
|
+
spec.homepage = 'http://github.com/voxpupuli/modulesync'
|
14
|
+
spec.license = 'Apache-2.0'
|
15
|
+
spec.required_ruby_version = '>= 2.0.0'
|
14
16
|
|
15
17
|
spec.files = `git ls-files -z`.split("\x0")
|
16
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -18,12 +20,12 @@ Gem::Specification.new do |spec|
|
|
18
20
|
spec.require_paths = ['lib']
|
19
21
|
|
20
22
|
spec.add_development_dependency 'aruba'
|
21
|
-
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'bundler'
|
22
24
|
spec.add_development_dependency 'rake'
|
23
25
|
spec.add_development_dependency 'rspec'
|
24
26
|
spec.add_development_dependency 'rubocop'
|
25
27
|
|
26
|
-
spec.add_runtime_dependency 'git', '~>1.
|
28
|
+
spec.add_runtime_dependency 'git', '~>1.3'
|
27
29
|
spec.add_runtime_dependency 'puppet-blacksmith', '~>3.0'
|
28
30
|
spec.add_runtime_dependency 'thor'
|
29
31
|
end
|
@@ -19,7 +19,7 @@ describe ModuleSync::Settings do
|
|
19
19
|
it { expect(subject.managed?('Gemfile')).to eq true }
|
20
20
|
it { expect(subject.managed?('Gemfile/foo')).to eq true }
|
21
21
|
it { expect(subject.managed_files([])).to eq ['Gemfile'] }
|
22
|
-
it { expect(subject.managed_files(%w
|
22
|
+
it { expect(subject.managed_files(%w[Rakefile Gemfile other_file])).to eq %w[Gemfile other_file] }
|
23
23
|
it { expect(subject.unmanaged_files([])).to eq ['Rakefile'] }
|
24
|
-
it { expect(subject.unmanaged_files(%w
|
24
|
+
it { expect(subject.unmanaged_files(%w[Rakefile Gemfile other_file])).to eq ['Rakefile'] }
|
25
25
|
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.8.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: 2017-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1.
|
89
|
+
version: '1.3'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
96
|
+
version: '1.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: puppet-blacksmith
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- lib/modulesync/renderer.rb
|
156
156
|
- lib/modulesync/settings.rb
|
157
157
|
- lib/modulesync/util.rb
|
158
|
+
- lib/monkey_patches.rb
|
158
159
|
- modulesync.gemspec
|
159
160
|
- spec/spec_helper.rb
|
160
161
|
- spec/unit/modulesync/settings_spec.rb
|
@@ -170,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
171
|
requirements:
|
171
172
|
- - ">="
|
172
173
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
174
|
+
version: 2.0.0
|
174
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
176
|
requirements:
|
176
177
|
- - ">="
|
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
179
|
version: '0'
|
179
180
|
requirements: []
|
180
181
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.4.
|
182
|
+
rubygems_version: 2.4.8
|
182
183
|
signing_key:
|
183
184
|
specification_version: 4
|
184
185
|
summary: Puppet Module Synchronizer
|