Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jeremymv2/chef sugar fix default #42

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,6 @@ knife tidy backup clean --backup-path backups/ --gsub-file substitutions.json

```json
{
"chef-sugar":{
"organizations/*/cookbooks/chef-sugar*/metadata.rb":[
{
"pattern":"^require .*/lib/chef/sugar/version",
"replace":"# require File.expand_path('../lib/chef/sugar/version', *__FILE__)"
},
{
"pattern":"version *Chef::Sugar::VERSION",
"replace":"version !COOKBOOK_VERSION!"
}
]
},
"io-read-version-and-readme.md":{
"organizations/*/cookbooks/*/metadata.rb":[
{
Expand Down
20 changes: 2 additions & 18 deletions conf/substitutions.json.example
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
{
"chef-sugar":{
"organizations/*/cookbooks/chef-sugar*/metadata.rb":[
{
"pattern":"^require .*/lib/chef/sugar/version",
"replace":"# require File.expand_path('../lib/chef/sugar/version', *__FILE__)"
},
{
"pattern":"version *Chef::Sugar::VERSION",
"replace":"version !COOKBOOK_VERSION!"
}
]
},
"io-read-version-and-readme.md":{
"your-problem-descriptor":{
"organizations/*/cookbooks/*/metadata.rb":[
{
"pattern":"^version +IO.read.* 'VERSION'.*",
"pattern":"^version .*GO_PIPELINE_LABEL",
"replace":"version !COOKBOOK_VERSION!"
},
{
"pattern":"^long_description +IO.read.* 'README.md'.*",
"replace":"#long_description \"A Long Description..\""
}
]
}
Expand Down
23 changes: 23 additions & 0 deletions lib/chef/knife/tidy_backup_clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def run
exit 1
end

fix_chef_sugar_metadata

Chef::TidySubstitutions.new(substitutions_file, tidy).run_substitutions if config[:gsub_file]

validate_user_emails
Expand Down Expand Up @@ -187,6 +189,27 @@ def generate_new_metadata(org)
end
end

def fix_chef_sugar_metadata
Dir[::File.join(tidy.backup_path, 'organizations/*/cookbooks/chef-sugar*/metadata.rb')].each do |file|
puts 'INFO: Searching for known chef-sugar problems when uploading.'
s = Chef::TidySubstitutions.new
version = s.cookbook_version_from_path(file)
patterns = [
{
search: '^require .*/lib/chef/sugar/version',
replace: "# require File.expand_path('../lib/chef/sugar/version', *__FILE__)"
},
{
search: '^version *Chef::Sugar::VERSION',
replace: "version '#{version}'"
}
]
patterns.each do |p|
s.sub_in_file(file, Regexp.new(p[:search]), p[:replace])
end
end
end

def fix_self_dependencies(org)
for_each_cookbook_path(org) do |cookbook_path|
name = tidy.cookbook_name_from_path(cookbook_path)
Expand Down