Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit on Coverity scan failure #2006

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/travis/build/addons/coverity_scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions spec/build/addons/coverity_scan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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