Skip to content

Commit

Permalink
Merge branch 'master' into before
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanratcliffe authored Feb 27, 2018
2 parents c547c95 + 1a45f54 commit a5d1a45
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
6 changes: 3 additions & 3 deletions features/cache.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ Feature: Create and maintain a .onceover cache
And the cache should contain all controlrepo files

Scenario: Creating a new file
Given control repo "caching"
Given existing control repo "caching"
When I create a file "example.txt"
And I run onceover command "run spec"
Then "example.txt" should be cached correctly

Scenario: Deleting a file
Given control repo "caching"
Given existing control repo "caching"
When I delete a file "deleteme.txt"
And I run onceover command "run spec"
Then "deleteme.txt" should be deleted from the cache

Scenario: Caching hidden files
Given control repo "caching"
Given existing control repo "caching"
When I create a file ".hidden/.hiddenfile"
And I run onceover command "run spec"
Then ".hidden/.hiddenfile" should be cached correctly
5 changes: 5 additions & 0 deletions features/step_definitions/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
FileUtils.cp_r "spec/fixtures/controlrepos/#{controlrepo_name}", @repo.tmp_folder
end

Given(/^existing control repo "([^"]*)"$/) do |controlrepo_name|
@repo = ControlRepo_Helper.new( controlrepo_name )
@cmd.controlrepo = @repo
end

Given(/^initialized control repo "([^"]*)"$/) do |controlrepo_name|
step %Q(control repo "#{controlrepo_name}")
step %Q(I run onceover command "init")
Expand Down
25 changes: 23 additions & 2 deletions lib/onceover/testconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ def deploy_local(repo = Onceover::Controlrepo.new, opts = {})
FileUtils.cp(file,"#{temp_controlrepo}/#{(file.relative_path_from(Pathname(repo.root))).to_s}")
end

logger.debug "Writing manifest of copied controlrepo files"
require 'json'
# Create a manifest of all files that were in the original repo
manifest = controlrepo_files.map do |file|
# Make sure the paths are relative so they remain relevant when used later
file.relative_path_from(Pathname(repo.root)).to_s
end
# Write all but the first as this is the root and we don't care about that
File.write("#{temp_controlrepo}/.onceover_manifest.json",manifest[1..-1].to_json)

# When using puppetfile vs deploy with r10k, we want to respect the :control_branch
# located in the Puppetfile. To accomplish that, we use git and find the current
# branch name, then replace strings within the staged puppetfile, prior to copying.
Expand All @@ -228,11 +238,22 @@ def deploy_local(repo = Onceover::Controlrepo.new, opts = {})
new_puppetfile_contents = puppetfile_contents.gsub(/:control_branch/, "'#{git_branch}'")
File.write("#{temp_controlrepo}/Puppetfile", new_puppetfile_contents)


# Remove all files written by the laste onceover run, but not the ones
# added by r10k, because that's what we are trying to cache but we don't
# know what they are
old_manifest_path = "#{repo.tempdir}/#{repo.environmentpath}/production/.onceover_manifest.json"
if File.exist? old_manifest_path
logger.debug "Found manifest from previous run, parsing..."
old_manifest = JSON.parse(File.read(old_manifest_path))
logger.debug "Removing #{old_manifest.count} files"
old_manifest.reverse.each do |file|
FileUtils.rm_f(File.join("#{repo.tempdir}/#{repo.environmentpath}/production/",file))
end
end
FileUtils.mkdir_p("#{repo.tempdir}/#{repo.environmentpath}")

logger.debug "Copying #{temp_controlrepo} to #{repo.tempdir}/#{repo.environmentpath}/production"
FileUtils.cp_r(temp_controlrepo, "#{repo.tempdir}/#{repo.environmentpath}/production")
FileUtils.cp_r("#{temp_controlrepo}/.", "#{repo.tempdir}/#{repo.environmentpath}/production")
FileUtils.rm_rf(temp_controlrepo)

# Pull the trigger! If it's not already been pulled
Expand Down
2 changes: 1 addition & 1 deletion onceover.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = "onceover"
s.version = "3.3.2"
s.version = "3.3.3"
s.authors = ["Dylan Ratcliffe"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/dylanratcliffe/onceover"
Expand Down

0 comments on commit a5d1a45

Please sign in to comment.