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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action][ensure_env_vars] efficiency improvement #18522

Merged
merged 3 commits into from Apr 12, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions fastlane/lib/fastlane/actions/ensure_env_vars.rb
Expand Up @@ -3,15 +3,11 @@ module Actions
class EnsureEnvVarsAction < Action
def self.run(params)
variables = params[:env_vars]
missing_variables = variables.select { |variable| ENV[variable].to_s.strip.empty? }

variables.each do |variable|
next unless ENV[variable].to_s.strip.empty?

UI.user_error!("Missing environment variable '#{variable}'")
end
UI.user_error!("Missing environment variable(s) '#{missing_variables.join('\', \'')}'") unless missing_variables.empty?

is_one = variables.length == 1

UI.success("Environment variable#{is_one ? '' : 's'} '#{variables.join('\', \'')}' #{is_one ? 'is' : 'are'} set!")
end

Expand Down
16 changes: 14 additions & 2 deletions fastlane/spec/actions_specs/ensure_env_vars_spec.rb
Expand Up @@ -41,7 +41,19 @@
ensure_env_vars(env_vars: [\'MISSING\'])
end').runner.execute(:test)
end.to raise_error(FastlaneCore::Interface::FastlaneError) do |error|
expect(error.message).to eq('Missing environment variable \'MISSING\'')
expect(error.message).to eq('Missing environment variable(s) \'MISSING\'')
end
end
end

context 'and multiple env vars are not set' do
it 'outputs error message' do
expect do
Fastlane::FastFile.new.parse('lane :test do
ensure_env_vars(env_vars: [\'MISSING_FIRST\', \'MISSING_SECOND\'])
end').runner.execute(:test)
end.to raise_error(FastlaneCore::Interface::FastlaneError) do |error|
expect(error.message).to eq('Missing environment variable(s) \'MISSING_FIRST\', \'MISSING_SECOND\'')
end
end
end
Expand All @@ -57,7 +69,7 @@
ensure_env_vars(env_vars: [\'MISSING\'])
end').runner.execute(:test)
end.to raise_error(FastlaneCore::Interface::FastlaneError) do |error|
expect(error.message).to eq('Missing environment variable \'MISSING\'')
expect(error.message).to eq('Missing environment variable(s) \'MISSING\'')
end
end
end
Expand Down