Write to random env variables
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module EnvironmentWriter
|
||||||
|
def set_output(name, value)
|
||||||
|
modify_env("GITHUB_OUTPUT", name, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_environment(name, value)
|
||||||
|
modify_env("GITHUB_ENV", name, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def modify_env(file, name, value)
|
||||||
|
return if value.nil?
|
||||||
|
|
||||||
|
File.open(ENV[file], "a") do |f|
|
||||||
|
f.puts "#{name}=#{value}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module OutputWriter
|
|
||||||
def set_output(name, value)
|
|
||||||
return if value.nil?
|
|
||||||
|
|
||||||
File.open(ENV["GITHUB_OUTPUT"], "a") do |f|
|
|
||||||
f.puts "#{name}=#{value}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
+14
-4
@@ -1,9 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "../concerns/output_writer"
|
require_relative "../concerns/environment_writer"
|
||||||
|
|
||||||
class Arguments
|
class Arguments
|
||||||
include OutputWriter
|
include EnvironmentWriter
|
||||||
|
|
||||||
def initialize(provider, command, issue_content)
|
def initialize(provider, command, issue_content)
|
||||||
@args = argument_class(provider, command, issue_content)
|
@args = argument_class(provider, command, issue_content)
|
||||||
@@ -24,12 +24,22 @@ class Arguments
|
|||||||
|
|
||||||
arguments.concat(["--custom-transformers", *@custom_transformers]) if @custom_transformers.length.positive?
|
arguments.concat(["--custom-transformers", *@custom_transformers]) if @custom_transformers.length.positive?
|
||||||
|
|
||||||
|
# rng = ENV["CI"] ? Random.new(0) : Random.new
|
||||||
|
rng = Random.new(0)
|
||||||
|
|
||||||
set_output(
|
set_output(
|
||||||
"args",
|
"args",
|
||||||
arguments.map do |a|
|
arguments.map do |a|
|
||||||
next a unless a.include?(" ")
|
value = a.include?(" ") ? a.inspect : a
|
||||||
|
|
||||||
a.inspect
|
unless value.start_with?("--")
|
||||||
|
name = "variable_#{rng.rand(0..1000)}"
|
||||||
|
set_environment(name, value)
|
||||||
|
|
||||||
|
value = "$#{name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
value
|
||||||
end.join(" ")
|
end.join(" ")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "active_support/core_ext/string"
|
require "active_support/core_ext/string"
|
||||||
require_relative "../concerns/output_writer"
|
require_relative "../concerns/environment_writer"
|
||||||
|
|
||||||
class Command
|
class Command
|
||||||
include OutputWriter
|
include EnvironmentWriter
|
||||||
|
|
||||||
VALID_COMMANDS = %w[audit migrate dry-run].freeze
|
VALID_COMMANDS = %w[audit migrate dry-run].freeze
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ require_rel "./jenkins/**/*.rb"
|
|||||||
require_rel "./travis_ci/**/*.rb"
|
require_rel "./travis_ci/**/*.rb"
|
||||||
|
|
||||||
class Provider
|
class Provider
|
||||||
include OutputWriter
|
include EnvironmentWriter
|
||||||
|
|
||||||
PROVIDER_MAP = {
|
PROVIDER_MAP = {
|
||||||
"azure-devops" => ::AzureDevops,
|
"azure-devops" => ::AzureDevops,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe OutputWriter do
|
RSpec.describe EnvironmentWriter do
|
||||||
let(:test_class) do
|
let(:test_class) do
|
||||||
class TestClass
|
class TestClass
|
||||||
include OutputWriter
|
include EnvironmentWriter
|
||||||
end
|
end
|
||||||
|
|
||||||
TestClass.new
|
TestClass.new
|
||||||
@@ -24,4 +24,20 @@ RSpec.describe OutputWriter do
|
|||||||
it { expect { subject }.not_to change { File.read(ENV["GITHUB_OUTPUT"], chomp: true).last } }
|
it { expect { subject }.not_to change { File.read(ENV["GITHUB_OUTPUT"], chomp: true).last } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#set_environment" do
|
||||||
|
let(:name) { "env_var_name" }
|
||||||
|
let(:value) { "env_var_value" }
|
||||||
|
let(:output) { "#{name}=#{value}" }
|
||||||
|
|
||||||
|
subject { test_class.set_environment(name, value) }
|
||||||
|
|
||||||
|
it { expect { subject }.to change { File.readlines(ENV["GITHUB_ENV"], chomp: true).last }.to(/#{output}/) }
|
||||||
|
|
||||||
|
context "when value is nil" do
|
||||||
|
let(:value) { nil }
|
||||||
|
|
||||||
|
it { expect { subject }.not_to change { File.read(ENV["GITHUB_ENV"], chomp: true).last } }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -54,7 +54,8 @@ RSpec.describe Arguments do
|
|||||||
let(:output) { ["--option", "value"] }
|
let(:output) { ["--option", "value"] }
|
||||||
|
|
||||||
it "writes an output variable" do
|
it "writes an output variable" do
|
||||||
expect(arguments).to receive(:set_output).with("args", "--option value")
|
expect(arguments).to receive(:set_output).with("args", "--option $variable_1")
|
||||||
|
expect(arguments).to receive(:set_environment).with("variable_684", "value")
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ RSpec.configure do |config|
|
|||||||
Dir.mkdir("tmp") unless Dir.exist?("tmp")
|
Dir.mkdir("tmp") unless Dir.exist?("tmp")
|
||||||
FileUtils.touch "tmp/test.txt"
|
FileUtils.touch "tmp/test.txt"
|
||||||
ENV["GITHUB_OUTPUT"] = "tmp/test.txt"
|
ENV["GITHUB_OUTPUT"] = "tmp/test.txt"
|
||||||
|
ENV["GITHUB_ENV"] = "tmp/test.txt"
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:suite) do
|
config.after(:suite) do
|
||||||
|
|||||||
Reference in New Issue
Block a user