Skip to content

Commit

Permalink
add a Stage::Skip, call travis_result on script
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs committed May 9, 2017
1 parent e3c3e54 commit 2a7b438
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
9 changes: 9 additions & 0 deletions example_payloads/skip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"config":{
"script": "skip"
},
"repository":{
"slug":"travis-repos/chirp-org-staging",
"source_url":"https://github.com/travis-repos/chirp-org-staging.git"
}
}
10 changes: 5 additions & 5 deletions lib/travis/build/stages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'travis/build/stages/builtin'
require 'travis/build/stages/custom'
require 'travis/build/stages/conditional'
require 'travis/build/stages/skip'

module Travis
module Build
Expand Down Expand Up @@ -75,14 +76,12 @@ def run
define_header_stage

STAGES.each do |stage|
define_stage(stage.type, stage.name) unless skip?(stage)
define_stage(stage.type, stage.name)
end

sh.raw "source $HOME/.travis/job_stages"

STAGES.each do |stage|
next if skip?(stage)

case stage.run_in_debug
when :always
sh.raw "travis_run_#{stage.name}"
Expand Down Expand Up @@ -114,6 +113,7 @@ def define_stage(type, name)

def run_stage(type, name)
type = :builtin if fallback?(type, name)
type = :skip if skip?(type, name)
stage = self.class.const_get(type.to_s.camelize).new(script, name)
stage.run
end
Expand All @@ -122,8 +122,8 @@ def debug_build?
script.debug_build_via_api?
end

def skip?(stage)
stage.type == :custom && SKIP_KEYWORDS.any? { |kw| config[stage.name] == kw }
def skip?(type, name)
type == :custom && SKIP_KEYWORDS.any? { |word| config[name] == word }
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/travis/build/stages/skip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'travis/build/stages/base'

module Travis
module Build
class Stages
class Skip < Base
def run
sh.raw 'travis_result 0' if script?
end
end
end
end
end
12 changes: 10 additions & 2 deletions spec/build/script_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@
end

context 'when install phase is `"skip"`' do
it 'does not execute `travis_run_install` function' do
it 'execute `travis_run_install` function, and set the test result' do
payload[:config][:install] = 'skip'
should include_sexp [:raw, 'travis_run_install']
should_not include_sexp [:raw, 'travis_result 0'] # these functions are hard to test, extract an bash ast type :function?
end
end

should_not include_sexp [:raw, 'travis_run_install']
context 'when script phase is `"skip"`' do
it 'execute `travis_run_script` function, and set the test result' do
payload[:config][:script] = 'skip'
should include_sexp [:raw, 'travis_run_install']
should include_sexp [:raw, 'travis_result 0'] # these functions are hard to test, extract an bash ast type :function?
end
end

Expand Down

0 comments on commit 2a7b438

Please sign in to comment.