Skip to content
Browse files

Set info ENV vars: TRAVIS_PULL_REQUEST and TRAVIS_SECURE_ENV_VARS

Those vars are set based on payload from travis, to allow easier scripting when
using secure env variables or running pull request specific code.
  • Loading branch information...
1 parent 2896153 commit 371a91ac725ca1b7ededb96549897bb515e8b716 @drogus committed Jul 5, 2012
View
3 features/support/step_definitions.rb
@@ -72,6 +72,9 @@ def decode(string)
Then /^it exports the given environment variables$/ do
+ step "it exports the line TRAVIS_PULL_REQUEST=false"
+ step "it exports the line TRAVIS_SECURE_ENV_VARS=false"
+
if $payload.config.env?
line = $payload.config.env
step "it exports the line #{line}"
View
4 features/switching_active_jdk.feature
@@ -22,6 +22,8 @@ Feature: Switching JDKs when testing a Clojure project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -59,6 +61,8 @@ Feature: Switching JDKs when testing a Clojure project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
2 features/test_clojure.feature
@@ -24,6 +24,8 @@ Feature: Testing a Clojure project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
2 features/test_clojure_with_given_jdk_version.feature
@@ -24,6 +24,8 @@ Feature: Testing a Clojure project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
32 features/test_erlang.feature
@@ -24,6 +24,8 @@ Feature: Testing an Erlang project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -48,6 +50,8 @@ Feature: Testing an Erlang project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -69,19 +73,21 @@ Feature: Testing an Erlang project
And it closes the ssh session
And it returns the result 0
And it has captured the following events
- | name | data |
- | job:test:start | started_at: [now] |
- | job:test:log | log: /Using worker/ |
- | job:test:log | log: cd ~/builds |
- | job:test:log | log: export FOO=foo |
- | job:test:log | log: git clone |
- | job:test:log | log: cd travis-ci/travis-ci |
- | job:test:log | log: git checkout |
- | job:test:log | log: /activate/ |
- | job:test:log | log: rebar get-deps |
- | job:test:log | log: /eunit/ |
- | job:test:log | log: /Done.* 0/ |
- | job:test:finish | finished_at: [now], result: 0 |
+ | name | data |
+ | job:test:start | started_at: [now] |
+ | job:test:log | log: /Using worker/ |
+ | job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false|
+ | job:test:log | log: export FOO=foo |
+ | job:test:log | log: git clone |
+ | job:test:log | log: cd travis-ci/travis-ci |
+ | job:test:log | log: git checkout |
+ | job:test:log | log: /activate/ |
+ | job:test:log | log: rebar get-deps |
+ | job:test:log | log: /eunit/ |
+ | job:test:log | log: /Done.* 0/ |
+ | job:test:finish | finished_at: [now], result: 0 |
Scenario: The repository can not be cloned
When it starts a job
View
6 features/test_groovy.feature
@@ -24,6 +24,8 @@ Feature: Testing a Groovy project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -56,6 +58,8 @@ Feature: Testing a Groovy project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -87,6 +91,8 @@ Feature: Testing a Groovy project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
6 features/test_java.feature
@@ -25,6 +25,8 @@ Feature: Testing a Java project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -56,6 +58,8 @@ Feature: Testing a Java project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -87,6 +91,8 @@ Feature: Testing a Java project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
98 features/test_nodejs.feature
@@ -23,21 +23,23 @@ Feature: Testing a Node.js project
And it closes the ssh session
And it returns the result 0
And it has captured the following events
- | name | data |
- | job:test:start | started_at: [now] |
- | job:test:log | log: /Using worker/ |
- | job:test:log | log: cd ~/builds |
- | job:test:log | log: export FOO=foo |
- | job:test:log | log: git clone |
- | job:test:log | log: cd travis-ci/travis-ci |
- | job:test:log | log: git checkout |
- | job:test:log | log: export TRAVIS_NODE_VERSION=0.4 |
- | job:test:log | log: nvm use 0.4 |
- | job:test:log | log: node --version |
- | job:test:log | log: npm --version |
- | job:test:log | log: make test |
- | job:test:log | log: /Done.* 0/ |
- | job:test:finish | finished_at: [now], result: 0 |
+ | name | data |
+ | job:test:start | started_at: [now] |
+ | job:test:log | log: /Using worker/ |
+ | job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
+ | job:test:log | log: export FOO=foo |
+ | job:test:log | log: git clone |
+ | job:test:log | log: cd travis-ci/travis-ci |
+ | job:test:log | log: git checkout |
+ | job:test:log | log: export TRAVIS_NODE_VERSION=0.4 |
+ | job:test:log | log: nvm use 0.4 |
+ | job:test:log | log: node --version |
+ | job:test:log | log: npm --version |
+ | job:test:log | log: make test |
+ | job:test:log | log: /Done.* 0/ |
+ | job:test:finish | finished_at: [now], result: 0 |
Scenario: A successful build
@@ -53,21 +55,23 @@ Feature: Testing a Node.js project
And it closes the ssh session
And it returns the result 0
And it has captured the following events
- | name | data |
- | job:test:start | started_at: [now] |
- | job:test:log | log: /Using worker/ |
- | job:test:log | log: cd ~/builds |
- | job:test:log | log: export FOO=foo |
- | job:test:log | log: git clone |
- | job:test:log | log: cd travis-ci/travis-ci |
- | job:test:log | log: git checkout |
- | job:test:log | log: export TRAVIS_NODE_VERSION=0.6.1 |
- | job:test:log | log: nvm use 0.6.1 |
- | job:test:log | log: node --version |
- | job:test:log | log: npm --version |
- | job:test:log | log: make test |
- | job:test:log | log: /Done.* 0/ |
- | job:test:finish | finished_at: [now], result: 0 |
+ | name | data |
+ | job:test:start | started_at: [now] |
+ | job:test:log | log: /Using worker/ |
+ | job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
+ | job:test:log | log: export FOO=foo |
+ | job:test:log | log: git clone |
+ | job:test:log | log: cd travis-ci/travis-ci |
+ | job:test:log | log: git checkout |
+ | job:test:log | log: export TRAVIS_NODE_VERSION=0.6.1 |
+ | job:test:log | log: nvm use 0.6.1 |
+ | job:test:log | log: node --version |
+ | job:test:log | log: npm --version |
+ | job:test:log | log: make test |
+ | job:test:log | log: /Done.* 0/ |
+ | job:test:finish | finished_at: [now], result: 0 |
Scenario: A successful build with a package.json file
When it starts a job
@@ -82,22 +86,24 @@ Feature: Testing a Node.js project
And it closes the ssh session
And it returns the result 0
And it has captured the following events
- | name | data |
- | job:test:start | started_at: [now] |
- | job:test:log | log: /Using worker/ |
- | job:test:log | log: cd ~/builds |
- | job:test:log | log: export FOO=foo |
- | job:test:log | log: git clone |
- | job:test:log | log: cd travis-ci/travis-ci |
- | job:test:log | log: git checkout |
- | job:test:log | log: export TRAVIS_NODE_VERSION=0.6.1 |
- | job:test:log | log: nvm use 0.6.1 |
- | job:test:log | log: node --version |
- | job:test:log | log: npm --version |
- | job:test:log | log: npm install --dev |
- | job:test:log | log: npm test |
- | job:test:log | log: /Done.* 0/ |
- | job:test:finish | finished_at: [now], result: 0 |
+ | name | data |
+ | job:test:start | started_at: [now] |
+ | job:test:log | log: /Using worker/ |
+ | job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
+ | job:test:log | log: export FOO=foo |
+ | job:test:log | log: git clone |
+ | job:test:log | log: cd travis-ci/travis-ci |
+ | job:test:log | log: git checkout |
+ | job:test:log | log: export TRAVIS_NODE_VERSION=0.6.1 |
+ | job:test:log | log: nvm use 0.6.1 |
+ | job:test:log | log: node --version |
+ | job:test:log | log: npm --version |
+ | job:test:log | log: npm install --dev |
+ | job:test:log | log: npm test |
+ | job:test:log | log: /Done.* 0/ |
+ | job:test:finish | finished_at: [now], result: 0 |
Scenario: The repository can not be cloned
When it starts a job
View
2 features/test_php.feature
@@ -23,6 +23,8 @@ Feature: Testing a Php project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false|
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
4 features/test_ruby.feature
@@ -23,6 +23,8 @@ Feature: Testing a Ruby project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false|
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -52,6 +54,8 @@ Feature: Testing a Ruby project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false|
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
4 features/test_ruby_with_given_jdk_version.feature
@@ -26,6 +26,8 @@ Feature: Testing a Ruby project with a given JDK version
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -62,6 +64,8 @@ Feature: Testing a Ruby project with a given JDK version
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
4 features/test_scala.feature
@@ -25,6 +25,8 @@ Feature: Testing a Scala project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -57,6 +59,8 @@ Feature: Testing a Scala project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
4 features/test_scala_with_given_jdk_version.feature
@@ -25,6 +25,8 @@ Feature: Testing a Scala project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
@@ -57,6 +59,8 @@ Feature: Testing a Scala project
| job:test:start | started_at: [now] |
| job:test:log | log: /Using worker/ |
| job:test:log | log: cd ~/builds |
+ | job:test:log | log: export TRAVIS_PULL_REQUEST=false |
+ | job:test:log | log: export TRAVIS_SECURE_ENV_VARS=false |
| job:test:log | log: export FOO=foo |
| job:test:log | log: git clone |
| job:test:log | log: cd travis-ci/travis-ci |
View
4 lib/travis/build/commit.rb
@@ -27,6 +27,10 @@ def ref
def config_url
job.config_url
end
+
+ def pull_request?
+ job.pull_request
+ end
end
end
end
View
23 lib/travis/build/job/test.rb
@@ -107,9 +107,28 @@ def chdir
end
def export
- Array(config.env).compact.select { |line| line.present? }.each do |line|
+ export_travis_specific_variables
+
+ env_vars.each do |line|
shell.export_line(line)
- end if config.env
+ end
+ end
+
+ def export_travis_specific_variables
+ shell.export_line "TRAVIS_PULL_REQUEST=#{(!!commit.pull_request?).inspect}"
+ shell.export_line "TRAVIS_SECURE_ENV_VARS=#{secure_env_vars?}"
+ end
+
+ def env_vars
+ if config.env
+ Array(config.env).compact.select { |line| line.present? }
+ else
+ []
+ end
+ end
+
+ def secure_env_vars?
+ !commit.pull_request? && env_vars.any? { |line| line =~ /^SECURE / }
end
def checkout
View
39 spec/build/job/test_spec.rb
@@ -7,7 +7,8 @@
let(:commit) { Hashr.new(:repository => {
:slug => "owner/repo",
},
- :checkout => true) }
+ :checkout => true,
+ :pull_request => false) }
let(:config) { Hashr.new(:env => 'FOO=foo', :script => 'rake') }
let(:job) { Travis::Build::Job::Test.new(shell, commit, config) }
@@ -101,6 +102,42 @@
end
describe 'export' do
+ context 'when we\'re dealing pull request' do
+ it 'exports TRAVIS_PULL_REQUEST=true ENV var' do
+ commit.expects(:pull_request?).at_least_once.returns(true)
+ shell.expects(:export_line).with("TRAVIS_PULL_REQUEST=true")
+ job.send(:export)
+ end
+ end
+
+ it 'exports TRAVIS_PULL_REQUEST=false ENV var' do
+ shell.expects(:export_line).with("TRAVIS_PULL_REQUEST=false")
+ job.send(:export)
+ end
+
+ it 'exports TRAVIS_SECURE_ENV_VARS=false ENV var' do
+ shell.expects(:export_line).with("TRAVIS_SECURE_ENV_VARS=false")
+ job.send(:export)
+ end
+
+ context 'with secure env vars' do
+ let(:config) { Hashr.new(:env => 'SECURE FOO=foo') }
+
+ it 'exports TRAVIS_SECURE_ENV_VARS=true ENV var' do
+ shell.expects(:export_line).with("TRAVIS_SECURE_ENV_VARS=true")
+ job.send(:export)
+ end
+ end
+
+ context 'when commit is a pull_request commit' do
+ it 'sets TRAVIS specific env vars accordingly' do
+ commit.expects(:pull_request?).twice.returns(true)
+ shell.expects(:export_line).with("TRAVIS_PULL_REQUEST=true")
+ shell.expects(:export_line).with("TRAVIS_SECURE_ENV_VARS=false")
+ job.send(:export)
+ end
+ end
+
it 'accepts a single string with multiple values' do
s = 'SUITE=integration'
config.env = s

0 comments on commit 371a91a

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