diff --git a/lib/travis/queue/sudo_detector.rb b/lib/travis/queue/sudo_detector.rb index 68a37d1a..8602c60d 100644 --- a/lib/travis/queue/sudo_detector.rb +++ b/lib/travis/queue/sudo_detector.rb @@ -7,8 +7,6 @@ class SudoDetector < Struct.new(:config) sudo ) - PATTERN = /^[^#]*\b(#{EXECUTABLES.join('|')})\b/ - STAGES = %i( before_install install @@ -22,7 +20,10 @@ class SudoDetector < Struct.new(:config) ) def detect? - stages.any? { |script| PATTERN =~ script.to_s } + stages.any? do |script| + commands = script.to_s.sub(/#.*$/,'') + has_common? commands.split, EXECUTABLES + end end private @@ -30,6 +31,14 @@ def detect? def stages config.values_at(*STAGES).compact.flatten end + + def has_common?(a,b) + Array(a).any? do |a_el| + Array(b).any? do |b_el| + a_el == b_el + end + end + end end end end diff --git a/spec/travis/queue/sudo_detector_spec.rb b/spec/travis/queue/sudo_detector_spec.rb index 76a95d7a..67804ee5 100644 --- a/spec/travis/queue/sudo_detector_spec.rb +++ b/spec/travis/queue/sudo_detector_spec.rb @@ -9,6 +9,7 @@ [{ before_install: ['docker run busybox echo whatever'] }, true], [{ before_script: ['echo ; echo ; echo ; sudo echo ; echo'] }, true], [{ install: '# no sudo needed here' }, false], + [{ script: 'docker-compose up' }, false], [{ install: true }, false], ]