Skip to content

Fix CI redux #3

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

Merged
merged 36 commits into from
Jan 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cacbbe4
ignore gems
ianfixes Jan 10, 2018
8d41392
address security concerns from github regarding gem versions
ianfixes Jan 10, 2018
ab47c85
split some files and add installer functionality
ianfixes Jan 10, 2018
d736446
don't disable the display if previously enabled outside with_display
ianfixes Jan 10, 2018
effc510
fix path for OSX
ianfixes Jan 10, 2018
64e272d
add test for the board-is-installed function
ianfixes Jan 10, 2018
341034d
add CI script to gem
ianfixes Jan 10, 2018
2119ebc
wrap 'which' method in its own class and add tests
ianfixes Jan 11, 2018
a247e2d
be more verbose about skipping display manager enable
ianfixes Jan 11, 2018
a115466
fix logic in existing_display?
ianfixes Jan 11, 2018
49c42ff
use IO.popen instead of forking a fork
ianfixes Jan 11, 2018
6d38e66
add environment to run command
ianfixes Jan 11, 2018
7f6b216
quote the string
ianfixes Jan 11, 2018
71c1d3f
use builtin ruby to save development time
ianfixes Jan 11, 2018
a1c6386
log all parameters in arduino_cmd run
ianfixes Jan 11, 2018
c0c3ce3
test output of xdpyinfo
ianfixes Jan 11, 2018
7119806
expose ability to run commands in display environment
ianfixes Jan 11, 2018
7740d57
wrap the display manager command runner
ianfixes Jan 11, 2018
6d6b084
query x server to wait for launch
ianfixes Jan 11, 2018
7e58049
Add some doc comments
ianfixes Jan 11, 2018
c3237b0
hail mary logging
ianfixes Jan 11, 2018
dc2b35f
add ability to capture preferences
ianfixes Jan 12, 2018
fdeda7f
guess when graphical error message prevents command from completing
ianfixes Jan 12, 2018
110daa1
mute a lot of logging
ianfixes Jan 12, 2018
8fc631c
factor gui guessing into its own function
ianfixes Jan 12, 2018
e8a7610
add ability to set prefs
ianfixes Jan 12, 2018
a76f074
board_installed? use run_with_gui_guess
ianfixes Jan 12, 2018
a4f3ce3
add commands to install boards and libraries
ianfixes Jan 12, 2018
8b26d2a
suppress arduino output
ianfixes Jan 12, 2018
135f374
prefs can fail graphically, so handle them graphically
ianfixes Jan 13, 2018
78fca73
expose kwargs explicitly in run call
ianfixes Jan 13, 2018
6124d6a
make debug messages in display_manager toggleable
ianfixes Jan 13, 2018
87fb012
add run wrapper that does not capture, but with the same signture as …
ianfixes Jan 13, 2018
fb38943
add more to test script, get closer to install.sh parity
ianfixes Jan 13, 2018
d2d77b5
use null file instead of IO.pipe. not sure why this matters for success
ianfixes Jan 13, 2018
64b0886
allow switching to a particular board for compilation
ianfixes Jan 14, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/pkg/
/spec/reports/
vendor
*.gem

# rspec failure tracking
.rspec_status
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
sudo: false
language: ruby

rvm:
# rvm:
# - "2.0.0"
# - "2.1.0"
# - "2.2.0"
# - rbx
- "2.5.0"
# - "2.5.0"

before_install: gem install bundler -v 1.15.4
script:
- bundle exec rubocop --version
- bundle exec rubocop -D .
- bundle exec rspec
- bundle exec ci_system_check.rb
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- `ArduinoInstallation` class for managing lib / executable paths
- `DisplayManager` class for managing Xvfb instance if needed
- `ArduinoCmd` captures and caches preferences
- `ArduinoCmd` reports on whether a board is installed
- `ArduinoCmd` sets preferences
- `ArduinoCmd` installs boards
- `ArduinoCmd` installs libraries
- `ArduinoCmd` selects boards (compiler preference)

### Changed
- `DisplayManger.with_display` doesn't `disable` if the display was enabled prior to starting the block

### Deprecated

### Removed

### Fixed
- Built gems are `.gitignore`d
- Updated gems based on Github's security advisories

### Security

Expand Down
11 changes: 7 additions & 4 deletions arduino_ci.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ Gem::Specification.new do |spec|
spec.description = spec.description
spec.homepage = "http://github.com/ifreecarve/arduino_ci"

spec.files = ['README.md', '.yardopts'] + Dir['lib/**/*.*'].reject { |f| f.match(%r{^(test|spec|features)/}) }

spec.bindir = "exe"
rejection_regex = %r{^(test|spec|features)/}
libfiles = Dir['lib/**/*.*'].reject { |f| f.match(rejection_regex) }
binfiles = Dir[File.join(spec.bindir, '/**/*.*')].reject { |f| f.match(rejection_regex) }
spec.files = ['README.md', '.yardopts'] + libfiles + binfiles

spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency 'rubocop', '~> 0', '>= 0.46.0'
spec.add_development_dependency 'yard', '~>0.8', '>= 0.8'
spec.add_development_dependency 'rubocop', '~>0.49.0'
spec.add_development_dependency 'yard', '~>0.9.11'
end
44 changes: 44 additions & 0 deletions exe/ci_system_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'arduino_ci'

puts "Enabling display with display manager"
ArduinoCI::DisplayManager::instance.enable

puts "Autlocating Arduino command"
arduino_cmd = ArduinoCI::ArduinoCmd.autolocate!

board_tests = {
"arduino:avr:uno" => true,
"eggs:milk:wheat" => false,
}

got_problem = false
board_tests.each do |k, v|
puts "I expect arduino_cmd.board_installed?(#{k}) to be #{v}"
result = arduino_cmd.board_installed?(k)
puts " board_installed?(#{k}) returns #{result}. expected #{v}"
got_problem = true if v != result
end

urls = [
"https://adafruit.github.io/arduino-board-index/package_adafruit_index.json",
"http://arduino.esp8266.com/stable/package_esp8266com_index.json"
]

puts "Setting additional URLs"
got_problem = true unless arduino_cmd.set_pref("boardsmanager.additional.urls", urls.join(","))

puts "Installing arduino:sam"
got_problem = true unless arduino_cmd.install_board("arduino:sam")
puts "Installing USBHost"
got_problem = true unless arduino_cmd.install_library("USBHost")
puts "checking that library is indexed"
got_problem = true unless arduino_cmd.library_is_indexed
puts "setting compiler warning level"
got_problem = true unless arduino_cmd.set_pref("compiler.warning_level", "all")
puts "use board! (install board)"
got_problem = true unless arduino_cmd.use_board!("arduino:samd:zero")
puts "verify that board has been installed"
got_problem = true unless arduino_cmd.board_installed?("arduino:samd:zero")

abort if got_problem
exit(0)
118 changes: 1 addition & 117 deletions lib/arduino_ci.rb
Original file line number Diff line number Diff line change
@@ -1,124 +1,8 @@
require "arduino_ci/version"

require 'singleton'

# Cross-platform way of finding an executable in the $PATH.
# via https://stackoverflow.com/a/5471032/2063546
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
require "arduino_ci/arduino_cmd"

# ArduinoCI contains classes for automated testing of Arduino code on the command line
# @author Ian Katz <[email protected]>
module ArduinoCI

# Wrap the Arduino executable. This requires, in some cases, a faked display.
class ArduinoCmd

# create as many ArduinoCmds as you like, but we need one and only one display manager
class DisplayMgr
include Singleton
attr_reader :enabled

def initialize
@existing = existing_display?
@enabled = false
@pid = nil
end

# attempt to determine if the machine is running a graphical display (i.e. not Travis)
def existing_display?
return true if RUBY_PLATFORM.include? "darwin"
return true if ENV["DISPLAY"].nil?
return true if ENV["DISPLAY"].include? ":"
false
end

# enable a virtual display
def enable
return @enabled = true if @existing # silent no-op if built in display
return unless @pid.nil?

@enabled = true
@pid = fork do
puts "Forking Xvfb"
system("Xvfb", ":1", "-ac", "-screen", "0", "1280x1024x16")
puts "Xvfb unexpectedly quit!"
end
sleep(3) # TODO: test a connection to the X server?
end

# disable the virtual display
def disable
return @enabled = false if @existing # silent no-op if built in display
return if @pid.nil?

begin
Process.kill 9, @pid
ensure
Process.wait @pid
@pid = nil
end
puts "Xvfb killed"
end

# Enable a virtual display for the duration of the given block
def with_display
enable
begin
yield environment
ensure
disable
end
end

def environment
return nil unless @existing || @enabled
return {} if @existing
{ DISPLAY => ":1.0" }
end

# On finalize, ensure child process is ended
def self.finalize
disable
end
end

class << self
protected :new

# attempt to find a workable Arduino executable across platforms
def guess_executable_location
osx_place = "/Applications/Arduino.app/Contents/MacOS/Arduino"
places = {
"arduino" => !which("arduino").nil?,
osx_place => (File.exist? osx_place),
}
places.each { |k, v| return k if v }
nil
end

def autolocate
ret = new
ret.path = guess_executable_location
ret
end
end

attr_accessor :path

def initialize
@display_mgr = DisplayMgr::instance
end

end

end
Loading