modulesync 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ tmp/
1
2
  modules/
2
3
  *.gem
3
- Gemfile.lock
4
+ Gemfile.lock
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ script: 'bundle exec rake test'
6
+ rvm:
7
+ - 1.9.3
8
+ - 2.0
9
+ - 2.1
@@ -1,3 +1,22 @@
1
+ ##2015-08-11 - 0.6.0
2
+
3
+ ### Summary
4
+
5
+ This release adds two new flags to help modulesync better integrate with CI tools.
6
+
7
+ #### Features
8
+
9
+ - Add --project-root flag
10
+ - Create --offline flag to disable git functionality
11
+
12
+ #### Bugfixes
13
+
14
+ - Fix :remote option for repo
15
+
16
+ #### Maintenance
17
+
18
+ - Added tests
19
+
1
20
  ##2015-06-30 - 0.5.0
2
21
 
3
22
  ### Summary
data/README.md CHANGED
@@ -121,6 +121,17 @@ overwrites local changes.
121
121
  msync update --noop
122
122
  ```
123
123
 
124
+ #### Offline support
125
+ The --offline flag was added to allow a user to disable git support within
126
+ msync. One reason for this is because the user wants to control git commands
127
+ external to msync. Note, when using this command, msync assumes you have
128
+ create the folder structure and git repositories correctly. If not, msync will
129
+ fail to update correctly.
130
+
131
+ ```
132
+ msync update --offline
133
+ ```
134
+
124
135
  #### Damage mode
125
136
 
126
137
  Make changes for real and push them back to master. This operates on the
@@ -0,0 +1,11 @@
1
+ require 'rake/clean'
2
+ require 'cucumber/rake/task'
3
+
4
+ CLEAN.include("pkg/", "tmp/")
5
+
6
+ Cucumber::Rake::Task.new do |t|
7
+ t.cucumber_opts = ""
8
+ t.cucumber_opts << "--format pretty"
9
+ end
10
+
11
+ task :test => [:clean, :cucumber]
@@ -0,0 +1,5 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before do
4
+ @aruba_timeout_seconds = 5
5
+ end
@@ -0,0 +1,201 @@
1
+ Feature: update
2
+ ModuleSync needs to update module boilerplate
3
+
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" 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 /Files added:\s+test/
30
+ Given I run `cat modules/puppet-test/test`
31
+ Then the output should contain "aruba"
32
+
33
+ Scenario: Adding a new file into foobar project-root
34
+ Given a file named "managed_modules.yml" with:
35
+ """
36
+ ---
37
+ - puppet-test
38
+ """
39
+ And a file named "modulesync.yml" with:
40
+ """
41
+ ---
42
+ namespace: maestrodev
43
+ git_base: https://github.com/
44
+ """
45
+ And a file named "config_defaults.yml" with:
46
+ """
47
+ ---
48
+ test:
49
+ name: aruba
50
+ """
51
+ And a directory named "moduleroot"
52
+ And a file named "moduleroot/test" with:
53
+ """
54
+ <%= @configs['name'] %>
55
+ """
56
+ When I run `msync update --noop --project-root=foobar`
57
+ Then the exit status should be 0
58
+ And the output should match /Files added:\s+test/
59
+ Given I run `cat foobar/puppet-test/test`
60
+ Then the output should contain "aruba"
61
+
62
+ Scenario: Modifying an existing file
63
+ Given a file named "managed_modules.yml" with:
64
+ """
65
+ ---
66
+ - puppet-test
67
+ """
68
+ And a file named "modulesync.yml" with:
69
+ """
70
+ ---
71
+ namespace: maestrodev
72
+ git_base: https://github.com/
73
+ """
74
+ And a file named "config_defaults.yml" with:
75
+ """
76
+ ---
77
+ Gemfile:
78
+ gem_source: https://somehost.com
79
+ """
80
+ And a directory named "moduleroot"
81
+ And a file named "moduleroot/Gemfile" with:
82
+ """
83
+ source '<%= @configs['gem_source'] %>'
84
+ """
85
+ When I run `msync update --noop`
86
+ Then the exit status should be 0
87
+ And the output should match:
88
+ """
89
+ Files changed:\s+
90
+ +diff --git a/Gemfile b/Gemfile
91
+ """
92
+ Given I run `cat modules/puppet-test/Gemfile`
93
+ Then the output should contain:
94
+ """
95
+ source 'https://somehost.com'
96
+ """
97
+
98
+ Scenario: Adding a new file in a new subdirectory
99
+ Given a file named "managed_modules.yml" with:
100
+ """
101
+ ---
102
+ - puppet-test
103
+ """
104
+ And a file named "modulesync.yml" with:
105
+ """
106
+ ---
107
+ namespace: maestrodev
108
+ git_base: https://github.com/
109
+ """
110
+ And a file named "config_defaults.yml" with:
111
+ """
112
+ ---
113
+ spec/spec_helper.rb:
114
+ require:
115
+ - puppetlabs_spec_helper/module_helper
116
+ """
117
+ And a file named "moduleroot/spec/spec_helper.rb" with:
118
+ """
119
+ <% @configs['require'].each do |required| -%>
120
+ require '<%= required %>'
121
+ <% end %>
122
+ """
123
+ When I run `msync update --noop`
124
+ Then the exit status should be 0
125
+ And the output should match:
126
+ """
127
+ Files added:\s+
128
+ spec/spec_helper.rb
129
+ """
130
+ Given I run `cat modules/puppet-test/spec/spec_helper.rb`
131
+ Then the output should contain:
132
+ """
133
+ require 'puppetlabs_spec_helper/module_helper'
134
+ """
135
+ When I run `msync update --offline --noop`
136
+ Then the exit status should be 0
137
+ And the output should match:
138
+ """
139
+ Files added:\s+
140
+ spec/spec_helper.rb
141
+ """
142
+ When I run `msync update --offline`
143
+ Then the exit status should be 0
144
+ And the output should match:
145
+ """
146
+ """
147
+
148
+ Scenario: Updating a module with a .sync.yml file
149
+ Given a file named "managed_modules.yml" with:
150
+ """
151
+ ---
152
+ - puppetlabs-stdlib
153
+ """
154
+ And a file named "modulesync.yml" with:
155
+ """
156
+ ---
157
+ git_base: https://github.com/
158
+ """
159
+ And a file named "config_defaults.yml" with:
160
+ """
161
+ ---
162
+ spec/spec_helper.rb:
163
+ require:
164
+ - puppetlabs_spec_helper/module_helper
165
+ """
166
+ And a file named "moduleroot/spec/spec_helper.rb" with:
167
+ """
168
+ <% @configs['require'].each do |required| -%>
169
+ require '<%= required %>'
170
+ <% end %>
171
+ """
172
+ And a file named "moduleroot/.travis.yml" with:
173
+ """
174
+ ---
175
+ sudo: false
176
+ language: ruby
177
+ cache: bundler
178
+ bundler_args: --without system_tests
179
+ script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"
180
+ matrix:
181
+ fast_finish: true
182
+ include:
183
+ - rvm: 1.8.7
184
+ env: PUPPET_GEM_VERSION="~> 3.0"
185
+ - rvm: 1.9.3
186
+ env: PUPPET_GEM_VERSION="~> 3.0"
187
+ - rvm: 2.1.5
188
+ env: PUPPET_GEM_VERSION="~> 3.0"
189
+ - rvm: 2.1.5
190
+ env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
191
+ - rvm: 2.1.6
192
+ env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
193
+ notifications:
194
+ email: false
195
+ """
196
+ When I run `msync update --noop`
197
+ Then the exit status should be 0
198
+ And the output should match:
199
+ """
200
+ Not managing spec/spec_helper.rb in puppetlabs-stdlib
201
+ """
@@ -13,8 +13,8 @@ module ModuleSync
13
13
  "#{config_path}/#{MODULE_FILES_DIR}/#{file}"
14
14
  end
15
15
 
16
- def self.module_file(puppet_module, file)
17
- "#{PROJ_ROOT}/#{puppet_module}/#{file}"
16
+ def self.module_file(project_root, puppet_module, file)
17
+ "#{project_root}/#{puppet_module}/#{file}"
18
18
  end
19
19
 
20
20
  def self.local_files(path)
@@ -56,9 +56,11 @@ module ModuleSync
56
56
  # managed_modules is either an array or a hash
57
57
  managed_modules.each do |puppet_module, opts|
58
58
  puts "Syncing #{puppet_module}"
59
- git_base = "#{options[:git_base]}#{options[:namespace]}"
60
- Git.pull(git_base, puppet_module, options[:branch], opts || {})
61
- module_configs = Util.parse_config("#{PROJ_ROOT}/#{puppet_module}/#{MODULE_CONF_FILE}")
59
+ unless options[:offline]
60
+ git_base = "#{options[:git_base]}#{options[:namespace]}"
61
+ Git.pull(git_base, puppet_module, options[:branch], options[:project_root], opts || {})
62
+ end
63
+ module_configs = Util.parse_config("#{options[:project_root]}/#{puppet_module}/#{MODULE_CONF_FILE}")
62
64
  global_defaults = defaults[GLOBAL_DEFAULTS_KEY] || {}
63
65
  module_defaults = module_configs[GLOBAL_DEFAULTS_KEY] || {}
64
66
  files_to_manage = (module_files | defaults.keys | module_configs.keys) - [GLOBAL_DEFAULTS_KEY]
@@ -70,17 +72,17 @@ module ModuleSync
70
72
  puts "Not managing #{file} in #{puppet_module}"
71
73
  files_to_delete << file
72
74
  elsif file_configs['delete']
73
- Renderer.remove(module_file(puppet_module, file))
75
+ Renderer.remove(module_file(options['project_root'], puppet_module, file))
74
76
  else
75
77
  erb = Renderer.build(local_file(options[:configs], file))
76
78
  template = Renderer.render(erb, file_configs)
77
- Renderer.sync(template, "#{PROJ_ROOT}/#{puppet_module}/#{file}")
79
+ Renderer.sync(template, "#{options[:project_root]}/#{puppet_module}/#{file}")
78
80
  end
79
81
  end
80
82
  files_to_manage -= files_to_delete
81
83
  if options[:noop]
82
84
  Git.update_noop(puppet_module, options)
83
- else
85
+ elsif not options[:offline]
84
86
  Git.update(puppet_module, files_to_manage, options)
85
87
  end
86
88
  end
@@ -14,6 +14,7 @@ module ModuleSync
14
14
  :managed_modules_conf => 'managed_modules.yml',
15
15
  :configs => '.',
16
16
  :tag_pattern => '%s',
17
+ :project_root => './modules',
17
18
  }
18
19
  end
19
20
 
@@ -35,7 +36,7 @@ module ModuleSync
35
36
  @options.merge!(Hash.transform_keys_to_symbols(Util.parse_config(MODULESYNC_CONF_FILE)))
36
37
  @options[:command] = args[0] if commands_available.include?(args[0])
37
38
  opt_parser = OptionParser.new do |opts|
38
- opts.banner = "Usage: msync update [-m <commit message>] [-c <directory> ] [--noop] [--bump] [--changelog] [--tag] [--tag-pattern <tag_pattern>] [-n <namespace>] [-b <branch>] [-r <branch>] [-f <filter>] | hook activate|deactivate [-c <directory> ] [-n <namespace>] [-b <branch>]"
39
+ opts.banner = "Usage: msync update [-m <commit message>] [-c <directory> ] [--offline] [--noop] [--bump] [--changelog] [--tag] [--tag-pattern <tag_pattern>] [-p <project_root> [-n <namespace>] [-b <branch>] [-r <branch>] [-f <filter>] | hook activate|deactivate [-c <directory> ] [-n <namespace>] [-b <branch>]"
39
40
  opts.on('-m', '--message <msg>',
40
41
  'Commit message to apply to updated modules') do |msg|
41
42
  @options[:message] = msg
@@ -52,6 +53,10 @@ module ModuleSync
52
53
  'Branch name to make the changes in. Defaults to "master"') do |branch|
53
54
  @options[:branch] = branch
54
55
  end
56
+ opts.on('-p', '--project-root <path>',
57
+ 'Path used by git to clone modules into. Defaults to "modules"') do |project_root|
58
+ @options[:project_root] = project_root
59
+ end
55
60
  opts.on('-r', '--remote-branch <branch>',
56
61
  'Remote branch name to push the changes to. Defaults to the branch name') do |branch|
57
62
  @options[:remote_branch] = branch
@@ -72,6 +77,10 @@ module ModuleSync
72
77
  'No-op mode') do |msg|
73
78
  @options[:noop] = true
74
79
  end
80
+ opts.on('--offline',
81
+ 'Do not run git command. Helpful if you have existing repositories locally.') do |msg|
82
+ @options[:offline] = true
83
+ end
75
84
  opts.on('--bump',
76
85
  'Bump module version to the next minor') do |msg|
77
86
  @options[:bump] = true
@@ -92,8 +101,8 @@ module ModuleSync
92
101
  end.parse!
93
102
 
94
103
  @options.fetch(:message) do
95
- if @options[:command] == 'update' && ! @options[:noop] && ! @options[:amend]
96
- fail("A commit message is required unless using noop.")
104
+ if @options[:command] == 'update' && ! @options[:noop] && ! @options[:amend] && ! @options[:offline]
105
+ fail("A commit message is required unless using noop or offline.")
97
106
  end
98
107
  end
99
108
 
@@ -4,7 +4,6 @@ module ModuleSync
4
4
  CONF_FILE = 'config_defaults.yml'
5
5
  MODULE_CONF_FILE = '.sync.yml'
6
6
  MODULESYNC_CONF_FILE = 'modulesync.yml'
7
- PROJ_ROOT = './modules'
8
7
  HOOK_FILE = '.git/hooks/pre-push'
9
8
  GLOBAL_DEFAULTS_KEY = :global
10
9
  end
@@ -30,24 +30,24 @@ module ModuleSync
30
30
  end
31
31
  end
32
32
 
33
- def self.pull(git_base, name, branch, opts)
34
- if ! Dir.exists?(PROJ_ROOT)
35
- Dir.mkdir(PROJ_ROOT)
33
+ def self.pull(git_base, name, branch, project_root, opts)
34
+ if ! Dir.exists?(project_root)
35
+ Dir.mkdir(project_root)
36
36
  end
37
37
 
38
38
  # Repo needs to be cloned in the cwd
39
- if ! Dir.exists?("#{PROJ_ROOT}/#{name}") || ! Dir.exists?("#{PROJ_ROOT}/#{name}/.git")
39
+ if ! Dir.exists?("#{opts[:project_root]}/#{name}") || ! Dir.exists?("#{opts[:project_root]}/#{name}/.git")
40
40
  puts "Cloning repository fresh"
41
- remote = opts[:remote] || git_base.start_with?('file://') ? "#{git_base}/#{name}" : "#{git_base}/#{name}.git"
42
- local = "#{PROJ_ROOT}/#{name}"
41
+ remote = opts[:remote] || (git_base.start_with?('file://') ? "#{git_base}/#{name}" : "#{git_base}/#{name}.git")
42
+ local = "#{project_root}/#{name}"
43
43
  puts "Cloning from #{remote}"
44
44
  repo = ::Git.clone(remote, local)
45
45
  switch_branch(repo, branch)
46
46
  # Repo already cloned, check out master and override local changes
47
47
  else
48
48
  # Some versions of git can't properly handle managing a repo from outside the repo directory
49
- Dir.chdir("#{PROJ_ROOT}/#{name}") do
50
- puts "Overriding any local changes to repositories in #{PROJ_ROOT}"
49
+ Dir.chdir("#{project_root}/#{name}") do
50
+ puts "Overriding any local changes to repositories in #{project_root}"
51
51
  repo = ::Git.open('.')
52
52
  repo.fetch
53
53
  repo.reset_hard
@@ -96,7 +96,7 @@ module ModuleSync
96
96
 
97
97
  # Git add/rm, git commit, git push
98
98
  def self.update(name, files, options)
99
- module_root = "#{PROJ_ROOT}/#{name}"
99
+ module_root = "#{options[:project_root]}/#{name}"
100
100
  message = options[:message]
101
101
  if options[:remote_branch]
102
102
  branch = "#{options[:branch]}:#{options[:remote_branch]}"
@@ -159,7 +159,7 @@ module ModuleSync
159
159
  def self.update_noop(name, options)
160
160
  puts "Using no-op. Files in #{name} may be changed but will not be committed."
161
161
 
162
- repo = ::Git.open("#{PROJ_ROOT}/#{name}")
162
+ repo = ::Git.open("#{options[:project_root]}/#{name}")
163
163
  repo.branch(options[:branch]).checkout
164
164
 
165
165
  puts "Files changed: "
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'modulesync'
7
- spec.version = '0.5.0'
7
+ spec.version = '0.6.0'
8
8
  spec.authors = ['Colleen Murphy']
9
9
  spec.email = ['colleen@puppetlabs.com']
10
10
  spec.summary = %q{Puppet Module Synchronizer}
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "aruba"
21
23
 
22
24
  spec.add_runtime_dependency 'git', '~>1.2'
23
25
  spec.add_runtime_dependency 'puppet-blacksmith', '~>3.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulesync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-30 00:00:00.000000000 Z
12
+ date: 2015-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
30
62
  - !ruby/object:Gem::Dependency
31
63
  name: git
32
64
  requirement: !ruby/object:Gem::Requirement
@@ -68,12 +100,16 @@ extensions: []
68
100
  extra_rdoc_files: []
69
101
  files:
70
102
  - .gitignore
103
+ - .travis.yml
71
104
  - CHANGELOG.md
72
105
  - Gemfile
73
106
  - LICENSE
74
107
  - README.md
108
+ - Rakefile
75
109
  - bin/msync
76
110
  - contrib/openstack-commit-msg-hook.sh
111
+ - features/support/env.rb
112
+ - features/update.feature
77
113
  - lib/modulesync.rb
78
114
  - lib/modulesync/cli.rb
79
115
  - lib/modulesync/constants.rb
@@ -107,4 +143,6 @@ rubygems_version: 1.8.23
107
143
  signing_key:
108
144
  specification_version: 3
109
145
  summary: Puppet Module Synchronizer
110
- test_files: []
146
+ test_files:
147
+ - features/support/env.rb
148
+ - features/update.feature