Skip to content
Browse files

Merge pull request #266 from travis-ci/ps-announce-env-vars-sources

Announce the source of env vars
  • Loading branch information...
2 parents d7497cb + b48a0fe commit 7e44ad789e62c16a5b6651065f9ecfd0fe321b48 @joshk joshk committed Jul 21, 2014
Showing with 45 additions and 4 deletions.
  1. +4 −0 lib/travis/build/data.rb
  2. +18 −2 lib/travis/build/data/env.rb
  3. +7 −2 lib/travis/build/script.rb
  4. +16 −0 spec/shared/script.rb
View
4 lib/travis/build/data.rb
@@ -72,6 +72,10 @@ def env_vars
@env_vars ||= Env.new(self).vars
end
+ def env_vars_groups
+ @env_vars_groups ||= Env.new(self).vars_groups
+ end
+
def raw_env_vars
data[:env_vars] || []
end
View
20 lib/travis/build/data/env.rb
@@ -7,14 +7,30 @@ class Data
class Env
delegate :secure_env_enabled?, :pull_request, :config, :build, :job, :repository, to: :data
+ class Group < Struct.new(:source, :vars)
+ def initialize(source, vars)
+ super(source, vars || [])
+ end
+
+ def announce?
+ source != 'travis' && vars.length > 0
+ end
+ end
+
attr_reader :data
def initialize(data)
@data = data
end
def vars
- travis_vars + api_vars + config_vars
+ travis_vars + settings_vars + config_vars
+ end
+
+ def vars_groups
+ [Group.new('travis', travis_vars),
+ Group.new('repository settings', settings_vars),
+ Group.new('.travis.yml', config_vars)]
end
private
@@ -47,7 +63,7 @@ def config_vars
extract_config_vars(config[:global_env]) + extract_config_vars(config[:env])
end
- def api_vars
+ def settings_vars
data.raw_env_vars.map { |var| Var.new(var[:name], var[:value], !var[:public]) }
end
View
9 lib/travis/build/script.rb
@@ -97,8 +97,13 @@ def export
set 'CI', 'true', echo: false
set 'CONTINUOUS_INTEGRATION', 'true', echo: false
set 'HAS_JOSH_K_SEAL_OF_APPROVAL', 'true', echo: false
- data.env_vars.each do |var|
- set var.key, var.value, echo: var.to_s
+ data.env_vars_groups.each do |group|
+ if group.announce?
+ cmd "echo -e \"\n\033[33;1mSetting environment variables from #{group.source}\033[0m\"; ", assert: false, echo: false
+ end
+ group.vars.each do |var|
+ set var.key, var.value, echo: var.to_s
+ end
end
if data.env_vars.any?
# adds a newline to the log
View
16 spec/shared/script.rb
@@ -9,6 +9,22 @@
let(:env_type) { 'global_env' }
end
+ it 'announces setting environment variables from settings' do
+ data['config']['env'] = nil
+ data['config']['global_env'] = nil
+ data['env_vars'] = [{ 'name' => 'SETTINGS_VAR', 'value' => 'a value', 'public' => false }]
+ is_expected.to echo 'export SETTINGS_VAR=[secure]'
+ is_expected.to run /Setting environment variables from repository settings/
+ is_expected.not_to run /Setting environment variables from .travis.yml/
+ end
+
+ it 'announces setting environment variables from config' do
+ data['config']['global_env'] = 'SECURE CONFIG_VAR=value'
+ is_expected.to echo 'export CONFIG_VAR=[secure]'
+ is_expected.not_to run /Setting environment variables from repository settings/
+ is_expected.to run /Setting environment variables from .travis.yml/
+ end
+
it 'sets TRAVIS_* env vars' do
data['config']['env'].delete_if { |var| var =~ /SECURE / }

0 comments on commit 7e44ad7

Please sign in to comment.
Something went wrong with that request. Please try again.