diff --git a/lib/models/arguments.rb b/lib/models/arguments.rb index 7ae5adb..d9fc3d8 100644 --- a/lib/models/arguments.rb +++ b/lib/models/arguments.rb @@ -24,18 +24,17 @@ class Arguments arguments.concat(["--custom-transformers", *@custom_transformers]) if @custom_transformers.length.positive? - # rng = ENV["CI"] ? Random.new(0) : Random.new - rng = Random.new(0) + rng = Random.new set_output( "args", arguments.map do |a| value = a.include?(" ") ? a.inspect : a - + unless value.start_with?("--") - name = "variable_#{rng.rand(0..1000)}" + name = "variable_#{rng.rand(1000..9999)}" set_environment(name, value) - + value = "$#{name}" end diff --git a/spec/models/arguments_spec.rb b/spec/models/arguments_spec.rb index 350ff45..48ef05d 100644 --- a/spec/models/arguments_spec.rb +++ b/spec/models/arguments_spec.rb @@ -54,8 +54,8 @@ RSpec.describe Arguments do let(:output) { ["--option", "value"] } it "writes an output variable" do - expect(arguments).to receive(:set_output).with("args", "--option $variable_1") - expect(arguments).to receive(:set_environment).with("variable_684", "value") + expect(arguments).to receive(:set_output).with("args", /--option \$variable_\d{4}/) + expect(arguments).to receive(:set_environment).with(/variable_\d{4}/, "value") subject end end @@ -64,7 +64,8 @@ RSpec.describe Arguments do let(:output) { ["--option", "some value"] } it "writes an output variable" do - expect(arguments).to receive(:set_output).with("args", "--option \"some value\"") + expect(arguments).to receive(:set_output).with("args", /--option \$variable_\d{4}/) + expect(arguments).to receive(:set_environment).with(/variable_\d{4}/, "\"some value\"") subject end end @@ -74,7 +75,10 @@ RSpec.describe Arguments do let(:options) { { "custom-transformers" => "transformers/**/*.rb" } } it "writes an output variable" do - expect(arguments).to receive(:set_output).with("args", "--option value --custom-transformers transformers/**/*.rb") + expect(arguments).to receive(:set_output).with("args", /--option \$variable_\d{4} --custom-transformers \$variable_\d{4}/) + ["value", "transformers/**/*.rb"].each do |value| + expect(arguments).to receive(:set_environment).with(/variable_\d{4}/, value) + end subject end end @@ -88,7 +92,11 @@ RSpec.describe Arguments do end it "writes an output variable" do - expect(arguments).to receive(:set_output).with("args", "--option value --custom-transformers transformers/jenkins/transformers.rb transformers/all.rb") + expect(arguments).to receive(:set_output).with("args", /--option \$variable_\d{4} --custom-transformers \$variable_\d{4} \$variable_\d{4}/) + ["value", *files].each do |value| + expect(arguments).to receive(:set_environment).with(/variable_\d{4}/, value) + end + subject end end