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

Match command names exactly #172

Open
wants to merge 2 commits 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
15 changes: 12 additions & 3 deletions lib/travis/queue/sudo_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class SudoDetector < Struct.new(:config)
sudo
)

PATTERN = /^[^#]*\b(#{EXECUTABLES.join('|')})\b/

STAGES = %i(
before_install
install
Expand All @@ -22,14 +20,25 @@ 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

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
1 change: 1 addition & 0 deletions spec/travis/queue/sudo_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
]

Expand Down