Skip to content

Commit f8ce3ba

Browse files
committed
try new CI script
1 parent 9409f08 commit f8ce3ba

File tree

4 files changed

+106
-5
lines changed

4 files changed

+106
-5
lines changed

.travis.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ language: ruby
88
# - rbx
99
# - "2.5.0"
1010

11-
before_install: gem install bundler -v 1.15.4
11+
#before_install: gem install bundler -v 1.15.4
1212
script:
13+
- bundle install
1314
- bundle exec rubocop --version
1415
- bundle exec rubocop -D .
1516
- bundle exec rspec
16-
- bundle exec ci_system_check.rb
17+
- cd SampleProjects/DoSomething
18+
- bundle install
19+
- bundle exec arduino_ci_remote.rb

SampleProjects/DoSomething/Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ PATH
22
remote: /Users/ikatz/Development/non-wayfair/arduino_ci
33
specs:
44
arduino_ci (0.0.1)
5+
os (~> 1.0)
56

67
GEM
78
remote: https://rubygems.org/
89
specs:
10+
os (1.0.0)
911

1012
PLATFORMS
1113
ruby

exe/arduino_ci_remote.rb

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env ruby
2+
require 'arduino_ci'
3+
require 'set'
4+
5+
WIDTH = 80
6+
7+
@failure_count = 0
8+
9+
# terminate after printing any debug info. TODO: capture debug info
10+
def terminate
11+
puts "Failures: #{@failure_count}"
12+
retcode = @failure_count.zero? ? 0 : 1
13+
exit(retcode)
14+
end
15+
16+
# make a nice status line for an action and react to the action
17+
def perform_action(message, on_fail_msg, abort_on_fail)
18+
line = "#{message}..."
19+
print line
20+
result = yield
21+
mark = result ? "✓" : "X"
22+
puts mark.rjust(WIDTH - line.length, " ")
23+
unless result
24+
puts on_fail_msg unless on_fail_msg.nil?
25+
@failure_count += 1
26+
# print out error messaging here if we've captured it
27+
terminate if abort_on_fail
28+
end
29+
result
30+
end
31+
32+
# Make a nice status for something that defers any failure code until script exit
33+
def attempt(message, &block)
34+
perform_action(message, nil, false, &block)
35+
end
36+
37+
# Make a nice status for something that kills the script immediately on failure
38+
def assure(message, &block)
39+
perform_action(message, "This may indicate a problem with ArduinoCI!", true, &block)
40+
end
41+
42+
# initialize command and config
43+
config = ArduinoCI::CIConfig.default.from_project_library
44+
arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
45+
46+
# initialize library under test
47+
installed_library_path = assure("Installing library under test") { arduino_cmd.install_local_library(".") }
48+
library_examples = arduino_cmd.library_examples(installed_library_path)
49+
50+
# gather up all required boards so we can install them up front.
51+
# start with the "platforms to unittest" and add the examples
52+
# while we're doing that, get the aux libraries as well
53+
all_platforms = {}
54+
aux_libraries = Set.new(config.aux_libraries_for_unittest + config.aux_libraries_for_build)
55+
config.platforms_to_unittest.each { |p| all_platforms[p] = config.platform_definition(p) }
56+
library_examples.each do |path|
57+
ovr_config = config.from_example(path)
58+
ovr_config.platforms_to_build.each { |p| all_platforms[p] = config.platform_definition(p) }
59+
aux_libraries.merge(ovr_config.aux_libraries_for_build)
60+
end
61+
62+
# with all platform info, we can extract unique packages and their urls
63+
# do that, set the URLs, and download the packages
64+
all_packages = all_platforms.values.map { |v| v[:package] }.uniq.reject(&:nil?)
65+
all_urls = all_packages.map { |p| config.package_url(p) }.uniq.reject(&:nil?)
66+
assure("Setting board manager URLs") do
67+
arduino_cmd.set_pref("boardsmanager.additional.urls", all_urls.join(","))
68+
end
69+
70+
all_packages.each do |p|
71+
assure("Installing board package #{p}") do
72+
arduino_cmd.install_boards(p)
73+
end
74+
end
75+
76+
aux_libraries.each do |l|
77+
assure("Installing aux library '#{l}'") { arduino_command.install_library(l) }
78+
end
79+
80+
attempt("Setting compiler warning level") { arduino_cmd.set_pref("compiler.warning_level", "all") }
81+
82+
library_examples.each do |example_path|
83+
ovr_config = config.from_example(example_path)
84+
ovr_config.platforms_to_build.each do |p|
85+
board = all_platforms[p][:board]
86+
assure("Switching to board for #{p} (#{board})") { arduino_cmd.use_board(board) }
87+
example_name = File.basename(example_path)
88+
attempt("Verifying #{example_name}") { arduino_cmd.verify_sketch(example_path) }
89+
end
90+
end
91+
92+
config.platforms_to_unittest.each do |p|
93+
board = all_platforms[p][:board]
94+
assure("Switching to board for #{p} (#{board})") { arduino_cmd.use_board(board) }
95+
cpp_library.test_files.each do |unittest_path|
96+
unittest_name = File.basename(unittest_path)
97+
attempt("Unit testing #{unittest_name}") { cpp_library.test(unittest_path) }
98+
end
99+
end

exe/ci_system_check.rb

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050

5151
library_path = File.join(File.dirname(File.dirname(__FILE__)), "SampleProjects", "DoSomething")
5252

53-
puts "verify a library with arduino mocks"
54-
cpp_library = ArduinoCI::CppLibrary.new(library_path)
55-
5653
puts "verify the examples of a library (#{library_path})..."
5754
puts " - Install the library"
5855
installed_library_path = arduino_cmd.install_local_library(library_path)

0 commit comments

Comments
 (0)