diff --git a/lib/travis/build/addons/coverity_scan.rb b/lib/travis/build/addons/coverity_scan.rb index 5b94ccd5c5..ce37216f80 100644 --- a/lib/travis/build/addons/coverity_scan.rb +++ b/lib/travis/build/addons/coverity_scan.rb @@ -17,6 +17,7 @@ def initialize(script, sh, data, config) @sh = sh @data = data @config = config.respond_to?(:to_hash) ? config.to_hash : {} + @build_script_present = !!@config[:build_script_url] @config[:build_script_url] ||= "#{SCAN_URL}/scripts/travisci_build_coverity_scan.sh" end @@ -70,6 +71,12 @@ def set_coverity_scan_branch end def build_command + shebang = Faraday.get(@config[:build_script_url]).body.to_s.split("\n").first.to_s.strip + interpreter = 'bash' + if shebang.present? && matches = shebang.match(%r{\A#!(/bin/\w+)\z}) + interpreter = matches[1] + end + sh.raw "export TRAVIS_TEST_RESULT=$(( ${TRAVIS_TEST_RESULT:-0} ))" sh.if "${TRAVIS_TEST_RESULT} = 0", echo: true do sh.fold('build_coverity') do @@ -79,7 +86,12 @@ def build_command env << "COVERITY_SCAN_BUILD_COMMAND=\"${COVERITY_SCAN_BUILD_COMMAND:-#{@config[:build_command]}}\"" env << "COVERITY_SCAN_BUILD_COMMAND_PREPEND=\"${COVERITY_SCAN_BUILD_COMMAND_PREPEND:-#{@config[:build_command_prepend]}}\"" env << "COVERITY_SCAN_BRANCH_PATTERN=${COVERITY_SCAN_BRANCH_PATTERN:-#{@config[:branch_pattern]}}" - sh.cmd "curl -s #{@config[:build_script_url]} | #{env.join(' ')} bash", echo: true + sh.cmd "curl -s #{@config[:build_script_url]} | #{env.join(' ')} #{interpreter}", echo: true + sh.raw 'result=$?', echo: true + sh.if '$result -ne 0', echo: true do + sh.raw "echo -e \"\033[33;1mSkipping build_coverity due to script error\033[0m\"" + sh.raw 'exit 1', echo: true + end end end sh.else echo:true do diff --git a/spec/build/addons/coverity_scan_spec.rb b/spec/build/addons/coverity_scan_spec.rb index 5708a4898d..68732d8d11 100644 --- a/spec/build/addons/coverity_scan_spec.rb +++ b/spec/build/addons/coverity_scan_spec.rb @@ -2,16 +2,14 @@ describe Travis::Build::Addons::CoverityScan, :sexp do let(:script) { stub('script') } - let(:config) { {} } + let(:config) { { project: { name: 'test' } } } let(:data) { payload_for(:push, :ruby, config: { addons: { coverity_scan: config } }) } let(:sh) { Travis::Shell::Builder.new } let(:addon) { described_class.new(script, sh, Travis::Build::Data.new(data), config) } subject { sh.to_sexp } before { addon.script } - # it_behaves_like 'compiled script' do - # let(:code) { ['CODECLIMATE_REPO_TOKEN=1234'] } - # end - - xit 'needs specs!' + it { is_expected.to include_sexp [:cmd, 'curl -s https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh | COVERITY_SCAN_PROJECT_NAME="$PROJECT_NAME" COVERITY_SCAN_NOTIFICATION_EMAIL="${COVERITY_SCAN_NOTIFICATION_EMAIL:-}" COVERITY_SCAN_BUILD_COMMAND="${COVERITY_SCAN_BUILD_COMMAND:-}" COVERITY_SCAN_BUILD_COMMAND_PREPEND="${COVERITY_SCAN_BUILD_COMMAND_PREPEND:-}" COVERITY_SCAN_BRANCH_PATTERN=${COVERITY_SCAN_BRANCH_PATTERN:-} /bin/sh', { echo: true }] } + it { is_expected.to include_sexp [:raw, 'result=$?'] } + it { is_expected.to include_sexp [:if, '$result -ne 0', [:then, [:cmds, [[:raw, "echo -e \"\e[33;1mSkipping build_coverity due to script error\e[0m\""], [:raw, 'exit 1']]]]] } end