Skip to content

Commit 8ed05e0

Browse files
committed
initial gem setup
1 parent 8b2a817 commit 8ed05e0

17 files changed

+436
-2
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
vendor
10+
11+
# rspec failure tracking
12+
.rspec_status

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--color

.rubocop.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
AllCops:
2+
Exclude:
3+
- '*.gemspec'
4+
- 'spec/*.rb'
5+
- '**/generated_parser/*'
6+
- './vendor/**/*'
7+
8+
# inherit_from: .rubocop_todo.yml
9+
10+
# Extra lines for readability
11+
Layout/EmptyLinesAroundClassBody:
12+
Enabled: false
13+
14+
Layout/EmptyLinesAroundMethodBody:
15+
Enabled: false
16+
17+
Layout/EmptyLinesAroundModuleBody:
18+
Enabled: false
19+
20+
# Configuration parameters: AllowForAlignment.
21+
Layout/ExtraSpacing:
22+
Enabled: false
23+
24+
Metrics/LineLength:
25+
Description: Limit lines to 80 characters.
26+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
27+
Enabled: true
28+
Max: 130
29+
30+
# Configuration parameters: CountComments.
31+
Metrics/ClassLength:
32+
Enabled: false
33+
Max: 400
34+
35+
Metrics/AbcSize:
36+
Enabled: false
37+
Max: 50
38+
39+
Metrics/MethodLength:
40+
Enabled: false
41+
Max: 50
42+
43+
# Configuration parameters: CountKeywordArgs.
44+
Metrics/ParameterLists:
45+
Max: 7
46+
47+
Style/BlockComments:
48+
Enabled: false
49+
50+
Style/ColonMethodCall:
51+
Enabled: false
52+
53+
# if you find "a == 3" readable and "3 == a" 'unreadable', do not contribute to this project.
54+
Style/YodaCondition:
55+
Enabled: false
56+
57+
# Configuration parameters: EnforcedStyle, SupportedStyles.
58+
Style/FormatString:
59+
Enabled: false
60+
61+
# Offense count: 1
62+
Metrics/CyclomaticComplexity:
63+
Enabled: false
64+
Max: 11
65+
66+
# Offense count: 1
67+
Metrics/PerceivedComplexity:
68+
Enabled: false
69+
Max: 14
70+
71+
# Cop supports --auto-correct.
72+
Style/RedundantSelf:
73+
Enabled: false
74+
75+
# because apostrophes
76+
Style/StringLiterals:
77+
Enabled: false
78+
79+
Style/TrailingCommaInLiteral:
80+
Enabled: false

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sudo: false
2+
language: ruby
3+
4+
rvm:
5+
- "2.0.0"
6+
- "2.1.0"
7+
- "2.2.0"
8+
- rbx
9+
10+
before_install: gem install bundler -v 1.15.4
11+
script:
12+
- bundle exec rubocop --version
13+
- bundle exec rubocop -D .
14+
- bundle exec rspec

.yardopts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/arduino_ci.rb lib/**/*.rb

CHANGELOG.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [Unreleased]
8+
### Added
9+
10+
### Changed
11+
12+
### Deprecated
13+
14+
### Removed
15+
16+
### Fixed
17+
18+
### Security
19+
20+
21+
## [0.0.1] - 2018-01-10
22+
### Added
23+
- Skeleton for gem with working unit tests
24+
25+
26+
[Unreleased]: https://github.com/ifreecarve/arduino_ci/compare/v0.0.1...HEAD
27+
[0.0.1]: https://github.com/ifreecarve/arduino_ci/compare/v0.0.0...v0.0.1

CONTRIBUTING.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Contributing to the ArduinoCI gem
2+
3+
ArduinoCI uses a very standard GitHub workflow.
4+
5+
1. Fork the repository on github
6+
2. Make your desired changes
7+
3. Push to your personal fork
8+
4. Open a pull request
9+
10+
Pull requests will trigger a Travis CI job. The following two commands will be expected to pass (so you may want to run them locally before opening the pull request):
11+
12+
* `rubocop -D` - code style tests
13+
* `rspec` - functional tests
14+
15+
Be prepared to write tests to accompany any code you would like to see merged.
16+
17+
18+
## Packaging the Gem
19+
20+
* Merge pull request with new features
21+
* Bump the version in lib/arduino_ci/version.rb and change it in README.md (since rubydoc.info doesn't always redirect to the latest version)
22+
* Update the sections of `CHANGELOG.md`
23+
* `git add README.md CHANGELOG.md lib/arduino_ci/version.rb`
24+
* `git commit -m "vVERSION bump"`
25+
* `git tag -a vVERSION -m "Released version VERSION"`
26+
* `gem build arduino_ci.gemspec`
27+
* `gem push arduino_ci-VERSION.gem`
28+
* `git push upstream`
29+
* `git push upstream --tags`

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "https://rubygems.org"
2+
3+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4+
5+
# Specify your gem's dependencies in arduino_ci.gemspec
6+
gemspec

README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
1-
# arduino_ci
2-
A Ruby gem for executing Continuous Integration (CI) tests on an Arduino library
1+
[![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci)
2+
[![Build Status](https://travis-ci.org/ifreecarve/arduino_ci.svg)](https://travis-ci.org/ifreecarve/arduino_ci)
3+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/)
4+
5+
# ArduinoCI Ruby gem (`arduino_ci`)
6+
7+
[Arduino CI](https://github.com/ifreecarve/arduino_ci) is a Ruby gem for executing Continuous Integration (CI) tests on an Arduino library -- both locally and as part of a service like Travis CI.
8+
9+
10+
## Installation
11+
12+
Add this line to your application's Gemfile:
13+
14+
```ruby
15+
gem 'arduino_ci'
16+
```
17+
18+
And then execute:
19+
20+
$ bundle
21+
22+
Or install it yourself as:
23+
24+
$ gem install arduino_ci
25+
26+
27+
## Usage
28+
29+
TODO: Write usage instructions here, based on other TODO of writing the actual gem.
30+
31+
32+
## Author
33+
34+
This gem was written by Ian Katz ([email protected]) in 2018. It's released under the Apache 2.0 license.
35+
36+
37+
## See Also
38+
39+
* [Contributing](CONTRIBUTING.md)

arduino_ci.gemspec

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# coding: utf-8
2+
lib = File.expand_path("../lib", __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require "arduino_ci/version"
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "arduino_ci"
8+
spec.version = ArduinoCI::VERSION
9+
spec.licenses = ['Apache 2.0']
10+
spec.authors = ["Ian Katz"]
11+
spec.email = ["[email protected]"]
12+
13+
spec.summary = "Tools for building and unit testing Arduino libraries"
14+
spec.description = spec.description
15+
spec.homepage = "http://github.com/ifreecarve/arduino_ci"
16+
17+
spec.files = ['README.md', '.yardopts'] + Dir['lib/**/*.*'].reject { |f| f.match(%r{^(test|spec|features)/}) }
18+
19+
spec.bindir = "exe"
20+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21+
spec.require_paths = ["lib"]
22+
23+
spec.add_development_dependency "bundler", "~> 1.15"
24+
spec.add_development_dependency "rspec", "~> 3.0"
25+
spec.add_development_dependency 'rubocop', '~> 0', '>= 0.46.0'
26+
spec.add_development_dependency 'yard', '~>0.8', '>= 0.8'
27+
end

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "arduino_ci"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

lib/arduino_ci.rb

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
require "arduino_ci/version"
2+
3+
require 'singleton'
4+
5+
# Cross-platform way of finding an executable in the $PATH.
6+
# via https://stackoverflow.com/a/5471032/2063546
7+
# which('ruby') #=> /usr/bin/ruby
8+
def which(cmd)
9+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
10+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
11+
exts.each do |ext|
12+
exe = File.join(path, "#{cmd}#{ext}")
13+
return exe if File.executable?(exe) && !File.directory?(exe)
14+
end
15+
end
16+
nil
17+
end
18+
19+
# ArduinoCI contains classes for automated testing of Arduino code on the command line
20+
# @author Ian Katz <[email protected]>
21+
module ArduinoCI
22+
23+
# Wrap the Arduino executable. This requires, in some cases, a faked display.
24+
class ArduinoCmd
25+
26+
# create as many ArduinoCmds as you like, but we need one and only one display manager
27+
class DisplayMgr
28+
include Singleton
29+
attr_reader :enabled
30+
31+
def initialize
32+
@existing = existing_display?
33+
@enabled = false
34+
@pid = nil
35+
end
36+
37+
# attempt to determine if the machine is running a graphical display (i.e. not Travis)
38+
def existing_display?
39+
return true if RUBY_PLATFORM.include? "darwin"
40+
return true if ENV["DISPLAY"].include? ":"
41+
false
42+
end
43+
44+
# enable a virtual display
45+
def enable
46+
return @enabled = true if @existing # silent no-op if built in display
47+
return unless @pid.nil?
48+
49+
@enabled = true
50+
@pid = fork do
51+
puts "Forking Xvfb"
52+
system("Xvfb", ":1", "-ac", "-screen", "0", "1280x1024x16")
53+
puts "Xvfb unexpectedly quit!"
54+
end
55+
sleep(3) # TODO: test a connection to the X server?
56+
end
57+
58+
# disable the virtual display
59+
def disable
60+
return @enabled = false if @existing # silent no-op if built in display
61+
return if @pid.nil?
62+
63+
begin
64+
Process.kill 9, @pid
65+
ensure
66+
Process.wait @pid
67+
@pid = nil
68+
end
69+
puts "Xvfb killed"
70+
end
71+
72+
# Enable a virtual display for the duration of the given block
73+
def with_display
74+
enable
75+
begin
76+
yield environment
77+
ensure
78+
disable
79+
end
80+
end
81+
82+
def environment
83+
return nil unless @existing || @enabled
84+
return {} if @existing
85+
{ DISPLAY => ":1.0" }
86+
end
87+
88+
# On finalize, ensure child process is ended
89+
def self.finalize
90+
disable
91+
end
92+
end
93+
94+
class << self
95+
protected :new
96+
97+
# attempt to find a workable Arduino executable across platforms
98+
def guess_executable_location
99+
osx_place = "/Applications/Arduino.app/Contents/MacOS/Arduino"
100+
places = {
101+
"arduino" => !which("arduino").nil?,
102+
osx_place => (File.exist? osx_place),
103+
}
104+
places.each { |k, v| return k if v }
105+
nil
106+
end
107+
108+
def autolocate
109+
ret = new
110+
ret.path = guess_executable_location
111+
ret
112+
end
113+
end
114+
115+
attr_accessor :path
116+
117+
def initialize
118+
@display_mgr = DisplayMgr::instance
119+
end
120+
121+
end
122+
123+
end

0 commit comments

Comments
 (0)