Skip to content

Commit 6ca001b

Browse files
authored
Ruby upgrade 3.4 changes (#280)
* trying to add ruby 3.4 pipeline in chef-cli Signed-off-by: nikhil2611 <[email protected]> * updating code to work with ruby 3.1 and 3.4 Signed-off-by: nikhil2611 <[email protected]> * chefstyle fixes Signed-off-by: nikhil2611 <[email protected]> * codeQL security fix Signed-off-by: nikhil2611 <[email protected]> * warning fixes Signed-off-by: nikhil2611 <[email protected]> * removing non required gems Signed-off-by: nikhil2611 <[email protected]> * Updated the unit.yml with ruby 3.4 Signed-off-by: nikhil2611 <[email protected]> --------- Signed-off-by: nikhil2611 <[email protected]>
1 parent fe70131 commit 6ca001b

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

.expeditor/verify.pipeline.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ steps:
2727
docker:
2828
image: ruby:3.3
2929

30+
- label: run-specs-ruby-3.4
31+
command:
32+
- .expeditor/run_linux_tests.sh rspec
33+
expeditor:
34+
executor:
35+
docker:
36+
image: ruby:3.4
37+
3038
- label: run-specs-windows-3.1
3139
command:
3240
- powershell .expeditor/run_windows_tests.ps1 rspec
@@ -46,6 +54,16 @@ steps:
4654
shell: ["powershell", "-Command"]
4755
image: rubydistros/windows-2019:3.3
4856

57+
- label: run-specs-windows-ruby-3.4
58+
command:
59+
- powershell .expeditor/run_windows_tests.ps1 rspec
60+
expeditor:
61+
executor:
62+
docker:
63+
host_os: windows
64+
shell: ["powershell", "-Command"]
65+
image: rubydistros/windows-2019:3.4
66+
4967
- label: cookstyle-generator-cb-tests-ruby-3.1
5068
command:
5169
- .expeditor/run_linux_tests.sh "rake style:cookstyle"
@@ -54,10 +72,26 @@ steps:
5472
docker:
5573
image: ruby:3.1
5674

75+
- label: cookstyle-generator-cb-tests-ruby-3.4
76+
command:
77+
- .expeditor/run_linux_tests.sh "rake style:cookstyle"
78+
expeditor:
79+
executor:
80+
docker:
81+
image: ruby:3.4
82+
5783
- label: chefstyle-tests-ruby-3.1
5884
command:
5985
- .expeditor/run_linux_tests.sh "rake style:chefstyle"
6086
expeditor:
6187
executor:
6288
docker:
6389
image: ruby:3.1
90+
91+
- label: chefstyle-tests-ruby-3.4
92+
command:
93+
- .expeditor/run_linux_tests.sh "rake style:chefstyle"
94+
expeditor:
95+
executor:
96+
docker:
97+
image: ruby:3.4

.github/workflows/unit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4
20-
- name: Set up ruby 3.1
20+
- name: Set up ruby 3.4
2121
uses: ruby/setup-ruby@v1
2222
with:
23-
ruby-version: 3.1
23+
ruby-version: 3.4
2424
bundler-cache: true
2525
- name: run specs
2626
run: bundle exec rake spec --trace

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ gemspec
44

55
gem "logger", "< 1.6" # 1.6 causes errors with mixlib-log < 3.1.1
66
gem "chefspec"
7+
gem "syslog"
8+
79
group :test do
810
gem "rake"
911
gem "rspec", "=3.12.0"

lib/chef-cli/policyfile/cookbook_location_specification.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def valid?
8989
def errors
9090
error_messages = []
9191
if source_options_invalid?
92-
error_messages << "Cookbook `#{name}' has invalid source options `#{source_options.inspect}'"
92+
formatted_opts = source_options.map { |k, v| "#{k.inspect}=>#{v.inspect}" }.join(", ")
93+
error_messages << "Cookbook `#{name}' has invalid source options `{#{formatted_opts}}'"
9394
end
9495
error_messages
9596
end

lib/chef-cli/policyfile/dsl.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@ def cookbook(name, *version_and_source_opts)
110110
else
111111
{}
112112
end
113-
114113
constraint = version_and_source_opts.first || ">= 0.0.0"
115114
spec = CookbookLocationSpecification.new(name, constraint, source_options, storage_config)
116115

117116
if ( existing_source = @cookbook_location_specs[name] )
118117
err = "Cookbook '#{name}' assigned to conflicting sources\n\n"
119-
err << "Previous source: #{existing_source.source_options.inspect}\n"
120-
err << "Conflicts with: #{source_options.inspect}\n"
118+
err << "Previous source: {" + existing_source.source_options.map { |k, v| "#{k.inspect}=>#{v.inspect}" }.join(", ") + "}\n"
119+
err << "Conflicts with: {" + source_options.map { |k, v| "#{k.inspect}=>#{v.inspect}" }.join(", ") + "}\n"
121120
@errors << err
122121
else
123122
@cookbook_location_specs[name] = spec
@@ -179,8 +178,11 @@ def eval_policyfile(policyfile_string)
179178
error_message << " #{error_context(policyfile_string, policyfile_filename, e)}\n\n"
180179
unless trace.empty?
181180
error_message << " Backtrace:\n"
181+
normalized_trace = trace.map do |line|
182+
line.gsub(/:in ['"]?(?:.*[#.]?)?(eval_policyfile)['"]?/, ":in `\\1'")
183+
end
182184
# TODO: need a way to disable filtering
183-
error_message << filtered_bt(policyfile_filename, e).inject("") { |formatted_trace, line| formatted_trace << " #{line}\n" }
185+
error_message << normalized_trace.inject("") { |formatted_trace, line| formatted_trace << " #{line}\n" }
184186
end
185187
@errors << error_message
186188
end

lib/chef-cli/policyfile_compiler.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ def install
194194
unless missing_recipes_by_cb_spec.empty?
195195
message = "The installed cookbooks do not contain all the recipes required by your run list(s):\n"
196196
missing_recipes_by_cb_spec.each do |spec, missing_items|
197-
message << "#{spec}\nis missing the following required recipes:\n"
197+
formatted_opts = "{" + spec.source_options.map { |k, v| "#{k.inspect}=>#{v.inspect}" }.join(", ") + "}"
198+
message << "Cookbook '#{spec.name}' = #{spec.version} #{formatted_opts}\n"
199+
message << "is missing the following required recipes:\n"
200+
198201
missing_items.each { |_cb, recipe| message << "* #{recipe}\n" }
199202
end
200203

spec/unit/policyfile_demands_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209

210210
instance_double("ChefCLI::Policyfile::CookbookLocationSpecification",
211211
name: "remote-cb",
212+
version: "1.1.1",
213+
source_options: remote_cb_source_opts,
212214
version_constraint: Semverse::Constraint.new("= 1.1.1"),
213215
ensure_cached: nil,
214216
to_s: s)

0 commit comments

Comments
 (0)