Skip to content

Commit b23267b

Browse files
author
Stanislav Kolotinskiy
committed
Exit on Coverity scan failure
Use provided shebang when eval'ing build script
1 parent 5f10098 commit b23267b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/travis/build/addons/coverity_scan.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def initialize(script, sh, data, config)
1717
@sh = sh
1818
@data = data
1919
@config = config.respond_to?(:to_hash) ? config.to_hash : {}
20+
@build_script_present = !!@config[:build_script_url]
2021
@config[:build_script_url] ||= "#{SCAN_URL}/scripts/travisci_build_coverity_scan.sh"
2122
end
2223

@@ -70,6 +71,12 @@ def set_coverity_scan_branch
7071
end
7172

7273
def build_command
74+
shebang = Faraday.get(@config[:build_script_url]).body.to_s.split("\n").first.to_s.strip
75+
interpreter = 'bash'
76+
if shebang.present? && matches = shebang.match(%r{\A#!(/bin/\w+)\z})
77+
interpreter = matches[1]
78+
end
79+
7380
sh.raw "export TRAVIS_TEST_RESULT=$(( ${TRAVIS_TEST_RESULT:-0} ))"
7481
sh.if "${TRAVIS_TEST_RESULT} = 0", echo: true do
7582
sh.fold('build_coverity') do
@@ -79,7 +86,12 @@ def build_command
7986
env << "COVERITY_SCAN_BUILD_COMMAND=\"${COVERITY_SCAN_BUILD_COMMAND:-#{@config[:build_command]}}\""
8087
env << "COVERITY_SCAN_BUILD_COMMAND_PREPEND=\"${COVERITY_SCAN_BUILD_COMMAND_PREPEND:-#{@config[:build_command_prepend]}}\""
8188
env << "COVERITY_SCAN_BRANCH_PATTERN=${COVERITY_SCAN_BRANCH_PATTERN:-#{@config[:branch_pattern]}}"
82-
sh.cmd "curl -s #{@config[:build_script_url]} | #{env.join(' ')} bash", echo: true
89+
sh.cmd "curl -s #{@config[:build_script_url]} | #{env.join(' ')} #{interpreter}", echo: true
90+
sh.raw 'result=$?', echo: true
91+
sh.if '$result -ne 0', echo: true do
92+
sh.raw "echo -e \"\033[33;1mSkipping build_coverity due to script error\033[0m\""
93+
sh.raw 'exit 1', echo: true
94+
end
8395
end
8496
end
8597
sh.else echo:true do

spec/build/addons/coverity_scan_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
describe Travis::Build::Addons::CoverityScan, :sexp do
44
let(:script) { stub('script') }
5-
let(:config) { {} }
5+
let(:config) { { project: { name: 'test' } } }
66
let(:data) { payload_for(:push, :ruby, config: { addons: { coverity_scan: config } }) }
77
let(:sh) { Travis::Shell::Builder.new }
88
let(:addon) { described_class.new(script, sh, Travis::Build::Data.new(data), config) }
99
subject { sh.to_sexp }
1010
before { addon.script }
1111

12-
# it_behaves_like 'compiled script' do
13-
# let(:code) { ['CODECLIMATE_REPO_TOKEN=1234'] }
14-
# end
15-
16-
xit 'needs specs!'
12+
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 }] }
13+
it { is_expected.to include_sexp [:raw, 'result=$?'] }
14+
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']]]]] }
1715
end

0 commit comments

Comments
 (0)