Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/voxpupuli/modulesync into…
Browse files Browse the repository at this point in the history
… fix_moduleroot_rubocop
  • Loading branch information
james.powis committed Mar 2, 2017
2 parents c249742 + 7ddc50d commit 41ef2e6
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.0
Exclude:
- 'vendor/**/*'
- 'tmp/**/*'
- 'pkg/**/*'
- 'lib/monkey_patches.rb'

# we still support ruby 1.8
Style/HashSyntax:
Enabled: false

Expand Down
23 changes: 20 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@
sudo: false
language: ruby
cache: bundler
dist: trusty
before_install:
- gem update --system
- gem install bundler
script: 'bundle exec rake test'
rvm:
- 1.9.3
- 2.0
- 2.1
- 2.2
- 2.1.9
- 2.2.6
- 2.3.3
- 2.4.0
notifications:
email: false
deploy:
provider: rubygems
api_key:
secure: "Tbf1EbLEobIIox+fftJZADZsfQQ6kl0urcMNetK7NJzFo/negD/WyJIUj3kro/B7buyYADEjTui/JR4o8EPbugfM3ie5vYOd5k3AesSzbdr4BSwGe/cGbGOB7/PZuGfFLkb94/FiCU2mIwibkbh1rHWGlBoPj7ntL0+5ZtdvsM4="
gem: modulesync
on:
rvm: 2.4.0
tags: true
all_branches: true
repo: voxpupuli/modulesync
50 changes: 44 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
##2015-08-13 - 0.6.1
# Changelog

## 2017-02-13 - 0.7.2

Fixes an issue releasing 0.7.1, no functional changes.

## 2017-02-13 - 0.7.1

Fixes an issue releasing 0.7.0, no functional changes.

## 2017-02-13 - 0.7.0

### Summary

This is the first release from Vox Pupuli, which has taken over maintenance of
modulesync.

#### Features
- New `msync update` arguments:
- `--git-base` to override `git_base`, e.g. for read-only git clones
- `-s` to skip the current module and continue on error
- `-x` for a negative filter (blacklist) of modules not to update
- Add `-a` argument to `msync hook` to pass additional arguments
- Add `:git_base` and `:namespace` data to `@configs` hash
- Allow `managed_modules.yml` to list modules with a different namespace
- Entire directories can be listed with `unmanaged: true`

#### Refactoring
- Replace CLI optionparser with thor

#### Bugfixes
- Fix git 1.8.0 compatibility, detecting when no files are changed
- Fix `delete: true` feature, now deletes files correctly
- Fix handling of `:global` config entries, not interpreted as a path
- Fix push without force to remote branch when no files have changed (#102)
- Output template name when ERB rendering fails
- Remove extraneous whitespace in `--noop` output

## 2015-08-13 - 0.6.1

### Summary

Expand Down Expand Up @@ -27,7 +65,7 @@ This release adds two new flags to help modulesync better integrate with CI tool

- Added tests

##2015-06-30 - 0.5.0
## 2015-06-30 - 0.5.0

### Summary

Expand All @@ -37,7 +75,7 @@ This release adds the ability to sync a non-bare local git repo.

- Allow one to sync non-bare local git repository

##2015-06-24 - 0.4.0
## 2015-06-24 - 0.4.0

### Summary

Expand All @@ -53,7 +91,7 @@ config.

- Fix markdown syntax in README

##2015-03-12 - 0.3.0
## 2015-03-12 - 0.3.0

### Summary

Expand Down Expand Up @@ -87,14 +125,14 @@ number of new flags for updating modules.
- Fix non-master branch functionality
- Add workarounds for older git versions

##2014-11-16 - 0.2.0
## 2014-11-16 - 0.2.0

### Summary

This release adds the --filter flag to filter what modules to sync.
Also fixes the README to document the very important -m flag.

##2014-9-29 - 0.1.0
## 2014-9-29 - 0.1.0

### Summary

Expand Down
5 changes: 0 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

if ENV['TRAVIS_RUBY_VERSION'] && ENV['TRAVIS_RUBY_VERSION'] == '1.9.3'
gem 'json_pure', '~> 1.0'
gem 'rubocop', '< 0.42.0'
end

gemspec
24 changes: 24 additions & 0 deletions features/step_definitions/git_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Given 'a mocked git configuration' do
steps %(
Given a mocked home directory
And I run `git config --global user.name Test`
And I run `git config --global user.email [email protected]`
)
end

Given 'a remote module repository' do
steps %(
Given a directory named "sources"
And I run `git clone https://github.com/maestrodev/puppet-test sources/puppet-test`
And a file named "managed_modules.yml" with:
"""
---
- puppet-test
"""
)
write_file('modulesync.yml', <<-EOS)
---
namespace: sources
git_base: file://#{expand_path('.')}/
EOS
end
82 changes: 78 additions & 4 deletions features/update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ Feature: update
When I run `msync update --noop`
Then the exit status should be 1

Scenario: Using skip_broken option with invalid files
Given a file named "managed_modules.yml" with:
"""
---
- puppet-test
"""
And a file named "modulesync.yml" with:
"""
---
namespace: maestrodev
git_base: https://github.com/
"""
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a directory named "moduleroot"
And a file named "moduleroot/test" with:
"""
<% @configs.each do |c| -%>
<%= c['name'] %>
<% end %>
"""
When I run `msync update --noop -s`
Then the exit status should be 0

Scenario: Modifying an existing file
Given a file named "managed_modules.yml" with:
"""
Expand Down Expand Up @@ -98,6 +126,29 @@ Feature: update
source 'https://somehost.com'
"""

Scenario: Modifying an existing file and committing the change
Given a mocked git configuration
And a remote module repository
And a file named "config_defaults.yml" with:
"""
---
Gemfile:
gem_source: https://somehost.com
"""
And a directory named "moduleroot"
And a file named "moduleroot/Gemfile" with:
"""
source '<%= @configs['gem_source'] %>'
"""
When I run `msync update -m "Update Gemfile" -r test`
Then the exit status should be 0
Given I cd to "sources/puppet-test"
And I run `git checkout test`
Then the file "Gemfile" should contain:
"""
source 'https://somehost.com'
"""

Scenario: Setting an existing file to unmanaged
Given a file named "managed_modules.yml" with:
"""
Expand Down Expand Up @@ -210,13 +261,13 @@ Feature: update
spec:
unmanaged: true
"""
And a directory named "moduleroot"
And a directory named "moduleroot/spec"
And a file named "moduleroot/spec/spec_helper.rb" with:
"""
some spec_helper fud
"""
And a directory named "modules/puppetlabs-apache/spec"
And a file named "modules/puppetlabs-apache/spec_helper.rb" with:
And a file named "modules/puppetlabs-apache/spec/spec_helper.rb" with:
"""
This is a fake spec_helper!
"""
Expand All @@ -227,10 +278,11 @@ Feature: update
"""
And the exit status should be 0
Given I run `cat modules/puppetlabs-apache/spec/spec_helper.rb`
Then the output should not contain:
Then the output should contain:
"""
some spec_helper fud
This is a fake spec_helper!
"""
And the exit status should be 0

Scenario: Adding a new file in a new subdirectory
Given a file named "managed_modules.yml" with:
Expand Down Expand Up @@ -694,3 +746,25 @@ Feature: update
"""
echo 'https://github.com/maestrodev'
"""

Scenario: Running the same update twice and pushing to a remote branch
Given a mocked git configuration
And a remote module repository
And a file named "config_defaults.yml" with:
"""
---
Gemfile:
gem_source: https://somehost.com
"""
And a directory named "moduleroot"
And a file named "moduleroot/Gemfile" with:
"""
source '<%= @configs['gem_source'] %>'
"""
When I run `msync update -m "Update Gemfile" -r test`
Then the exit status should be 0
Given I remove the directory "modules"
When I run `msync update -m "Update Gemfile" -r test`
Then the exit status should be 0
Then the output should not contain "error"
Then the output should not contain "rejected"
63 changes: 37 additions & 26 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'modulesync/renderer'
require 'modulesync/settings'
require 'modulesync/util'
require 'monkey_patches'

module ModuleSync
include Constants
Expand Down Expand Up @@ -86,6 +87,36 @@ def self.manage_file(filename, settings, options)
end
end

def self.manage_module(puppet_module, module_files, module_options, defaults, options)
puts "Syncing #{puppet_module}"
namespace, module_name = self.module_name(puppet_module, options[:namespace])
unless options[:offline]
git_base = options[:git_base]
git_uri = "#{git_base}#{namespace}"
Git.pull(git_uri, module_name, options[:branch], options[:project_root], module_options || {})
end
module_configs = Util.parse_config("#{options[:project_root]}/#{module_name}/#{MODULE_CONF_FILE}")
settings = Settings.new(defaults[GLOBAL_DEFAULTS_KEY] || {},
defaults,
module_configs[GLOBAL_DEFAULTS_KEY] || {},
module_configs,
:puppet_module => module_name,
:git_base => git_base,
:namespace => namespace)
settings.unmanaged_files(module_files).each do |filename|
puts "Not managing #{filename} in #{module_name}"
end

files_to_manage = settings.managed_files(module_files)
files_to_manage.each { |filename| manage_file(filename, settings, options) }

if options[:noop]
Git.update_noop(module_name, options)
elsif !options[:offline]
Git.update(module_name, files_to_manage, options)
end
end

def self.update(options)
options = config_defaults.merge(options)
defaults = Util.parse_config("#{options[:configs]}/#{CONF_FILE}")
Expand All @@ -98,32 +129,12 @@ def self.update(options)

# managed_modules is either an array or a hash
managed_modules.each do |puppet_module, module_options|
puts "Syncing #{puppet_module}"
namespace, module_name = self.module_name(puppet_module, options[:namespace])
unless options[:offline]
git_base = options[:git_base]
git_uri = "#{git_base}#{namespace}"
Git.pull(git_uri, module_name, options[:branch], options[:project_root], module_options || {})
end
module_configs = Util.parse_config("#{options[:project_root]}/#{module_name}/#{MODULE_CONF_FILE}")
settings = Settings.new(defaults[GLOBAL_DEFAULTS_KEY] || {},
defaults,
module_configs[GLOBAL_DEFAULTS_KEY] || {},
module_configs,
:puppet_module => module_name,
:git_base => git_base,
:namespace => namespace)
settings.unmanaged_files(module_files).each do |filename|
puts "Not managing #{filename} in #{module_name}"
end

files_to_manage = settings.managed_files(module_files)
files_to_manage.each { |filename| manage_file(filename, settings, options) }

if options[:noop]
Git.update_noop(module_name, options)
elsif !options[:offline]
Git.update(module_name, files_to_manage, options)
begin
manage_module(puppet_module, module_files, module_options, defaults, options)
rescue
STDERR.puts "Error while updating #{puppet_module}"
raise unless options[:skip_broken]
puts "Skipping #{puppet_module} as update process failed"
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/modulesync/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Base < Thor
option :message, :aliases => '-m', :desc => 'Commit message to apply to updated modules. Required unless running in noop mode.'
option :configs, :aliases => '-c', :desc => 'The local directory or remote repository to define the list of managed modules, the file templates, and the default values for template variables.'
option :remote_branch, :aliases => '-r', :desc => 'Remote branch name to push the changes to. Defaults to the branch name.'
option :skip_broken, :type => :boolean, :aliases => '-s', :desc => 'Process remaining modules if an error is found', :default => false
option :amend, :type => :boolean, :desc => 'Amend previous commit', :default => false
option :force, :type => :boolean, :desc => 'Force push amended commit', :default => false
option :noop, :type => :boolean, :desc => 'No-op mode', :default => false
Expand Down
Loading

0 comments on commit 41ef2e6

Please sign in to comment.